Class ExactTensorSolver<T extends AbstractTensor<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:
LinearSolver<T>
- Direct Known Subclasses:
ComplexExactTensorSolver,RealExactTensorSolver
public abstract class ExactTensorSolver<T extends AbstractTensor<T,?,?>,U extends MatrixMixin<U,?,V,?>,V extends VectorMixin<V,U,?,?>>
extends Object
implements LinearSolver<T>
Solves a well determined system of equations \( AX = B \) in an exact sense where \( A \), \( X \), and \( B \) are tensors.
All indices of \( X \) are summed over in the tensor product with the rightmost indices of
\( A \) as if by
A.tensorDot(X, M, N) where
M = new int[]{X.rank()-1, X.rank(), X.rank()+1, ..., A.rank()-1} and
N = new int[]{0, 1, ..., X.rank()-1}.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedExactTensorSolver(LinearMatrixSolver<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 voidcheckSize(int aNumEntries, int prod) Ensures thataNumEntries==prod.protected ShapegetOutputShape(T A, T B, int aRankOriginal) Constructs the shape of the output.protected abstract UinitMatrix(T A, int prod) Initializes matrix for equivalent linear matrix equation.protected abstract VinitVector(T B) Initializes vector for equivalent linear matrix equation.Solves the linear tensor equation given by \( AX = B \) for the tensor \( X \).protected abstract TWraps solution as a tensor and reshapes to the proper shape.
-
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 by \( AX = B \) for the tensor \( X \).
All indices of \( X \) are summed over in the tensor product with the rightmost indices of \( A \) as if by
A.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:
solvein interfaceLinearSolver<T extends AbstractTensor<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 system \( AX = B \).
-
getOutputShape
Constructs the shape of the output.- Parameters:
A- Tensor corresponding to \( A \) in \( AX = B \).B- Tensor corresponding to \( B \) in \( AX = B \).aRankOriginal- Original rank ofAbefore any reshaping.- Returns:
- The shape of \( X \) in \( AX = B \).
-
checkSize
protected void checkSize(int aNumEntries, int prod) Ensures thataNumEntries==prod.- Parameters:
aNumEntries- The total number of data in the \( A \) 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 equation \( Ax=b \).outputShape- Shape for the solution tensor \( x \).- Returns:
- The solution \( x \) to the linear tensor equation \( Ax = b \).
-