Package jisa.maths.matrices
Interface Matrix<T>
-
- All Superinterfaces:
java.lang.Iterable<T>
- All Known Implementing Classes:
AbstractMatrix
,AbstractMatrix.LMatrix
,ComplexMatrix
,ComplexMatrix.Col
,ComplexMatrix.Identity
,ComplexMatrix.Row
,MMatrix
,RealMatrix
public interface Matrix<T> extends java.lang.Iterable<T>
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
Matrix.EntryConsumer<T>
static interface
Matrix.EntryMapper<U,T>
static interface
Matrix.LinearMapper<T>
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Matrix<T>
add(Matrix<T> rhs)
Adds the given matrix to this one.Matrix<T>
add(T rhs)
Add the given value to each element in this matrix, returning the result.void
addToElement(int row, int col, T value)
Replace the value of an element with itself plus a given value.Matrix<T>
appendCols(Matrix<T> cols)
Creates a new matrix consisting of the given columns appended to the right of this matrix.Matrix<T>
appendRows(Matrix<T> rows)
Creates a new matrix consisting of the given rows appended to the bottom of this matrix.static boolean
canMultiply(Matrix a, Matrix b)
Checks if the two matrices, A and B, can be multiplied (A*B)default void
checkIndices(int row, int col)
Checks if the provided row and column indices are within bounds for this matrix.static boolean
colMatrixMatch(Matrix a, Matrix b)
int
cols()
Returns the number of columns in the matrix.Matrix<T>
copy()
Returns a deep copy of the matrix.static boolean
dimensionsMatch(Matrix a, Matrix b)
Checks if the two matrices, A and B, have the same dimensions.default Matrix<T>
div(Matrix<T> rhs)
Multiplies this matrix by the inverse of another.default Matrix<T>
div(T rhs)
Divides all elements in this matrix by the given value.default Matrix<T>
divide(Matrix<T> rhs)
Multiplies this matrix by the inverse of another.Matrix<T>
divide(T rhs)
Divides all elements in this matrix by the given value.void
divideElement(int row, int col, T value)
Replace the value of an element with itself divided by a given value.Matrix<T>
elementDivide(Matrix<T> rhs)
Performs element-wise division of this matrix by the specified matrix (divides each element in this matrix by its corresponding element in the other).Matrix<T>
elementMultiply(Matrix<T> rhs)
Computes the element-wise product of this matrix with another (this .* other).default boolean
equals(Matrix<T> compareTo)
Returns whether this matrix is the same as the given matrix.default void
forEach(java.util.function.Consumer<? super T> forEach)
Loops over each element, going along each row in turn.default void
forEach(Matrix.EntryConsumer<T> forEach)
Loops over each element, going along each row in turn.default void
forEachCol(java.util.function.Consumer<T[]> forEach)
Loops over all columns, providing each column as an array.default void
forEachRow(java.util.function.Consumer<T[]> forEach)
Loops over all rows, providing each row as an array.T
get(int row, int col)
Returns the element at the given indices.T[]
getColArray(int col)
Returns the values in a single column as an array.Matrix<T>
getColMatrix(int col)
Returns a single column as a column matrix.Matrix<T>
getColSums()
Returns a row matrix of the sums of each column in this matrix.T[][]
getData()
Returns all elements as a 2-dimensional array.T
getDeterminant()
Returns the determinant of the matrix (only for square matrices).Matrix<T>
getDiagonal()
Returns the diagonal values of the square matrix as a column matrix.T[]
getFlatData()
Returns all elements in a 1-dimensional array.LU<T>
getLU()
Computes and returns the LU decomposition of this matrix (only for square matrices).QR<T>
getQR()
Computes and returns the QR decomposition of this matrix.T[]
getRowArray(int row)
Returns the values in a single row as an array.Matrix<T>
getRowMatrix(int row)
Returns a single row as a row matrix.Matrix<T>
getRowSums()
Returns a column matrix of the sums of each row in this matrix.Matrix<T>
getSubMatrix(int[] rows, int[] cols)
Returns a sub-matrix containing only the specified rows and columns from this matrix.Matrix<T>
getSubMatrix(int startRow, int endRow, int startCol, int endCol)
Returns a sub-matrix containing only the rows and columns specified in the given ranges (inclusive).T
getTrace()
Returns the trace of the matrix (sum of diagonal elements).Matrix<T>
invert()
Inverts the matrix and returns the result (only for square matrices).default boolean
isCol()
Returns whether this matrix is a column matrix (cols() == 1).default boolean
isRow()
Returns whether this matrix is a row matrix (rows() == 1).static boolean
isScalar(Matrix a)
boolean
isSingular()
Returns whether the matrix is singular (has no inverse).default boolean
isSquare()
Returns whether the matrix is square or not (no.default java.util.Iterator<T>
iterator()
Matrix<T>
leftDivide(Matrix<T> rhs)
Multiplies the supplied matrix by the inverse of this matrix.Matrix<T>
leftDivide(T lhs)
Divides the given value by each element in the matrix returning a matrix of the results.Matrix<T>
leftElementDivide(Matrix<T> lhs)
Performs element-wise division of the specified matrix by this matrix (divides each element in the supplied matrix by its corresponding element in this matrix).Matrix<T>
leftElementMultiply(Matrix<T> lhs)
Computes the element-wise product of another matrix with this matrix (other * this).Matrix<T>
leftMultiply(Matrix<T> lhs)
Multiplies another matrix by this matrix (other * this).Matrix<T>
leftMultiply(T lhs)
Pre-multiplies each element in this matrix by a scalar value.Matrix<T>
map(GFunction<T,T> mapper)
Map all elements of this matrix into a new matrix according to the provided mapping function.Matrix<T>
map(Matrix.EntryMapper<T,T> mapper)
Map all elements of this matrix into a new matrix according to the provided mapping function.default <U> void
map(Matrix<U> to, GFunction<U,T> mapper)
Map all elements onto another matrix of a different type, U.default <U> void
map(Matrix<U> to, Matrix.EntryMapper<U,T> mapper)
Map all elements onto another matrix of a different type, U.default void
mapCol(int col, GFunction<T,T> mapper)
Maps the values of a specified column onto themselves.void
mapCol(int col, Matrix.LinearMapper<T> mapper)
Maps the values of a specified column onto themselves.default void
mapColToCol(int source, int dest, GFunction<T,T> mapper)
Maps one column onto another.void
mapColToCol(int source, int dest, Matrix.LinearMapper<T> mapper)
Maps one column onto another.void
mapElement(int row, int col, GFunction<T,T> mapper)
Replace an element with the value of a function of itself.default void
mapRow(int row, GFunction<T,T> mapper)
Maps the values of a specified row onto themselves.void
mapRow(int row, Matrix.LinearMapper<T> mapper)
Maps the values of a specified row onto themselves.default void
mapRowToRow(int source, int dest, GFunction<T,T> mapper)
Maps one row onto another.void
mapRowToRow(int source, int dest, Matrix.LinearMapper<T> mapper)
Maps one row onto another.default void
mapSelf(GFunction<T,T> mapper)
Map all elements of this matrix onto themselves according to the provided mapping function.default void
mapSelf(Matrix.EntryMapper<T,T> mapper)
Map all elements of this matrix onto themselves according to the provided mapping function.default Matrix<T>
minus(Matrix<T> rhs)
Subtracts the given matrix from this one, returning the result.default Matrix<T>
minus(T rhs)
Subtracts the given value from each element in this matrix, returning the result.Matrix<T>
multiply(Matrix<T> rhs)
Multiplies this matrix by another (this * other).Matrix<T>
multiply(T rhs)
Multiplies each element in this matrix by a scalar value.void
multiplyElement(int row, int col, T value)
Replace the value of an element with itself multiplied by a given value.default Matrix<T>
plus(Matrix<T> rhs)
Adds the given matrix to this one.default Matrix<T>
plus(T rhs)
Add the given value to each element in this matrix, returning the result.Matrix<T>
reshape(int rows, int cols)
Reshapes the elements in the matrix into a matrix of different dimensions (but same total number of elements), returning the result.static boolean
rowMatrixMatch(Matrix a, Matrix b)
int
rows()
Returns the number of rows in the matrix.void
set(int row, int col, T value)
Sets the matrix element at the given (row, col) position.void
setAll(T value)
Sets all elements to a single value.void
setAll(T... values)
Sets all elements in the matrix.default void
setCol(int col, Matrix<T> values)
Sets all elements in the specified column from a column matrix.default void
setCol(int col, T... values)
Sets all elements in the specified column.void
setDiagonal(T value)
Sets the values along the leading diagonal to the same value.void
setDiagonal(T... values)
Sets the elements on the leading diagonal of the matrix.default void
setRow(int row, Matrix<T> values)
Sets all elements in the specified row from a row matrix.default void
setRow(int row, T... values)
Sets all elements in the specified row.default void
setSubMatrix(int startRow, int startCol, Matrix<T> subMatrix)
Sets the value of elements within the specified sub-matrix.default int
size()
Returns the total number of elements in the matrix.default java.util.stream.Stream<T>
stream()
Matrix<T>
subtract(Matrix<T> rhs)
Subtracts the given matrix from this one, returning the result.Matrix<T>
subtract(T rhs)
Subtracts the given value from each element in this matrix, returning the result.void
subtractFromElement(int row, int col, T value)
Replace the value of an element with itself minus a given value.default Matrix<T>
times(Matrix<T> rhs)
Multiplies this matrix by another (this * other).default Matrix<T>
times(T rhs)
Multiplies each element in this matrix by a scalar value.java.lang.String
toString()
Returns a textual representation of this matrix.Matrix<T>
transpose()
Transposes the matrix and returns the result.
-
-
-
Method Detail
-
dimensionsMatch
static boolean dimensionsMatch(Matrix a, Matrix b)
Checks if the two matrices, A and B, have the same dimensions.- Parameters:
a
- Matrix Ab
- Matrix B- Returns:
- Same dimensions?
-
isScalar
static boolean isScalar(Matrix a)
-
canMultiply
static boolean canMultiply(Matrix a, Matrix b)
Checks if the two matrices, A and B, can be multiplied (A*B)- Parameters:
a
- Matrix Ab
- Matrix B- Returns:
- Can they multiply?
-
rows
int rows()
Returns the number of rows in the matrix.- Returns:
- Number of rows
-
cols
int cols()
Returns the number of columns in the matrix.- Returns:
- Number of columns
-
equals
default boolean equals(Matrix<T> compareTo)
Returns whether this matrix is the same as the given matrix. To qualify as being equal the two matrices must be of the same dimensions and each element must be the same.- Parameters:
compareTo
- Matrix to compare to- Returns:
- Are they equal?
-
size
default int size()
Returns the total number of elements in the matrix.- Returns:
- Number of elements
-
isSquare
default boolean isSquare()
Returns whether the matrix is square or not (no. rows = no. columns).- Returns:
- Is it square?
-
get
T get(int row, int col)
Returns the element at the given indices.- Parameters:
row
- Row indexcol
- Column index- Returns:
- Element at (row,col)
-
getData
T[][] getData()
Returns all elements as a 2-dimensional array.- Returns:
- All elements
-
getFlatData
T[] getFlatData()
Returns all elements in a 1-dimensional array.- Returns:
- All elements
-
getDiagonal
Matrix<T> getDiagonal()
Returns the diagonal values of the square matrix as a column matrix.- Returns:
- Diagonal values
-
setDiagonal
void setDiagonal(T... values)
Sets the elements on the leading diagonal of the matrix. Matrix must be square.- Parameters:
values
- Diagonal elements- Throws:
NonSquareException
- if the matrix is not square.
-
setDiagonal
void setDiagonal(T value)
Sets the values along the leading diagonal to the same value. Matrix must be square.- Parameters:
value
- Element value
-
set
void set(int row, int col, T value)
Sets the matrix element at the given (row, col) position.- Parameters:
row
- Row indexcol
- Column indexvalue
- Element value to set
-
setAll
void setAll(T... values)
Sets all elements in the matrix.- Parameters:
values
- Elements
-
setRow
default void setRow(int row, T... values)
Sets all elements in the specified row.- Parameters:
row
- Row indexvalues
- Elements
-
setRow
default void setRow(int row, Matrix<T> values)
Sets all elements in the specified row from a row matrix.- Parameters:
row
- Row indexvalues
- Row matrix of elements
-
setCol
default void setCol(int col, T... values)
Sets all elements in the specified column.- Parameters:
col
- Column indexvalues
- Elements
-
setCol
default void setCol(int col, Matrix<T> values)
Sets all elements in the specified column from a column matrix.- Parameters:
col
- Column indexvalues
- Column matrix of elements
-
setAll
void setAll(T value)
Sets all elements to a single value.- Parameters:
value
- Value to set
-
mapElement
void mapElement(int row, int col, GFunction<T,T> mapper)
Replace an element with the value of a function of itself.- Parameters:
row
- Row indexcol
- Column indexmapper
- Function for mapping
-
multiplyElement
void multiplyElement(int row, int col, T value)
Replace the value of an element with itself multiplied by a given value.- Parameters:
row
- Row indexcol
- Column indexvalue
- Factor to multiply by
-
divideElement
void divideElement(int row, int col, T value)
Replace the value of an element with itself divided by a given value.- Parameters:
row
- Row indexcol
- Column indexvalue
- Factor to divide by
-
addToElement
void addToElement(int row, int col, T value)
Replace the value of an element with itself plus a given value.- Parameters:
row
- Row indexcol
- Column indexvalue
- Value to add
-
subtractFromElement
void subtractFromElement(int row, int col, T value)
Replace the value of an element with itself minus a given value.- Parameters:
row
- Row indexcol
- Column indexvalue
- Value to subtract
-
map
Matrix<T> map(Matrix.EntryMapper<T,T> mapper)
Map all elements of this matrix into a new matrix according to the provided mapping function.- Parameters:
mapper
- Mapping function- Returns:
- Mapped matrix
-
map
Matrix<T> map(GFunction<T,T> mapper)
Map all elements of this matrix into a new matrix according to the provided mapping function.- Parameters:
mapper
- Mapping function- Returns:
- Mapped matrix
-
mapSelf
default void mapSelf(Matrix.EntryMapper<T,T> mapper)
Map all elements of this matrix onto themselves according to the provided mapping function.- Parameters:
mapper
- Mapping function
-
mapSelf
default void mapSelf(GFunction<T,T> mapper)
Map all elements of this matrix onto themselves according to the provided mapping function.- Parameters:
mapper
- Mapping function
-
map
default <U> void map(Matrix<U> to, Matrix.EntryMapper<U,T> mapper)
Map all elements onto another matrix of a different type, U.- Type Parameters:
U
- Type to map to- Parameters:
to
- Matrix to map ontomapper
- Function that defines mapping
-
map
default <U> void map(Matrix<U> to, GFunction<U,T> mapper)
Map all elements onto another matrix of a different type, U.- Type Parameters:
U
- Type to map to- Parameters:
to
- Matrix to map ontomapper
- Function that defines mapping
-
mapRow
void mapRow(int row, Matrix.LinearMapper<T> mapper)
Maps the values of a specified row onto themselves.- Parameters:
row
- Row index to mapmapper
- Function the defines mapping
-
mapRow
default void mapRow(int row, GFunction<T,T> mapper)
Maps the values of a specified row onto themselves.- Parameters:
row
- Row index to mapmapper
- Function the defines mapping
-
mapCol
void mapCol(int col, Matrix.LinearMapper<T> mapper)
Maps the values of a specified column onto themselves.- Parameters:
col
- Column index to mapmapper
- Function the defines mapping
-
mapCol
default void mapCol(int col, GFunction<T,T> mapper)
Maps the values of a specified column onto themselves.- Parameters:
col
- Column index to mapmapper
- Function the defines mapping
-
mapRowToRow
void mapRowToRow(int source, int dest, Matrix.LinearMapper<T> mapper)
Maps one row onto another.- Parameters:
source
- Source row indexdest
- Destination row indexmapper
- Function that defines mapping
-
mapRowToRow
default void mapRowToRow(int source, int dest, GFunction<T,T> mapper)
Maps one row onto another.- Parameters:
source
- Source row indexdest
- Destination row indexmapper
- Function that defines mapping
-
mapColToCol
void mapColToCol(int source, int dest, Matrix.LinearMapper<T> mapper)
Maps one column onto another.- Parameters:
source
- Source column indexdest
- Destination column indexmapper
- Function that defines mapping
-
mapColToCol
default void mapColToCol(int source, int dest, GFunction<T,T> mapper)
Maps one column onto another.- Parameters:
source
- Source column indexdest
- Destination column indexmapper
- Function that defines mapping
-
stream
default java.util.stream.Stream<T> stream()
-
getRowArray
T[] getRowArray(int row)
Returns the values in a single row as an array.- Parameters:
row
- Row index- Returns:
- Array of values
-
getColArray
T[] getColArray(int col)
Returns the values in a single column as an array.- Parameters:
col
- Column index- Returns:
- Array of values
-
getRowMatrix
Matrix<T> getRowMatrix(int row)
Returns a single row as a row matrix.- Parameters:
row
- Row index- Returns:
- Row matrix
-
getColMatrix
Matrix<T> getColMatrix(int col)
Returns a single column as a column matrix.- Parameters:
col
- Column index- Returns:
- Column matrix
-
multiply
Matrix<T> multiply(Matrix<T> rhs)
Multiplies this matrix by another (this * other).- Parameters:
rhs
- Right-hand side of multiplication- Returns:
- Result of multiplication
-
times
default Matrix<T> times(Matrix<T> rhs)
Multiplies this matrix by another (this * other).- Parameters:
rhs
- Matrix to multiply by (right-hand side)- Returns:
- Result of multiplication
-
leftMultiply
Matrix<T> leftMultiply(Matrix<T> lhs)
Multiplies another matrix by this matrix (other * this).- Parameters:
lhs
- Matrix to multiply (left-hand side)- Returns:
- Result of multiplication
-
multiply
Matrix<T> multiply(T rhs)
Multiplies each element in this matrix by a scalar value.- Parameters:
rhs
- Scalar value.- Returns:
- Result of multiplication
-
times
default Matrix<T> times(T rhs)
Multiplies each element in this matrix by a scalar value. (Kotlin operator overload)- Parameters:
rhs
- Scalar value.- Returns:
- Result of multiplication
-
leftMultiply
Matrix<T> leftMultiply(T lhs)
Pre-multiplies each element in this matrix by a scalar value.- Parameters:
lhs
- Scalar value.- Returns:
- Result of multiplication
-
elementMultiply
Matrix<T> elementMultiply(Matrix<T> rhs)
Computes the element-wise product of this matrix with another (this .* other).- Parameters:
rhs
- Matrix to multiply by (right-hand side)- Returns:
- Result of multiplication
-
leftElementMultiply
Matrix<T> leftElementMultiply(Matrix<T> lhs)
Computes the element-wise product of another matrix with this matrix (other * this).- Parameters:
lhs
- Matrix to multiply (left-hand side)- Returns:
- Result of multiplication
-
divide
default Matrix<T> divide(Matrix<T> rhs)
Multiplies this matrix by the inverse of another.- Parameters:
rhs
- Matrix to "divide" by (left-hand side)- Returns:
- Result of "division"
-
div
default Matrix<T> div(Matrix<T> rhs)
Multiplies this matrix by the inverse of another.- Parameters:
rhs
- Matrix to "divide" by (left-hand side)- Returns:
- Result of "division"
-
leftDivide
Matrix<T> leftDivide(Matrix<T> rhs)
Multiplies the supplied matrix by the inverse of this matrix.- Parameters:
rhs
- Matrix to be "divided"- Returns:
- Result of division
-
elementDivide
Matrix<T> elementDivide(Matrix<T> rhs)
Performs element-wise division of this matrix by the specified matrix (divides each element in this matrix by its corresponding element in the other).- Parameters:
rhs
- Matrix to divide by- Returns:
- Result of division
-
leftElementDivide
Matrix<T> leftElementDivide(Matrix<T> lhs)
Performs element-wise division of the specified matrix by this matrix (divides each element in the supplied matrix by its corresponding element in this matrix).- Parameters:
lhs
- Matrix to divide- Returns:
- Result of division
-
divide
Matrix<T> divide(T rhs)
Divides all elements in this matrix by the given value.- Parameters:
rhs
- Value to divide by- Returns:
- Result of division
-
div
default Matrix<T> div(T rhs)
Divides all elements in this matrix by the given value.- Parameters:
rhs
- Value to divide by- Returns:
- Result of division
-
leftDivide
Matrix<T> leftDivide(T lhs)
Divides the given value by each element in the matrix returning a matrix of the results.- Parameters:
lhs
- Value to be divided- Returns:
- Result of division
-
add
Matrix<T> add(Matrix<T> rhs)
Adds the given matrix to this one. (Adds each element with its corresponding element).- Parameters:
rhs
- Matrix to add- Returns:
- Result of addition
-
plus
default Matrix<T> plus(Matrix<T> rhs)
Adds the given matrix to this one. (Adds each element with its corresponding element).- Parameters:
rhs
- Matrix to add- Returns:
- Result of addition
-
add
Matrix<T> add(T rhs)
Add the given value to each element in this matrix, returning the result.- Parameters:
rhs
- Value to add- Returns:
- Result of addition
-
plus
default Matrix<T> plus(T rhs)
Add the given value to each element in this matrix, returning the result.- Parameters:
rhs
- Value to add- Returns:
- Result of addition
-
subtract
Matrix<T> subtract(Matrix<T> rhs)
Subtracts the given matrix from this one, returning the result.- Parameters:
rhs
- Matrix to subtract- Returns:
- Result of subtraction
-
minus
default Matrix<T> minus(Matrix<T> rhs)
Subtracts the given matrix from this one, returning the result.- Parameters:
rhs
- Matrix to subtract- Returns:
- Result of subtraction
-
subtract
Matrix<T> subtract(T rhs)
Subtracts the given value from each element in this matrix, returning the result.- Parameters:
rhs
- Value to subtract- Returns:
- Result of subtraction
-
minus
default Matrix<T> minus(T rhs)
Subtracts the given value from each element in this matrix, returning the result.- Parameters:
rhs
- Value to subtract- Returns:
- Result of subtraction
-
getSubMatrix
Matrix<T> getSubMatrix(int[] rows, int[] cols)
Returns a sub-matrix containing only the specified rows and columns from this matrix.- Parameters:
rows
- Array of row indicescols
- Array of column indices- Returns:
- Sub-matrix
-
getSubMatrix
Matrix<T> getSubMatrix(int startRow, int endRow, int startCol, int endCol)
Returns a sub-matrix containing only the rows and columns specified in the given ranges (inclusive).- Parameters:
startRow
- Start of row rangeendRow
- End of row rangestartCol
- Start of column rangeendCol
- End of column range- Returns:
- Sub-matrix
-
appendRows
Matrix<T> appendRows(Matrix<T> rows)
Creates a new matrix consisting of the given rows appended to the bottom of this matrix.- Parameters:
rows
- Rows to append (must match column dimension)- Returns:
- Combined matrix
-
appendCols
Matrix<T> appendCols(Matrix<T> cols)
Creates a new matrix consisting of the given columns appended to the right of this matrix.- Parameters:
cols
- Columns to append (must match row dimension)- Returns:
- Combined matrix
-
setSubMatrix
default void setSubMatrix(int startRow, int startCol, Matrix<T> subMatrix)
Sets the value of elements within the specified sub-matrix.- Parameters:
startRow
- Starting row index of sub-matrix within matrixstartCol
- Starting column index of sub-matrix within matrixsubMatrix
- Sub-matrix to set
-
isSingular
boolean isSingular()
Returns whether the matrix is singular (has no inverse).- Returns:
- Singular?
-
isRow
default boolean isRow()
Returns whether this matrix is a row matrix (rows() == 1).- Returns:
- Row matrix?
-
isCol
default boolean isCol()
Returns whether this matrix is a column matrix (cols() == 1).- Returns:
- Column matrix?
-
getDeterminant
T getDeterminant()
Returns the determinant of the matrix (only for square matrices).- Returns:
- Determinant value
-
getTrace
T getTrace()
Returns the trace of the matrix (sum of diagonal elements).- Returns:
- Trace value
-
invert
Matrix<T> invert()
Inverts the matrix and returns the result (only for square matrices).- Returns:
- Inverted matrix
-
transpose
Matrix<T> transpose()
Transposes the matrix and returns the result.- Returns:
- Transposed matrix
-
reshape
Matrix<T> reshape(int rows, int cols)
Reshapes the elements in the matrix into a matrix of different dimensions (but same total number of elements), returning the result.rows * cols must equal this.size().
- Parameters:
rows
- New number of rowscols
- New number of columns- Returns:
- Reshaped matrix
-
getQR
QR<T> getQR()
Computes and returns the QR decomposition of this matrix.- Returns:
- QR Decomposition
-
getLU
LU<T> getLU()
Computes and returns the LU decomposition of this matrix (only for square matrices).- Returns:
- LU Decomposition
-
getRowSums
Matrix<T> getRowSums()
Returns a column matrix of the sums of each row in this matrix.- Returns:
- Column matrix of sums
-
getColSums
Matrix<T> getColSums()
Returns a row matrix of the sums of each column in this matrix.- Returns:
- Row matrix of sums
-
forEach
default void forEach(Matrix.EntryConsumer<T> forEach)
Loops over each element, going along each row in turn.- Parameters:
forEach
- Action to perform for each value.
-
forEach
default void forEach(java.util.function.Consumer<? super T> forEach)
Loops over each element, going along each row in turn.- Specified by:
forEach
in interfacejava.lang.Iterable<T>
- Parameters:
forEach
- Action to perform for each value.
-
forEachRow
default void forEachRow(java.util.function.Consumer<T[]> forEach)
Loops over all rows, providing each row as an array.- Parameters:
forEach
- Action to perform for each row.
-
forEachCol
default void forEachCol(java.util.function.Consumer<T[]> forEach)
Loops over all columns, providing each column as an array.- Parameters:
forEach
- Action to perform for each column.
-
iterator
default java.util.Iterator<T> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<T>
-
checkIndices
default void checkIndices(int row, int col) throws IndexException
Checks if the provided row and column indices are within bounds for this matrix. Throws an IndexException if not.- Parameters:
row
- Row indexcol
- Column index- Throws:
IndexException
- If indices are out of bounds.
-
toString
java.lang.String toString()
Returns a textual representation of this matrix.- Overrides:
toString
in classjava.lang.Object
- Returns:
- String representation
-
-