Interface Matrix<E>

All Superinterfaces:
AbelianGroup<Matrix<E>>, AbelianMonoid<Matrix<E>>, Group<Matrix<E>>, Magma<Matrix<E>>, Module<Matrix<E>, E>, Monoid<Matrix<E>>, Ring<Matrix<E>>, Semiring<Matrix<E>>, Set<Matrix<E>>
All Known Implementing Classes:
DenseMatrix, GenericMatrix, MMapMatrix, NativeRealDoubleMatrix, NativeRealFloatMatrix, RealDoubleMatrix, SIMDRealDoubleMatrix, SIMDRealFloatMatrix, SparseMatrix, TiledMatrix

public interface Matrix<E> extends Ring<Matrix<E>>, Module<Matrix<E>, E>
Represents a matrix of scalar elements.

A matrix is a rectangular array of numbers, symbols, or expressions, arranged in rows and columns. Square matrices form a Ring.

Since:
1.0
Author:
Silvere Martin-Michiellot, Gemini AI (Google DeepMind)
  • Method Details

    • of

      static <E> Matrix<E> of(E[][] data, Ring<E> ring)
      Creates a matrix from a 2D array.
    • of

      static <E> Matrix<E> of(List<List<E>> data, Ring<E> ring)
      Creates a matrix from a 2D list.
    • triangular

      static <E> Matrix<E> triangular(List<List<E>> data, Ring<E> ring)
      Creates a triangular matrix from a 2D list.
    • tridiagonal

      static <E> Matrix<E> tridiagonal(List<List<E>> data, Ring<E> ring)
      Creates a tridiagonal matrix from a 2D list.
    • identity

      static <E> Matrix<E> identity(int size, Ring<E> ring)
      Creates an identity matrix.
    • zeros

      static <E> Matrix<E> zeros(int rows, int cols, Ring<E> ring)
      Creates a matrix of zeros.
    • rows

      int rows()
      Returns the number of rows in this matrix.
    • cols

      int cols()
      Returns the number of columns in this matrix.
    • get

      E get(int row, int col)
      Returns the element at the specified row and column.
    • getStorage

      MatrixStorage<E> getStorage()
      Returns the underlying storage of this matrix.
      Returns:
      the matrix storage
    • getProvider

      default LinearAlgebraProvider<E> getProvider()
      Returns the provider that created or manages this matrix.
      Returns:
      the linear algebra provider
    • map

      default Matrix<E> map(Function<E,E> mapper)
      Applies a mapping function to each element of this matrix.
      Parameters:
      mapper - the function to apply
      Returns:
      a new matrix with mapped elements
    • add

      Matrix<E> add(Matrix<E> other)
      Returns the sum of this matrix and another.
    • subtract

      default Matrix<E> subtract(Matrix<E> other)
      Returns the difference of this matrix and another.
    • multiply

      Matrix<E> multiply(Matrix<E> other)
      Returns the product of this matrix and another.
    • transpose

      Matrix<E> transpose()
      Returns the transpose of this matrix.
    • trace

      E trace()
      Returns the trace of this matrix (sum of diagonal elements).
    • getSubMatrix

      Matrix<E> getSubMatrix(int rowStart, int rowEnd, int colStart, int colEnd)
      Returns a submatrix of this matrix.
    • getRow

      Vector<E> getRow(int row)
      Returns the row at the specified index as a vector.
    • getColumn

      Vector<E> getColumn(int col)
      Returns the column at the specified index as a vector.
    • determinant

      E determinant()
      Returns the determinant of this matrix.
    • inverse

      Matrix<E> inverse()
      Returns the multiplicative inverse of this matrix.
    • multiply

      Vector<E> multiply(Vector<E> vector)
      Multiplies this matrix by a vector.
    • negate

      Matrix<E> negate()
      Returns the negation of this matrix (-this).
    • zero

      Matrix<E> zero()
      Returns the zero matrix of the same dimensions.
      Specified by:
      zero in interface AbelianMonoid<E>
      Returns:
      the zero element
    • lu

      LUResult<E> lu()
      Computes the LU decomposition of this matrix.
    • qr

      QRResult<E> qr()
      Computes the QR decomposition of this matrix.
    • svd

      SVDResult<E> svd()
      Computes the Singular Value Decomposition (SVD) of this matrix.
    • cholesky

      CholeskyResult<E> cholesky()
      Computes the Cholesky decomposition of this matrix.
    • eigen

      EigenResult<E> eigen()
      Computes the eigenvalue decomposition of this matrix.
    • isMultiplicationCommutative

      default boolean isMultiplicationCommutative()
      Description copied from interface: Semiring
      Tests whether multiplication is commutative in this semiring.
      Specified by:
      isMultiplicationCommutative in interface Semiring<E>
      Returns:
      true if multiplication commutes
    • isCommutative

      default boolean isCommutative()
      Description copied from interface: AbelianGroup
      Abelian groups are always commutative by definition.
      Specified by:
      isCommutative in interface AbelianGroup<E>
      Specified by:
      isCommutative in interface AbelianMonoid<E>
      Specified by:
      isCommutative in interface Group<E>
      Specified by:
      isCommutative in interface Magma<E>
      Returns:
      always true
    • isEmpty

      default boolean isEmpty()
      Description copied from interface: Set
      Returns true if this set contains no elements.

      The empty set (∅) is a fundamental concept in set theory. It is the unique set containing no elements.

      Specified by:
      isEmpty in interface Set<E>
      Returns:
      true if this set is empty
    • inverse

      default Matrix<E> inverse(Matrix<E> element)
      Description copied from interface: Group
      Returns the inverse of the given element.

      For element a, returns a⁻¹ such that: a ∗ a⁻¹ = a⁻¹ ∗ a = e (identity).

      Specified by:
      inverse in interface Group<E>
      Parameters:
      element - the element to invert
      Returns:
      the inverse element
    • identity

      default Matrix<E> identity()
      Description copied from interface: Monoid
      Returns the identity element of this monoid.

      Satisfies: e ∗ a = a ∗ e = a for all a.

      Specified by:
      identity in interface AbelianMonoid<E>
      Specified by:
      identity in interface Monoid<E>
      Returns:
      the identity element
    • operate

      default Matrix<E> operate(Matrix<E> left, Matrix<E> right)
      Description copied from interface: Magma
      Performs the binary operation on two elements.

      This is the fundamental operation of a magma. The result must be an element of this magma (closure property).

      Properties: None required (not necessarily associative or commutative)

      Specified by:
      operate in interface Magma<E>
      Parameters:
      left - the first operand
      right - the second operand
      Returns:
      the result of a ∗ b
      See Also:
    • add

      default Matrix<E> add(Matrix<E> a, Matrix<E> b)
      Description copied from interface: AbelianMonoid
      Returns the sum of two elements (additive notation).

      Delegates to Magma.operate(Object, Object).

      Specified by:
      add in interface AbelianMonoid<E>
      Parameters:
      a - the first addend
      b - the second addend
      Returns:
      a + b
    • multiply

      default Matrix<E> multiply(Matrix<E> a, Matrix<E> b)
      Description copied from interface: Semiring
      Returns the product of two elements.

      Multiplication must be associative and distribute over addition.

      Specified by:
      multiply in interface Semiring<E>
      Parameters:
      a - the first factor
      b - the second factor
      Returns:
      a × b
    • getScalarRing

      Ring<E> getScalarRing()
      Description copied from interface: Module
      Returns the ring of scalars for this module.
      Specified by:
      getScalarRing in interface Module<Matrix<E>, E>
      Returns:
      the scalar ring
    • scale

      Matrix<E> scale(E scalar, Matrix<E> element)
      Description copied from interface: Module
      Scalar multiplication (r × m).
      Specified by:
      scale in interface Module<Matrix<E>, E>
      Parameters:
      scalar - the scalar r ∈ R
      element - the module element m ∈ M
      Returns:
      r × m
    • scale

      default Matrix<E> scale(E scalar)
      Convenience scalar multiplication (scalar × this).
      Specified by:
      scale in interface Module<Matrix<E>, E>
      Parameters:
      scalar - the scalar
      Returns:
      scalar × this
    • toTensor

      default Tensor<E> toTensor()
      Converts this matrix to a rank-2 tensor.
      Returns:
      the corresponding tensor