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.

  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    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 Type
    Method
    Description
    protected 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
    Initializes vector for equivalent linear matrix equation.
    solve(T A, T B)
    Solves the linear tensor equation given by \( AX = B \) for the tensor \( X \).
    protected abstract T
    wrap(V x, Shape outputShape)
    Wraps solution as a tensor and reshapes to the proper shape.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ExactTensorSolver

      protected ExactTensorSolver(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.
      Parameters:
      matrixSolver - Matrix solver to use as the solver for the equivalent matrix system.
  • Method Details

    • solve

      public T solve(T A, T B)

      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 TensorOverSemiring.tensorDot(TensorOverSemiring, int[], int[]) where M = new int[]{X.rank()-1, X.rank(), X.rank()+1, ..., A.rank()-1} and N = new int[]{0, 1, ..., X.rank()-1}

      Specified by:
      solve in interface LinearSolver<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

      protected Shape getOutputShape(T A, T B, int aRankOriginal)
      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 of A before any reshaping.
      Returns:
      The shape of \( X \) in \( AX = B \).
    • checkSize

      protected void checkSize(int aNumEntries, int prod)
      Ensures that aNumEntries==prod.
      Parameters:
      aNumEntries - The total number of data in the \( A \) tensor.
      prod - Product of all axis lengths in the output shape.
    • initMatrix

      protected abstract U initMatrix(T A, int prod)
      Initializes matrix for equivalent linear matrix equation.
      Parameters:
      A - Tensor to convert to matrix.
      prod - Product of all axis lengths in \( A \).
      Returns:
      A matrix with the same data as tensor \( A \) with shape (prod, prod).
    • initVector

      protected abstract V initVector(T B)
      Initializes vector for equivalent linear matrix equation.
      Parameters:
      B - Tensor to convert to vector.
      Returns:
      Flattens tensor B and converts to a vector.
    • wrap

      protected abstract T wrap(V x, Shape outputShape)
      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 \).