Package org.la4j
Class Matrix
java.lang.Object
org.la4j.Matrix
- Direct Known Subclasses:
DenseMatrix
,SparseMatrix
A real matrix.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
private static final String
private static final NumberFormat
private static final String
private static final String[]
protected int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd
(double value) Adds givenvalue
(v) to every element of this matrix (A).Adds giventhat
matrix (B) to this matrix (A).abstract <T> T
apply
(MatrixMatrixOperation<T> operation, Matrix that) Pipes this matrix to a givenoperation
.abstract <T> T
apply
(MatrixOperation<T> operation) Pipes this matrix to a givenoperation
.abstract <T> T
apply
(MatrixVectorOperation<T> operation, Vector that) Pipes this matrix to a givenoperation
.blank()
Creates the blank matrix (a zero matrix with same size) of this matrix.blankOfColumns
(int columns) Creates the blank matrix (a zero matrix with same size) of this matrix of the given shape:columns
.blankOfRows
(int rows) Creates the blank matrix (a zero matrix with same size) of this matrix of the given shape:rows
.abstract Matrix
blankOfShape
(int rows, int columns) Creates the blank matrix (a zero matrix with same size) of this matrix of the given shape:rows
xcolumns
.static Matrix
Returns a column-major matrix iterator.int
columns()
Returns the number of columns of this matrix.static Matrix
constant
(int rows, int columns, double constant) Creates a constantMatrix
of the given shape andvalue
.copy()
Copies this matrix.copyOfColumns
(int columns) Copies this matrix into the new matrix with specified column dimension:columns
.copyOfRows
(int rows) Copies this matrix into the new matrix with specified row dimension:rows
.abstract Matrix
copyOfShape
(int rows, int columns) Copies this matrix into the new matrix with specified dimensions:rows
andcolumns
.double
Calculates the determinant of this matrix.static Matrix
diagonal
(int size, double diagonal) double
Calculates the product of diagonal elements of this matrix.divide
(double value) Divides every element of this matrix (A) by givenvalue
(v).void
each
(MatrixProcedure procedure) Applies givenprocedure
to each element of this matrix.void
eachInColumn
(int j, VectorProcedure procedure) Applies givenprocedure
to each element of specified column of this matrix.void
eachInRow
(int i, VectorProcedure procedure) Applies givenprocedure
to each element of specified row of this matrix.protected void
ensureDimensionsAreCorrect
(int rows, int columns) protected void
ensureIndexesAreInBounds
(int i, int j) boolean
boolean
Returns true when matrix is equal to givenmatrix
with givenprecision
double
Calculates an Euclidean norm of this matrix, a.k.a.protected void
double
fold
(MatrixAccumulator accumulator) Folds all elements of this matrix with givenaccumulator
.double
foldColumn
(int j, VectorAccumulator accumulator) Folds all elements of specified column in this matrix with givenaccumulator
.double[]
foldColumns
(VectorAccumulator accumulator) Folds all elements (in a column-by-column manner) of this matrix with givenaccumulator
.double
foldRow
(int i, VectorAccumulator accumulator) Folds all elements of specified row in this matrix with givenaccumulator
.double[]
foldRows
(VectorAccumulator accumulator) Folds all elements (in row-by-row manner) of this matrix with givenaccumulator
.static Matrix
from1DArray
(int rows, int columns, double[] array) Creates aMatrix
of the given 1Darray
w/o copying the underlying array.static Matrix
from2DArray
(double[][] array) Creates aMatrix
of the given 2Darray
w/o copying the underlying array.static Matrix
ParsesMatrix
from the given CSV string.static Matrix
ParsesMatrix
from the given Matrix Market string.abstract double
get
(int i, int j) Gets the specified element of this matrix.abstract Vector
getColumn
(int j) Copies the specified column of this matrix into the vector.abstract Vector
getRow
(int i) Copies the specified row of this matrix into the vector.hadamardProduct
(Matrix that) Calculates the Hadamard (element-wise) product of this and giventhat
matrix.int
hashCode()
static Matrix
identity
(int size) Creates an identityMatrix
of the givensize
.private void
indent
(StringBuilder sb, int howMany) double
Calculates an Infinity norm of this matrix.Inserts a giventhat
(B) into this matrix (A).Inserts a giventhat
matrix (B) into this matrix (A).Inserts a giventhat
matrix (B) into this matrix (A).Inserts a giventhat
matrix (B) into this matrix (A).insertColumn
(int j, Vector column) Adds one column to matrix.Adds one row to matrix.boolean
is
(AdvancedMatrixPredicate predicate) Checks whether this matrix compiles with givenpredicate
or not.boolean
is
(MatrixPredicate predicate) Checks whether this matrix compiles with givenpredicate
or not.iterator()
Returns a matrix iterator.iteratorOfColumn
(int j) Returns a vector iterator of the given column {code j}.iteratorOfRow
(int i) Returns a vector iterator of the given row {code i}.kroneckerProduct
(Matrix that) Calculates the Kronecker product of this matrix (A) and giventhat
matrix (B).double
Calculates a Manhattan norm of this matrix, a.k.a.double
max()
Searches for the maximum value of the elements of this matrix.double
maxInColumn
(int j) Searches for the maximum value of specified column in this matrix.double
maxInRow
(int i) Searches for the maximum value of specified row in this matrix.double
min()
Searches for the minimum value of the elements of this matrix.double
minInColumn
(int j) Searches for the minimum value of specified column in this matrix.double
minInRow
(int i) Searches for the minimum value of specified row in this matrix.Converts this matrix into the string representation.mkString
(NumberFormat formatter) Converts this matrix into the string representation.mkString
(NumberFormat formatter, String rowsDelimiter, String columnsDelimiter) Converts this matrix into the string representation.multiply
(double value) Scales this matrix by givenvalue
(v).Multiplies this matrix (A) by giventhat
matrix (B).Multiplies this matrix (A) by giventhat
vector (x).Multiplies this matrix by its transpose.boolean
non
(AdvancedMatrixPredicate predicate) Checks whether this matrix compiles with givenpredicate
or not.boolean
non
(MatrixPredicate predicate) Checks whether this matrix compiles with givenpredicate
or not.double
norm()
Calculates an Euclidean norm of this matrix, a.k.a.power
(int n) Powers this matrix of given exponent {code n}.double
product()
Multiplies up all elements of this matrix.static Matrix
static Matrix
randomSymmetric
(int size, Random random) Creates a random symmetricMatrix
of the givensize
.int
rank()
Calculates the rank of this matrix.removeColumn
(int j) Removes one column from matrix.Removes first column from matrix.Removes first row from matrix.Removes last column from matrix.Removes last row from matrix.removeRow
(int i) Removes one row from matrix.rotate()
Rotates this matrix by 90 degrees to the right.Returns a row-major matrix iterator.int
rows()
Returns the number of rows of this matrix.select
(int[] rowIndices, int[] columnIndices) Returns a new matrix with the selected rows and columns.abstract void
set
(int i, int j, double value) Sets the specified element of this matrix to givenvalue
.void
setAll
(double value) Sets all elements of this matrix to the givenvalue
.void
setColumn
(int j, double value) Sets all elements of the specified column of this matrix to givenvalue
.void
Copies givencolumn
into the specified column of this matrix.void
setRow
(int i, double value) Sets all elements of the specified row of this matrix to givenvalue
.void
Copies givenrow
into the specified row of this matrix.shuffle()
Shuffles this matrix.slice
(int fromRow, int fromColumn, int untilRow, int untilColumn) Retrieves the specified sub-matrix of this matrix.sliceBottomRight
(int fromRow, int fromColumn) Retrieves the specified sub-matrix of this matrix.sliceTopLeft
(int untilRow, int untilColumn) Retrieves the specified sub-matrix of this matrix.subtract
(double value) Subtracts givenvalue
(v) from every element of this matrix (A).Subtracts giventhat
matrix (B) from this matrix (A).double
sum()
Summarizes up all elements of this matrix.void
swapColumns
(int i, int j) Swaps the specified columns of this matrix.void
swapRows
(int i, int j) Swaps the specified rows of this matrix.<T extends Matrix>
Tto
(MatrixFactory<T> factory) Converts this matrix using the givenfactory
.abstract byte[]
toBinary()
Encodes this matrix into a byte array.Converts this matrix into a column-major sparse matrix.Converts this matrix into the column vector.toCSV()
Converts this matrix into the CSV (Comma Separated Value) string.toCSV
(NumberFormat formatter) Converts this matrix into the CSV (Comma Separated Value) string using the givenformatter
.Converts this matrix into a dense matrix.Converts this matrix into the Matrix Market string.abstract String
toMatrixMarket
(NumberFormat formatter) Converts this matrix into the Matrix Market string using the given numberformatter
.Converts this matrix into a row-major sparse matrix.Converts this matrix into the row vector.Converts this matrix into a sparse matrix.toString()
double
trace()
Calculates the trace of this matrix.transform
(MatrixFunction function) Builds a new matrix by applying givenfunction
to each element of this matrix.transformColumn
(int j, VectorFunction function) Builds a new matrix by applying givenfunction
to each element of specified column in this matrix.transformRow
(int i, VectorFunction function) Builds a new matrix by applying givenfunction
to each element of specified row in this matrix.Transposes this matrix.static Matrix
unit
(int rows, int columns) void
update
(MatrixFunction function) Updates all elements of this matrix by applying givenfunction
.void
updateAt
(int i, int j, MatrixFunction function) Updates the specified element of this matrix by applying givenfunction
.void
updateColumn
(int j, VectorFunction function) Updates all elements of the specified column in this matrix by applying givenfunction
.void
updateRow
(int i, VectorFunction function) Updates all elements of the specified row in this matrix by applying givenfunction
.Creates a new decompositor by givenfactory
of this matrix.Creates a new inverter by givenfactory
of this matrix.withSolver
(LinearAlgebra.SolverFactory factory) Creates a new solver by givenfactory
of this matrix.static Matrix
zero
(int rows, int columns) Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
DEFAULT_ROWS_DELIMITER
- See Also:
-
DEFAULT_COLUMNS_DELIMITER
- See Also:
-
DEFAULT_FORMATTER
-
INDENTS
-
rows
protected int rows -
columns
protected int columns
-
-
Constructor Details
-
Matrix
public Matrix()Creates a zero-shape matrix. -
Matrix
public Matrix(int rows, int columns) Creates a matrix of given shaperows
xcolumns
;
-
-
Method Details
-
zero
-
constant
Creates a constantMatrix
of the given shape andvalue
. -
diagonal
-
unit
-
identity
Creates an identityMatrix
of the givensize
. -
random
-
randomSymmetric
Creates a random symmetricMatrix
of the givensize
. -
from1DArray
Creates aMatrix
of the given 1Darray
w/o copying the underlying array. -
from2DArray
Creates aMatrix
of the given 2Darray
w/o copying the underlying array. -
block
-
fromCSV
ParsesMatrix
from the given CSV string.- Parameters:
csv
- the string in CSV format- Returns:
- a parsed matrix
-
fromMatrixMarket
ParsesMatrix
from the given Matrix Market string.- Parameters:
mm
- the string in Matrix Market format- Returns:
- a parsed matrix
-
get
public abstract double get(int i, int j) Gets the specified element of this matrix.- Parameters:
i
- element's row indexj
- element's column index- Returns:
- the element of this matrix
-
set
public abstract void set(int i, int j, double value) Sets the specified element of this matrix to givenvalue
.- Parameters:
i
- element's row indexj
- element's column indexvalue
- element's new value
-
getRow
Copies the specified row of this matrix into the vector.- Parameters:
i
- the row index- Returns:
- the row represented as vector
-
getColumn
Copies the specified column of this matrix into the vector.- Parameters:
j
- the column index- Returns:
- the column represented as vector
-
blankOfShape
Creates the blank matrix (a zero matrix with same size) of this matrix of the given shape:rows
xcolumns
.- Returns:
- blank matrix
-
copyOfShape
Copies this matrix into the new matrix with specified dimensions:rows
andcolumns
.- Parameters:
rows
- the number of rows in new matrixcolumns
- the number of columns in new matrix- Returns:
- the copy of this matrix with new size
-
apply
Pipes this matrix to a givenoperation
.- Type Parameters:
T
- the result type- Parameters:
operation
- the matrix operation (an operation that takes a matrix and returnsT
)- Returns:
- the result of an operation applied to this matrix
-
apply
Pipes this matrix to a givenoperation
.- Type Parameters:
T
- the result type- Parameters:
operation
- the matrix-matrix operation (an operation that takes two matrices and returnsT
)that
- the right hand matrix of the given operation- Returns:
- the result of an operation applied to this matrix
-
apply
Pipes this matrix to a givenoperation
.- Type Parameters:
T
- the result type- Parameters:
operation
- the matrix-vector operation (an operation that takes matrix and vector and returnsT
)that
- the right hand vector of the given operation- Returns:
- the result of an operation applied to this matrix
-
toBinary
public abstract byte[] toBinary()Encodes this matrix into a byte array.- Returns:
- a byte array representing this matrix
-
toMatrixMarket
Converts this matrix into the Matrix Market string using the given numberformatter
.- Returns:
- a string in Matrix Market format representing this matrix;
-
setAll
public void setAll(double value) Sets all elements of this matrix to the givenvalue
.- Parameters:
value
- the element's new value
-
setRow
public void setRow(int i, double value) Sets all elements of the specified row of this matrix to given
value
.- Parameters:
i
- the row indexvalue
- the element's new value
-
setColumn
public void setColumn(int j, double value) Sets all elements of the specified column of this matrix to given
value
.- Parameters:
j
- the column indexvalue
- the element's new value
-
swapRows
public void swapRows(int i, int j) Swaps the specified rows of this matrix.- Parameters:
i
- the row indexj
- the row index
-
swapColumns
public void swapColumns(int i, int j) Swaps the specified columns of this matrix.- Parameters:
i
- the column indexj
- the column index
-
rows
public int rows()Returns the number of rows of this matrix.- Returns:
- the number of rows
-
columns
public int columns()Returns the number of columns of this matrix.- Returns:
- the number of columns
-
transpose
Transposes this matrix.- Returns:
- the transposed matrix
-
rotate
Rotates this matrix by 90 degrees to the right.- Returns:
- the rotated matrix
-
power
Powers this matrix of given exponent {code n}.- Parameters:
n
- the exponent- Returns:
- the powered matrix
-
multiply
Scales this matrix by givenvalue
(v).- Parameters:
value
- the scale factor- Returns:
- A * v
-
multiply
Multiplies this matrix (A) by giventhat
vector (x).- Parameters:
that
- the vector- Returns:
- A * x
-
multiply
Multiplies this matrix (A) by giventhat
matrix (B).- Parameters:
that
- the right hand matrix for multiplication- Returns:
- A * B
-
multiplyByItsTranspose
Multiplies this matrix by its transpose.- Returns:
- this matrix multiplied by its transpose
-
subtract
Subtracts givenvalue
(v) from every element of this matrix (A).- Parameters:
value
- the right hand value for subtraction- Returns:
- A - v
-
subtract
Subtracts giventhat
matrix (B) from this matrix (A).- Parameters:
that
- the right hand matrix for subtraction- Returns:
- A - B
-
add
Adds givenvalue
(v) to every element of this matrix (A).- Parameters:
value
- the right hand value for addition- Returns:
- A + v
-
add
Adds giventhat
matrix (B) to this matrix (A).- Parameters:
that
- the right hand matrix for addition- Returns:
- A + B
-
insert
Inserts a giventhat
(B) into this matrix (A). The original values are overwritten by the new ones.- Parameters:
that
- the matrix to insert, from the first row and column- Returns:
- a matrix with the parameter inserted into it
-
insert
Inserts a giventhat
matrix (B) into this matrix (A). The original values are overwritten by the new ones.- Parameters:
that
- the matrix to insertrows
- number of rows to insertcolumns
- number of columns to insert- Returns:
- a matrix with the parameter inserted into it
-
insert
Inserts a giventhat
matrix (B) into this matrix (A). The original values are overwritten by the new ones.- Parameters:
that
- the matrix to insertdestRow
- the row to insert at in the destination matrixdestColumn
- the column to insert at in the destination matrixrows
- number of rows to insertcolumns
- number of columns to insert- Returns:
- a matrix with the parameter inserted into it
-
insert
public Matrix insert(Matrix that, int srcRow, int srcColumn, int destRow, int destColumn, int rows, int columns) Inserts a giventhat
matrix (B) into this matrix (A). The original values are overwritten by the new ones.- Parameters:
that
- the matrix to insertsrcRow
- the row to start at in the source matrixsrcColumn
- the column to start at in the source matrixdestRow
- the row to insert at in the destination matrixdestColumn
- the column to insert at in the destination matrixrows
- number of rows to insertcolumns
- number of columns to insert- Returns:
- a matrix with the parameter inserted into it
-
divide
Divides every element of this matrix (A) by givenvalue
(v).- Parameters:
value
- the right hand value for division- Returns:
- A / v
-
kroneckerProduct
Calculates the Kronecker product of this matrix (A) and giventhat
matrix (B).- Parameters:
that
- the right hand matrix for Kronecker product- Returns:
- A (+) B
-
trace
public double trace()Calculates the trace of this matrix.See http://mathworld.wolfram.com/MatrixTrace.html for more details.
- Returns:
- the trace of this matrix
-
diagonalProduct
public double diagonalProduct()Calculates the product of diagonal elements of this matrix.- Returns:
- the product of diagonal elements of this matrix
-
norm
public double norm()Calculates an Euclidean norm of this matrix, a.k.a. frobenius norm- Returns:
- an Euclidean norm
-
euclideanNorm
public double euclideanNorm()Calculates an Euclidean norm of this matrix, a.k.a. frobenius norm- Returns:
- an Euclidean norm
-
manhattanNorm
public double manhattanNorm()Calculates a Manhattan norm of this matrix, a.k.a. taxicab norm- Returns:
- a Manhattan norm
-
infinityNorm
public double infinityNorm()Calculates an Infinity norm of this matrix.- Returns:
- an Infinity norm
-
product
public double product()Multiplies up all elements of this matrix.- Returns:
- the product of all elements of this matrix
-
sum
public double sum()Summarizes up all elements of this matrix.- Returns:
- the sum of all elements of this matrix
-
hadamardProduct
Calculates the Hadamard (element-wise) product of this and giventhat
matrix.- Parameters:
that
- the right hand matrix for Hadamard product- Returns:
- the Hadamard product of two matrices
-
determinant
public double determinant()Calculates the determinant of this matrix.See http://mathworld.wolfram.com/Determinant.html for more details.
- Returns:
- the determinant of this matrix
-
rank
public int rank()Calculates the rank of this matrix.See http://mathworld.wolfram.com/MatrixRank.html for more details.
- Returns:
- the rank of this matrix
-
setRow
Copies givenrow
into the specified row of this matrix.- Parameters:
i
- the row indexrow
- the row represented as vector
-
setColumn
Copies givencolumn
into the specified column of this matrix.- Parameters:
j
- the column indexcolumn
- the column represented as vector
-
insertRow
Adds one row to matrix.- Parameters:
i
- the row index- Returns:
- matrix with row.
-
insertColumn
Adds one column to matrix.- Parameters:
j
- the column index- Returns:
- matrix with column.
-
removeRow
Removes one row from matrix.- Parameters:
i
- the row index- Returns:
- matrix without row.
-
removeColumn
Removes one column from matrix.- Parameters:
j
- the column index- Returns:
- matrix without column.
-
removeFirstRow
Removes first row from matrix.- Returns:
- matrix without first row.
-
removeFirstColumn
Removes first column from matrix.- Returns:
- matrix without first column
-
removeLastRow
Removes last row from matrix.- Returns:
- matrix without last row
-
removeLastColumn
Removes last column from matrix.- Returns:
- matrix without last column
-
blank
Creates the blank matrix (a zero matrix with same size) of this matrix.- Returns:
- blank matrix
-
blankOfRows
Creates the blank matrix (a zero matrix with same size) of this matrix of the given shape:rows
. Thecolumns
number remains the same.- Returns:
- blank matrix
-
blankOfColumns
Creates the blank matrix (a zero matrix with same size) of this matrix of the given shape:columns
. Therows
number remains the same.- Returns:
- blank matrix
-
copy
Copies this matrix.- Returns:
- the copy of this matrix
-
copyOfRows
Copies this matrix into the new matrix with specified row dimension:rows
.- Parameters:
rows
- the number of rows in new matrix- Returns:
- the copy of this matrix with new size
-
copyOfColumns
Copies this matrix into the new matrix with specified column dimension:columns
.- Parameters:
columns
- the number of columns in new matrix- Returns:
- the copy of this matrix with new size
-
shuffle
Shuffles this matrix.Copies this matrix into the matrix that contains the same elements but with the elements shuffled around (which might also result in the same matrix (with a small likelihood)).
- Returns:
- the shuffled matrix
-
slice
Retrieves the specified sub-matrix of this matrix. The sub-matrix is specified by intervals for row indices and column indices.- Parameters:
fromRow
- the beginning of the row indices intervalfromColumn
- the beginning of the column indices intervaluntilRow
- the ending of the row indices intervaluntilColumn
- the ending of the column indices interval- Returns:
- the sub-matrix of this matrix
-
sliceTopLeft
Retrieves the specified sub-matrix of this matrix. The sub-matrix is specified by intervals for row indices and column indices. The top left points of both intervals are fixed to zero.- Parameters:
untilRow
- the ending of the row indices intervaluntilColumn
- the ending of the column indices interval- Returns:
- the sub-matrix of this matrix
-
sliceBottomRight
Retrieves the specified sub-matrix of this matrix. The sub-matrix is specified by intervals for row indices and column indices. The bottom right points of both intervals are fixed to matrix dimensions - it's rows and columns correspondingly.- Parameters:
fromRow
- the beginning of the row indices intervalfromColumn
- the beginning of the column indices interval- Returns:
- the sub-matrix of this matrix
-
select
Returns a new matrix with the selected rows and columns. This method can be used either return a specific subset of rows and/or columns or to permute the indices in an arbitrary order. The list of indices are allowed to contain duplicates indices. This is more general than slice() which selects only contiguous blocks. However, where applicable slice() is probably more efficient.- Parameters:
rowIndices
- the array of row indicescolumnIndices
- the array of column indices- Returns:
- the new matrix with the selected rows and columns
- Throws:
IllegalArgumentException
- if invalid row or column indices are provided
-
each
Applies givenprocedure
to each element of this matrix.- Parameters:
procedure
- the matrix procedure
-
eachInRow
Applies givenprocedure
to each element of specified row of this matrix.- Parameters:
i
- the row indexprocedure
- the vector procedure
-
eachInColumn
Applies givenprocedure
to each element of specified column of this matrix.- Parameters:
j
- the column indexprocedure
- the vector procedure
-
max
public double max()Searches for the maximum value of the elements of this matrix.- Returns:
- maximum value of this matrix
-
min
public double min()Searches for the minimum value of the elements of this matrix.- Returns:
- minimum value of this matrix
-
maxInRow
public double maxInRow(int i) Searches for the maximum value of specified row in this matrix.- Parameters:
i
- the row index- Returns:
- maximum value of specified row in this matrix
-
minInRow
public double minInRow(int i) Searches for the minimum value of specified row in this matrix.- Parameters:
i
- the row index- Returns:
- minimum value of specified row in this matrix
-
maxInColumn
public double maxInColumn(int j) Searches for the maximum value of specified column in this matrix.- Parameters:
j
- the column index- Returns:
- maximum value of specified column in this matrix
-
minInColumn
public double minInColumn(int j) Searches for the minimum value of specified column in this matrix.- Parameters:
j
- the column index- Returns:
- minimum value of specified column in this matrix
-
transform
Builds a new matrix by applying givenfunction
to each element of this matrix.- Parameters:
function
- the matrix function- Returns:
- the transformed matrix
-
transformRow
Builds a new matrix by applying givenfunction
to each element of specified row in this matrix.- Parameters:
i
- the row indexfunction
- the vector function- Returns:
- the transformed matrix
-
transformColumn
Builds a new matrix by applying givenfunction
to each element of specified column in this matrix.- Parameters:
j
- the column indexfunction
- the vector function- Returns:
- the transformed matrix
-
update
Updates all elements of this matrix by applying givenfunction
.- Parameters:
function
- the matrix function
-
updateAt
Updates the specified element of this matrix by applying givenfunction
.- Parameters:
i
- the row indexj
- the column indexfunction
- the matrix function
-
updateRow
Updates all elements of the specified row in this matrix by applying givenfunction
.- Parameters:
i
- the row indexfunction
- the vector function
-
updateColumn
Updates all elements of the specified column in this matrix by applying givenfunction
.- Parameters:
j
- the column indexfunction
- the vector function
-
fold
Folds all elements of this matrix with givenaccumulator
.- Parameters:
accumulator
- the matrix accumulator- Returns:
- the accumulated value
-
foldRow
Folds all elements of specified row in this matrix with givenaccumulator
.- Parameters:
i
- the row indexaccumulator
- the vector accumulator- Returns:
- the accumulated value
-
foldRows
Folds all elements (in row-by-row manner) of this matrix with givenaccumulator
.- Parameters:
accumulator
- the vector accumulator- Returns:
- the accumulated double array
-
foldColumn
Folds all elements of specified column in this matrix with givenaccumulator
.- Parameters:
j
- the column indexaccumulator
- the vector accumulator- Returns:
- the accumulated value
-
foldColumns
Folds all elements (in a column-by-column manner) of this matrix with givenaccumulator
.- Parameters:
accumulator
- the vector accumulator- Returns:
- the accumulated double array
-
is
Checks whether this matrix compiles with givenpredicate
or not.- Parameters:
predicate
- the matrix predicate- Returns:
- whether this matrix compiles with predicate
-
is
Checks whether this matrix compiles with givenpredicate
or not.- Parameters:
predicate
- the advanced matrix predicate- Returns:
- whether this matrix compiles with predicate
-
non
Checks whether this matrix compiles with givenpredicate
or not.- Parameters:
predicate
- the matrix predicate- Returns:
- whether this matrix compiles with predicate
-
non
Checks whether this matrix compiles with givenpredicate
or not.- Parameters:
predicate
- the advanced matrix predicate- Returns:
- whether this matrix compiles with predicate
-
toRowVector
Converts this matrix into the row vector.- Returns:
- the row vector of this matrix
-
toColumnVector
Converts this matrix into the column vector.- Returns:
- the column vector of this matrix
-
withSolver
Creates a new solver by givenfactory
of this matrix.- Parameters:
factory
- the solver factory- Returns:
- the linear system solver of this matrix
-
withInverter
Creates a new inverter by givenfactory
of this matrix.- Parameters:
factory
- the inverter factory- Returns:
- the inverter of this matrix
-
withDecompositor
Creates a new decompositor by givenfactory
of this matrix.- Parameters:
factory
- the decompositor factory- Returns:
- the decompositor of this matrix
-
equals
Returns true when matrix is equal to givenmatrix
with givenprecision
- Parameters:
matrix
- matrixprecision
- given precision- Returns:
- equals of this matrix to that
-
mkString
Converts this matrix into the string representation.- Parameters:
formatter
- the number formatter- Returns:
- the matrix converted to a string
-
mkString
Converts this matrix into the string representation.- Parameters:
rowsDelimiter
- the rows' delimitercolumnsDelimiter
- the columns' delimiter- Returns:
- the matrix converted to a string
-
mkString
Converts this matrix into the string representation.- Parameters:
formatter
- the number formatterrowsDelimiter
- the rows' delimitercolumnsDelimiter
- the columns' delimiter- Returns:
- the matrix converted to a string
-
toString
-
iterator
Returns a matrix iterator. -
rowMajorIterator
Returns a row-major matrix iterator.- Returns:
- a row-major matrix iterator.
-
columnMajorIterator
Returns a column-major matrix iterator.- Returns:
- a column-major matrix iterator.
-
iteratorOfRow
Returns a vector iterator of the given row {code i}.- Returns:
- a vector iterator
-
iteratorOfColumn
Returns a vector iterator of the given column {code j}.- Returns:
- a vector iterator
-
hashCode
public int hashCode() -
equals
-
to
Converts this matrix using the givenfactory
.- Type Parameters:
T
- type of the result matrix- Parameters:
factory
- the factory that creates an output matrix- Returns:
- converted matrix
-
toSparseMatrix
Converts this matrix into a sparse matrix.- Returns:
- a sparse matrix
-
toDenseMatrix
Converts this matrix into a dense matrix.- Returns:
- a dense matrix
-
toRowMajorSparseMatrix
Converts this matrix into a row-major sparse matrix.- Returns:
- a row-major sparse matrix
-
toColumnMajorSparseMatrix
Converts this matrix into a column-major sparse matrix.- Returns:
- a row-major sparse matrix
-
toCSV
Converts this matrix into the CSV (Comma Separated Value) string.- Returns:
- a CSV string representing this matrix
-
toMatrixMarket
Converts this matrix into the Matrix Market string.- Returns:
- a string in Matrix Market format representing this matrix;
-
toCSV
Converts this matrix into the CSV (Comma Separated Value) string using the givenformatter
.- Parameters:
formatter
- the number formatter- Returns:
- a CSV string representing this matrix
-
ensureDimensionsAreCorrect
protected void ensureDimensionsAreCorrect(int rows, int columns) -
ensureIndexesAreInBounds
protected void ensureIndexesAreInBounds(int i, int j) -
fail
-
indent
-