Package org.flag4j.linalg.solvers.exact
Class ExactTensorSolver<T extends TensorBase<T,?,?,?,?,?,?>,U extends MatrixMixin<U,?,?,?,?,?,V,?>,V extends VectorMixin<V,?,?,?,?,U,?,?>>
java.lang.Object
org.flag4j.linalg.solvers.exact.ExactTensorSolver<T,U,V>
- Type Parameters:
T
- Type of tensor in equation to solve.U
- Matrix type equivalent of tensor to solve.V
- Vector type equivalent of tensor to solve.
- All Implemented Interfaces:
LinearTensorSolver<T>
- Direct Known Subclasses:
ComplexExactTensorSolver
,RealExactTensorSolver
public abstract class ExactTensorSolver<T extends TensorBase<T,?,?,?,?,?,?>,U extends MatrixMixin<U,?,?,?,?,?,V,?>,V extends VectorMixin<V,?,?,?,?,U,?,?>>
extends Object
implements LinearTensorSolver<T>
Solves a well determined system of equations A*X=B
in an exact sense where A, X, and B are tensors.
If the system is not well determined, i.e. A
is 'square' and full rank, then use a
least-squares solver.
-
Field Summary
Modifier and TypeFieldDescriptionprivate final LinearSolver
<U, V> Solver to solve a linear matrix equationC*X=d
forX
whereC
andX
are matrices andd
is a vector. -
Constructor Summary
ModifierConstructorDescriptionprotected
ExactTensorSolver
(LinearSolver<U, V> matrixSolver) Creates an exact tensor solver which will use reform the problem as a matrix linear system and use the provided solver to solve the tensor system. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
checkSize
(int aNumEntries, int prod) Ensures that aNumEntries==prod.protected Shape
getOutputShape
(T A, T B, int aRankOriginal) Constructs the shape of the output.protected abstract U
initMatrix
(T A, int prod) Initializes matrix for equivalent linear matrix equation.protected abstract V
initVector
(T B) Initializes vector for equivalent linear matrix equation.Solves the linear tensor equation given byA*X=B
for the tensorX
.protected abstract T
Wraps solution as a tensor and reshapes to the proper shape.
-
Field Details
-
matrixSolver
private final LinearSolver<U extends MatrixMixin<U,?, matrixSolver?, ?, ?, ?, V, ?>, V extends VectorMixin<V, ?, ?, ?, ?, U, ?, ?>> Solver to solve a linear matrix equationC*X=d
forX
whereC
andX
are matrices andd
is a vector.
-
-
Constructor Details
-
ExactTensorSolver
Creates an exact tensor solver which will use reform the problem as a matrix linear system and use the provided solver to solve the tensor system.- Parameters:
matrixSolver
- Matrix solver to use as the solver for the equivalent matrix system.
-
-
Method Details
-
solve
Solves the linear tensor equation given byA*X=B
for the tensorX
. All indices ofX
are summed over in the tensor product with the rightmost indices ofA
as if byA.tensorDot(X, M, N)
whereM = new int[]{X.rank()-1, X.rank(), X.rank()+1, ..., A.rank()-1}
andN = new int[]{0, 1, ..., X.rank()-1}
- Specified by:
solve
in interfaceLinearTensorSolver<T extends TensorBase<T,
?, ?, ?, ?, ?, ?>> - Parameters:
A
- Coefficient tensor in the linear system.B
- Tensor of constants in the linear system.- Returns:
- The solution to
x
in the linear systemA*X=B
.
-
getOutputShape
-
checkSize
protected void checkSize(int aNumEntries, int prod) Ensures that aNumEntries==prod.- Parameters:
aNumEntries
- The total number of entries in theA
tensor.prod
- Product of all axis lengths in the output shape.
-
initMatrix
-
initVector
-
wrap
Wraps solution as a tensor and reshapes to the proper shape.- Parameters:
x
- Vector solution to matrix linear equation which is equivalent to the tensor equationA*X=B
.outputShape
- Shape for the solution tensorX
.- Returns:
- The solution
X
to the linear tensor equationA*X=B
.
-