Type Parameters:
E -
All Superinterfaces:
java.util.function.BiFunction<Vector<E>,Ring<E>,Vector<E>>
All Known Implementing Classes:
BaseMatrix, MutableMatrix, SparseMatrix

public interface Matrix<E> extends java.util.function.BiFunction<Vector<E>,Ring<E>,Vector<E>>
A representation of a matrix taking entries of type E.

Matrices are by default immutable, but calling the mutable() returns an instance of a MutableMatrix which may be edited.

  • Method Summary

    Modifier and Type
    Method
    Description
    default Vector<E>
    collapseColumns(E init, java.util.function.BinaryOperator<E> op)
     
    default Vector<E>
    collapseRows(E init, java.util.function.BinaryOperator<E> op)
     
    static <F> Matrix<F>
    column(Vector<F> vector)
     
     
    static <E> Matrix<E>
    copy(Matrix<E> matrix)
    Create copy of a matrix.
    static <E> Matrix<E>
    diagonal(int n, java.util.function.IntFunction<E> populator, E zero)
     
    static <T> java.util.function.BinaryOperator<Matrix<T>>
    entrywiseOperator(java.util.function.BinaryOperator<T> op)
     
    boolean
    equals(Matrix<E> other, java.util.function.BiPredicate<E,E> equality)
     
    extendTo(int m, int n, E padding)
    Returns a new larger matrix of size m x n which has this matrix in the top left corner and pads the rest using the given padding value.
    default Matrix<E>
    extendWith(int dm, int dn, E padding)
     
    static <E> Matrix<E>
    eye(int n, Ring<E> ring)
     
    static <E> Matrix<E>
    eye(int n, E one, E zero)
     
    static <E> Matrix<E>
    fromBlocks(Matrix<Matrix<E>> blocks)
     
    get(int i, int j)
     
    default E
     
    getColumn(int j)
     
    int
     
    getRow(int i)
     
    int
     
    boolean
     
    static <E> Matrix<E>
    lazy(int m, int n, IntBinaryFunction<E> populator)
    Generate a Matrix<E> where each element is created using the given populator when it is needed.
    <F> Matrix<F>
    map(java.util.function.Function<E,F> f)
     
    minor(int i, int j)
     
    Returns a mutable copy of this matrix.
    static <E> Matrix<E>
    of(int m, int n, IntBinaryFunction<E> populator)
    Create a new matrix with the given height, width and populate it using the given function.
    static <E> Matrix<E>
    of(int m, int n, IntBinaryFunction<E> populator, boolean populateSequentially)
    Create a new matrix with the given height, width and populate it using the given function.
    static <E> Matrix<E>
    of(int m, int n, E defaultValue)
     
    static <E> Matrix<E>
    of(int m, E... entries)
    Convenience function to quickly define (small) matrices.
    static <E> Matrix<E>
    of(int m, java.util.function.IntFunction<ArrayList<E>> rowPopulator)
    Create a new matrix with the given height and populate it using the given row populator.
    static <E> Matrix<E>
    of(E[]... rows)
     
    static <E> Matrix<E>
    of(ArrayList<E>... rows)
     
    static <F> Matrix<F>
    row(Vector<F> vector)
     
     
    default java.util.stream.Stream<E>
     
    submatrix(int[] rows, int[] columns)
    Returns a new matrix with the given rows and columns from this matrix.
    submatrix(int r0, int r1, int c0, int c1)
    Returns a new matrix of size (r1-r0) x (c1-c0) with rows r0, ..., r1-1 and columns c0, ..., c1-1 from this matrix.
    toString(java.util.function.Function<E,String> toString)
     
     
    Returns a view of the given matrix.

    Methods inherited from interface java.util.function.BiFunction

    andThen, apply
  • Method Details

    • lazy

      static <E> Matrix<E> lazy(int m, int n, IntBinaryFunction<E> populator)
      Generate a Matrix<E> where each element is created using the given populator when it is needed.
      Type Parameters:
      E - The type of the entries.
      Parameters:
      m - The height of the matrix
      n - The width of the matrix
      populator - The populator function where populator.apply(i, j) generates the (i,j)'th entry.
      Returns:
      A Matrix<E> where each element is created using the given populator when it is needed.
    • copy

      static <E> Matrix<E> copy(Matrix<E> matrix)
      Create copy of a matrix. Note that the entries will be the same as in the original, and is hence not cloned.
    • of

      static <E> Matrix<E> of(int m, int n, IntBinaryFunction<E> populator)
      Create a new matrix with the given height, width and populate it using the given function. The entries are created immediately in parallel.
    • of

      static <E> Matrix<E> of(int m, int n, IntBinaryFunction<E> populator, boolean populateSequentially)
      Create a new matrix with the given height, width and populate it using the given function. The entries are created immediately sequentially.
    • of

      static <E> Matrix<E> of(int m, java.util.function.IntFunction<ArrayList<E>> rowPopulator)
      Create a new matrix with the given height and populate it using the given row populator. The rows are created immediately in parallel.
    • of

      static <E> Matrix<E> of(E[]... rows)
    • of

      @SafeVarargs static <E> Matrix<E> of(ArrayList<E>... rows)
    • of

      @SafeVarargs static <E> Matrix<E> of(int m, E... entries)
      Convenience function to quickly define (small) matrices. The m is the number of rows and the remaining are the entries which should be divisible by the number of rows.
    • of

      static <E> Matrix<E> of(int m, int n, E defaultValue)
    • eye

      static <E> Matrix<E> eye(int n, E one, E zero)
    • eye

      static <E> Matrix<E> eye(int n, Ring<E> ring)
    • fromBlocks

      static <E> Matrix<E> fromBlocks(Matrix<Matrix<E>> blocks)
    • entrywiseOperator

      static <T> java.util.function.BinaryOperator<Matrix<T>> entrywiseOperator(java.util.function.BinaryOperator<T> op)
    • row

      static <F> Matrix<F> row(Vector<F> vector)
    • column

      static <F> Matrix<F> column(Vector<F> vector)
    • diagonal

      static <E> Matrix<E> diagonal(int n, java.util.function.IntFunction<E> populator, E zero)
    • getColumn

      Vector<E> getColumn(int j)
    • getRow

      Vector<E> getRow(int i)
    • get

      default E get(Pair<Integer,Integer> index)
    • get

      E get(int i, int j)
    • getHeight

      int getHeight()
    • getWidth

      int getWidth()
    • minor

      Matrix<E> minor(int i, int j)
    • transpose

      Matrix<E> transpose()
    • map

      <F> Matrix<F> map(java.util.function.Function<E,F> f)
    • rows

      Iterable<Vector<E>> rows()
    • columns

      Iterable<Vector<E>> columns()
    • equals

      boolean equals(Matrix<E> other, java.util.function.BiPredicate<E,E> equality)
    • isSquare

      boolean isSquare()
    • extendTo

      Matrix<E> extendTo(int m, int n, E padding)
      Returns a new larger matrix of size m x n which has this matrix in the top left corner and pads the rest using the given padding value.
    • extendWith

      default Matrix<E> extendWith(int dm, int dn, E padding)
    • submatrix

      Matrix<E> submatrix(int[] rows, int[] columns)
      Returns a new matrix with the given rows and columns from this matrix. The given arrays are assumed to be sorted.
    • submatrix

      Matrix<E> submatrix(int r0, int r1, int c0, int c1)
      Returns a new matrix of size (r1-r0) x (c1-c0) with rows r0, ..., r1-1 and columns c0, ..., c1-1 from this matrix.
    • view

      Matrix<E> view()
      Returns a view of the given matrix. This does not store any values but instead maps operations to this matrix.
    • mutable

      MutableMatrix<E> mutable()
      Returns a mutable copy of this matrix.
    • collapseRows

      default Vector<E> collapseRows(E init, java.util.function.BinaryOperator<E> op)
    • collapseColumns

      default Vector<E> collapseColumns(E init, java.util.function.BinaryOperator<E> op)
    • stream

      default java.util.stream.Stream<E> stream()
    • toString

      String toString(java.util.function.Function<E,String> toString)