java.lang.Object
org.apache.sis.referencing.operation.matrix.Solver
All Implemented Interfaces:
org.opengis.referencing.operation.Matrix

final class Solver extends Object implements org.opengis.referencing.operation.Matrix
Computes the value of U which solves X × U = Y. The solve(double[], Matrix, double[], int, int) method in this class is adapted from the LUDecomposition class of the JAMA matrix package. JAMA is provided in the public domain.

This class implements the Matrix interface as an implementation convenience. This implementation details can be ignored.

Since:
0.4
Version:
0.4
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final org.opengis.referencing.operation.Matrix
    A immutable identity matrix without defined size.
    private static final int
    The size of the (i, j, s) tuples used internally by solve(Matrix, Matrix, double[], int, int, boolean) for storing information about the NaN values.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    For the IDENTITY constant only.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.opengis.referencing.operation.Matrix
    Returns this since this matrix is immutable.
    double
    getElement(int j, int i)
    Returns 1 for elements on the diagonal, 0 otherwise.
    int
    Arbitrarily returns 0.
    int
    Arbitrarily returns 0.
    (package private) static MatrixSIS
    inverse(org.opengis.referencing.operation.Matrix X, boolean noChange)
    Computes the inverse of the given matrix.
    boolean
    Returns true since this matrix is the identity matrix.
    void
    setElement(int j, int i, double d)
    Unsupported operation since this matrix is immutable.
    private static MatrixSIS
    solve(double[] LU, org.opengis.referencing.operation.Matrix Y, double[] eltY, int size, int innerSize)
    Implementation of solve and inverse methods.
    (package private) static MatrixSIS
    solve(org.opengis.referencing.operation.Matrix X, org.opengis.referencing.operation.Matrix Y)
    Solves X × U = Y.
    private static MatrixSIS
    solve(org.opengis.referencing.operation.Matrix X, org.opengis.referencing.operation.Matrix Y, double[] eltY, int size, int innerSize, boolean noChange)
    Implementation of solve and inverse methods, with filtering of NaN values.

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • TUPLE_SIZE

      private static final int TUPLE_SIZE
      The size of the (i, j, s) tuples used internally by solve(Matrix, Matrix, double[], int, int, boolean) for storing information about the NaN values.
      See Also:
    • IDENTITY

      private static final org.opengis.referencing.operation.Matrix IDENTITY
      A immutable identity matrix without defined size. This is used only for computing the inverse.
  • Constructor Details

    • Solver

      private Solver()
      For the IDENTITY constant only.
  • Method Details

    • isIdentity

      public boolean isIdentity()
      Returns true since this matrix is the identity matrix.
      Specified by:
      isIdentity in interface org.opengis.referencing.operation.Matrix
    • getElement

      public double getElement(int j, int i)
      Returns 1 for elements on the diagonal, 0 otherwise. This method never thrown exception.
      Specified by:
      getElement in interface org.opengis.referencing.operation.Matrix
    • setElement

      public void setElement(int j, int i, double d)
      Unsupported operation since this matrix is immutable.
      Specified by:
      setElement in interface org.opengis.referencing.operation.Matrix
    • clone

      public org.opengis.referencing.operation.Matrix clone()
      Returns this since this matrix is immutable. This method is defined because required by Matrix interface.
      Specified by:
      clone in interface org.opengis.referencing.operation.Matrix
      Overrides:
      clone in class Object
    • getNumRow

      public int getNumRow()
      Arbitrarily returns 0. The actual value does not matter for the purpose of Solver.
      Specified by:
      getNumRow in interface org.opengis.referencing.operation.Matrix
    • getNumCol

      public int getNumCol()
      Arbitrarily returns 0. The actual value does not matter for the purpose of Solver.
      Specified by:
      getNumCol in interface org.opengis.referencing.operation.Matrix
    • inverse

      static MatrixSIS inverse(org.opengis.referencing.operation.Matrix X, boolean noChange) throws NoninvertibleMatrixException
      Computes the inverse of the given matrix. This method shall be invoked only for square matrices.
      Parameters:
      X - the matrix to invert, which must be square.
      noChange - if true, do not allow modifications to the X matrix.
      Throws:
      NoninvertibleMatrixException - if the X matrix is not square or singular.
    • solve

      static MatrixSIS solve(org.opengis.referencing.operation.Matrix X, org.opengis.referencing.operation.Matrix Y) throws NoninvertibleMatrixException
      Solves X × U = Y. This method is an adaptation of the LUDecomposition class of the JAMA matrix package.
      Parameters:
      X - the matrix to invert.
      Y - the desired result of X × U.
      Throws:
      NoninvertibleMatrixException - if the X matrix is not square or singular.
    • solve

      private static MatrixSIS solve(org.opengis.referencing.operation.Matrix X, org.opengis.referencing.operation.Matrix Y, double[] eltY, int size, int innerSize, boolean noChange) throws NoninvertibleMatrixException
      Implementation of solve and inverse methods, with filtering of NaN values. This method searches for NaN values before to attempt solving or inverting the matrix. If some NaN values are found but the matrix is written in such a way that each NaN value is used for exactly one coordinate value (i.e. a matrix row is used for a one-dimensional conversion which is independent of all other dimensions), then we will edit the matrix in such a way that this NaN value does not prevent the inverse matrix to be computed.

      This method does not checks the matrix size. Check for matrix size shall be performed by the caller like below:

      Parameters:
      X - the matrix to invert, which must be square.
      Y - the desired result of X × U.
      eltY - elements and error terms of the Y matrix, or null if not available.
      size - the value of X.getNumRow(), X.getNumCol() and Y.getNumRow().
      innerSize - the value of Y.getNumCol().
      noChange - if true, do not allow modifications to the X matrix.
      Throws:
      NoninvertibleMatrixException - if the X matrix is not square or singular.
    • solve

      private static MatrixSIS solve(double[] LU, org.opengis.referencing.operation.Matrix Y, double[] eltY, int size, int innerSize) throws NoninvertibleMatrixException
      Implementation of solve and inverse methods. This method contains the code ported from the JAMA package. Use a "left-looking", dot-product, Crout/Doolittle algorithm.

      This method does not checks the matrix size. It is caller's responsibility to ensure that the following hold:

      Parameters:
      LU - elements of the X matrix to invert, including error terms.
      Y - the desired result of X × U.
      eltY - elements and error terms of the Y matrix, or null if not available.
      size - the value of X.getNumRow(), X.getNumCol() and Y.getNumRow().
      innerSize - the value of Y.getNumCol().
      Throws:
      NoninvertibleMatrixException - if the X matrix is not square or singular.