Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pipeTo instead of with? #179

Open
vkostyukov opened this issue May 7, 2014 · 7 comments
Open

Use pipeTo instead of with? #179

vkostyukov opened this issue May 7, 2014 · 7 comments

Comments

@vkostyukov
Copy link
Owner

I'm thinking of using pipeTo method name istead of withSolver, withDecompositor, withInverter:

Matrix {
  LinearSystemSolver pipeTo(SolverFactory factory);
  MatrixInverter pipeTo(InverterFactory factory);
  MatrixDecompisitor pipeTo(DecompositorFactory factory);
}
@vkostyukov vkostyukov added this to the la4j-0.5.0 milestone May 7, 2014
@vkostyukov
Copy link
Owner Author

An example of usage:

Matrix a = ...
Matrix b = a.pipeTo(LinearAlgebra.GAUSS_JORDAN).invert();

@vkostyukov
Copy link
Owner Author

Matrix a = ...
// GAUSS_JORDAN is no longe a factory in an operation from Matrix to MatrixInverter
MatrixInverter = a.pipeTo(LinearAlgebra.GAUSS_JORDAN);
// A typical use-case
Matrix b = a.pipeTo(LinearAlgebra.GAUSS_JORDAN).invert();
// Or in-place:
Matrix b = a.pipeTo(LinearAlgebra.GAUSS_JORDAN).invertInPlace();
// Or do it in a single line
Matrix b = a.pipeAndApplyTo(LinearAlgebra.GAUSS_JORDAN);
// Or in-place
Matrix b = a.pipeAndApplyInPlaceTo(LinearAlgebra.GAUSS_JORDAN);

@vkostyukov
Copy link
Owner Author

Everything is an operation: Iverter, Decompisitor, LinearSolver. And pipeTo is a core routin to work with it. This should be refactored in this release. For now, only oo-place operations for complex things.

@vkostyukov
Copy link
Owner Author

Just curring:

// we didn't pass vector to a MatrixVectorOration, so it returned a curried operation;
// we still have troubles here since we want to cache the LU between calls to solver.apply().
VectorOperation<Vector> solver = a.pipeTo(LinearAlgebra.FORWARD_BACK_SUBST);
solver.apply(Vector);
// we might want to pass a factory
Matrix b = a.pipeTo(LinearAlgebra.GAUSS_JORDAN);

// GAUSS_JORDAN is an operation factory

@vkostyukov
Copy link
Owner Author

A matrix-operation-factory concept

MatrixOperationFactory<T> {
  MatrixOperation<T> apply(Factory factory)
}

@vkostyukov
Copy link
Owner Author

In a base class:

public <T> pipeTo<T>(MatrixOperationFactory<T> operation) {
  return pipeTo(operation.apply(factory))
}

@vkostyukov
Copy link
Owner Author

The overall picture for decomposers should looks like:

Matrix lup[] = a.pipeTo(LinearAlgebra.LU);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant