Class CommonOps_FDRM
Common matrix operations are contained here. Which specific underlying algorithm is used is not specified just the out come of the operation. Nor should calls to these functions reply on the underlying implementation. Which algorithm is used can depend on the matrix being passed in.
For more exotic and specialized generic operations see SpecializedOps_FDRM
.
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Performs absolute value of a matrix:
a = abs(a)
aij = abs(aij)static void
Performs absolute value of a matrix:
c = abs(a)
cij = abs(aij)static <T extends FMatrixD1>
Tadd
(float alpha, T a, float beta, T b, T output) Performs the following operation:
c = α * a + β * b
cij = α * aij + β * bijstatic <T extends FMatrixD1>
Tadd
(float alpha, T a, T b, T output) Performs the following operation:
c = α * a + b
cij = α * aij + bijstatic void
Performs an in-place scalar addition:
a = a + val
aij = aij + valstatic <T extends FMatrixD1>
Tadd
(T a, float val, T output) Performs scalar addition:
c = a + val
cij = aij + valstatic <T extends FMatrixD1>
Tadd
(T a, float beta, T b, T output) Performs the following operation:
c = a + β * b
cij = aij + β * bijstatic <T extends FMatrixD1>
Tadd
(T a, T b, T output) Performs the following operation:
c = a + b
cij = aij + bijstatic void
Performs the following operation:
a = a + β * b
aij = aij + β * bijstatic void
Performs the following operation:
a = a + b
aij = aij + bijstatic FMatrixRMaj
apply
(FMatrixRMaj input, FOperatorUnary func) static FMatrixRMaj
apply
(FMatrixRMaj input, FOperatorUnary func, @Nullable FMatrixRMaj output) This applies a given unary function on every value stored in the matrixstatic void
Changes the sign of every element in the matrix.
aij = -aijstatic <T extends FMatrixD1>
TchangeSign
(T input, T output) Changes the sign of every element in the matrix.
outputij = -inputijstatic FMatrixRMaj[]
columnsToVector
(FMatrixRMaj A, @Nullable FMatrixRMaj[] v) Converts the columns in a matrix into a set of vectors.static FMatrixRMaj
concatColumns
(FMatrixRMaj a, FMatrixRMaj b, @Nullable FMatrixRMaj output) output = [a , b]static FMatrixRMaj
Concatenates all the matrices together along their columns.static void
concatRows
(FMatrixRMaj a, FMatrixRMaj b, FMatrixRMaj output) output = [a ; b]static FMatrixRMaj
concatRowsMulti
(FMatrixRMaj... m) Concatenates all the matrices together along their columns.static int
Counts the number of elements in A which are truestatic float
det
(FMatrixRMaj mat) Returns the determinant of the matrix.static FMatrixRMaj
diag
(float... diagEl) Creates a new square matrix whose diagonal elements are specified by diagEl and all the other elements are zero.
aij = 0 if i ≤ j
aij = diag[i] if i = jstatic FMatrixRMaj
diag
(@Nullable FMatrixRMaj ret, int width, float... diagEl) static FMatrixRMaj
diagR
(int numRows, int numCols, float... diagEl) Creates a new rectangular matrix whose diagonal elements are specified by diagEl and all the other elements are zero.
aij = 0 if i ≤ j
aij = diag[i] if i = jstatic void
Performs an in-place element by element scalar division with the scalar on top.
aij = α/aijstatic <T extends FMatrixD1>
Tdivide
(float alpha, T input, T output) Performs an element by element scalar division with the scalar on top.
bij = α/aijstatic void
Performs an in-place element by element scalar division with the scalar on bottom.
aij = aij/αstatic <T extends FMatrixD1>
Tdivide
(T input, float alpha, T output) Performs an element by element scalar division with the scalar on botton.
bij = aij /αstatic void
divideCols
(FMatrixRMaj A, float[] values) Divides every element in column i by value[i].static void
divideRows
(float[] values, FMatrixRMaj A) Divides every element in row i by value[i].static void
divideRowsCols
(float[] diagA, int offsetA, FMatrixRMaj B, float[] diagC, int offsetC) Equivalent to multiplying a matrix B by the inverse of two diagonal matrices.static float
Computes the dot product or inner product between two vectors.static BMatrixRMaj
elementBoolean
(FMatrixRMaj input, DElementCoorBoolean func, @Nullable BMatrixRMaj output) Applies a binary operator to even element in the input matrix.static void
elementDiv
(FMatrixD1 A, FMatrixD1 B) Performs the an element by element division operation:
aij = aij / bijstatic <T extends FMatrixD1>
TelementDiv
(T A, T B, T output) Performs the an element by element division operation:
cij = aij / bijstatic <T extends FMatrixD1>
TelementExp
(T A, T output) Element-wise exp operation
cij = (float)Math.exp(aij)static BMatrixRMaj
elementLessThan
(FMatrixRMaj A, float value, @Nullable BMatrixRMaj output) Applies the > operator to each element in A.static BMatrixRMaj
elementLessThan
(FMatrixRMaj A, FMatrixRMaj B, @Nullable BMatrixRMaj output) Applies the < operator to each element in A.static BMatrixRMaj
elementLessThanOrEqual
(FMatrixRMaj A, float value, @Nullable BMatrixRMaj output) Applies the ≥ operator to each element in A.static BMatrixRMaj
elementLessThanOrEqual
(FMatrixRMaj A, FMatrixRMaj B, @Nullable BMatrixRMaj output) Applies the A ≤ B operator to each element.static <T extends FMatrixD1>
TelementLog
(T A, T output) Element-wise log operation
cij = (float)Math.log(aij)static float
Returns the value of the element in the matrix that has the largest value.
Max{ aij } for all i and jstatic float
elementMax
(FMatrixD1 a, ElementLocation loc) Returns the value of the element in the matrix that has the largest value.
Max{ aij } for all i and jstatic float
Returns the absolute value of the element in the matrix that has the largest absolute value.
Max{ |aij| } for all i and jstatic float
elementMaxAbs
(FMatrixD1 a, ElementLocation loc) Returns the absolute value of the element in the matrix that has the largest absolute value.
Max{ |aij| } for all i and jstatic float
Returns the value of the element in the matrix that has the minimum value.
Min{ aij } for all i and jstatic float
elementMin
(FMatrixD1 a, ElementLocation loc) Returns the value of the element in the matrix that has the minimum value.
Min{ aij } for all i and jstatic float
Returns the absolute value of the element in the matrix that has the smallest absolute value.
Min{ |aij| } for all i and jstatic float
elementMinAbs
(FMatrixD1 a, ElementLocation loc) Returns the absolute value of the element in the matrix that has the smallest absolute value.
Min{ |aij| } for all i and jstatic BMatrixRMaj
elementMoreThan
(FMatrixRMaj A, float value, @Nullable BMatrixRMaj output) Applies the > operator to each element in A.static BMatrixRMaj
elementMoreThanOrEqual
(FMatrixRMaj A, float value, @Nullable BMatrixRMaj output) Applies the ≥ operator to each element in A.static void
elementMult
(FMatrixD1 A, FMatrixD1 B) Performs the an element by element multiplication operation:
aij = aij * bijstatic <T extends FMatrixD1>
TelementMult
(T A, T B, T output) Performs the an element by element multiplication operation:
cij = aij * bijstatic <T extends FMatrixD1>
TelementPower
(float a, T B, T output) Element-wise power operation
cij = a ^ bijstatic <T extends FMatrixD1>
TelementPower
(T A, float b, T output) Element-wise power operation
cij = aij ^ bstatic <T extends FMatrixD1>
TelementPower
(T A, T B, T output) Element-wise power operation
cij = aij ^ bijstatic FMatrixRMaj
elements
(FMatrixRMaj A, BMatrixRMaj marked, @Nullable FMatrixRMaj output) Returns a row matrix which contains all the elements in A which are flagged as true in 'marked'static float
elementSum
(FMatrixD1 mat) Computes the sum of all the elements in the matrix:
sum(i=1:m , j=1:n ; aij)static float
elementSumAbs
(FMatrixD1 mat) Computes the sum of the absolute value all the elements in the matrix:
sum(i=1:m , j=1:n ; |aij|)static void
Extract where the destination is reshaped to match the extracted regionstatic void
Extracts a submatrix from 'src' and inserts it in a submatrix in 'dst'.static void
Extracts a submatrix from 'src' and inserts it in a submatrix in 'dst'.static FMatrixRMaj
extract
(FMatrixRMaj src, int[] rows, int rowsSize, int[] cols, int colsSize, @Nullable FMatrixRMaj dst) Extracts out a matrix from source given a sub matrix with arbitrary rows and columns specified in two array listsstatic FMatrixRMaj
extract
(FMatrixRMaj src, int[] indexes, int length, @Nullable FMatrixRMaj dst) Extracts the elements from the source matrix by their 1D index.static FMatrixRMaj
extract
(FMatrixRMaj src, int srcY0, int srcY1, int srcX0, int srcX1) Creates a new matrix which is the specified submatrix of 'src'static FMatrixRMaj
extractColumn
(FMatrixRMaj a, int column, @Nullable FMatrixRMaj out) Extracts the column from a matrix.static FMatrixRMaj
extractDiag
(FMatrixRMaj src, @Nullable FMatrixRMaj dst) Extracts the diagonal elements 'src' write it to the 'dst' vector.static FMatrixRMaj
extractRow
(FMatrixRMaj a, int row, @Nullable FMatrixRMaj out) Extracts the row from a matrix.static void
Sets every element in the matrix to the specified value.
aij = valuestatic FMatrixRMaj
identity
(int width) Creates an identity matrix of the specified size.
aij = 0 if i ≠ j
aij = 1 if i = jstatic FMatrixRMaj
identity
(int numRows, int numCols) Creates a rectangular matrix which is zero except along the diagonals.static void
insert
(FMatrixRMaj src, FMatrixRMaj dst, int[] rows, int rowsSize, int[] cols, int colsSize) Inserts into the specified elements of dst the source matrix.static void
Inserts matrix 'src' into matrix 'dest' with the (0,0) of src at (row,col) in dest.static boolean
invert
(FMatrixRMaj mat) Performs a matrix inversion operation on the specified matrix and stores the results in the same matrix.
a = a-1static boolean
invert
(FMatrixRMaj mat, FMatrixRMaj result) Performs a matrix inversion operation that does not modify the original and stores the results in another matrix.static boolean
invertSPD
(FMatrixRMaj mat, FMatrixRMaj result) Matrix inverse for symmetric positive definite matrices.static FMatrixRMaj
kron
(FMatrixRMaj A, FMatrixRMaj B, @Nullable FMatrixRMaj C) The Kronecker product of two matrices is defined as:
Cij = aijB
where Cij is a sub matrix inside of C ∈ ℜ m*k × n*l, A ∈ ℜ m × n, and B ∈ ℜ k × l.static FMatrixRMaj
maxCols
(FMatrixRMaj input, @Nullable FMatrixRMaj output) Finds the element with the minimum value along column in the input matrix and returns the results in a vector:
bj = min(i=1:m ; aij)static FMatrixRMaj
maxRows
(FMatrixRMaj input, @Nullable FMatrixRMaj output) Finds the element with the maximum value along each row in the input matrix and returns the results in a vector:
bj = max(i=1:n ; aji)static FMatrixRMaj
minCols
(FMatrixRMaj input, @Nullable FMatrixRMaj output) Finds the element with the minimum value along column in the input matrix and returns the results in a vector:
bj = min(i=1:m ; aij)static FMatrixRMaj
minRows
(FMatrixRMaj input, @Nullable FMatrixRMaj output) Finds the element with the minimum value along each row in the input matrix and returns the results in a vector:
bj = min(i=1:n ; aji)static <T extends FMatrix1Row>
Tmult
(float alpha, T a, T b, T output) Performs the following operation:
c = α * a * b
cij = α ∑k=1:n { * aik * bkj}static <T extends FMatrix1Row>
Tmult
(T a, T b, T output) Performs the following operation:
c = a * b
cij = ∑k=1:n { aik * bkj}static void
multAdd
(float alpha, FMatrix1Row a, FMatrix1Row b, FMatrix1Row c) Performs the following operation:
c = c + α * a * b
cij = cij + α * ∑k=1:n { aik * bkj}static void
multAdd
(FMatrix1Row a, FMatrix1Row b, FMatrix1Row c) Performs the following operation:
c = c + a * b
cij = cij + ∑k=1:n { aik * bkj}static void
multAddTransA
(float alpha, FMatrix1Row a, FMatrix1Row b, FMatrix1Row c) Performs the following operation:
c = c + α * aT * b
cij =cij + α * ∑k=1:n { aki * bkj}static void
multAddTransA
(FMatrix1Row a, FMatrix1Row b, FMatrix1Row c) Performs the following operation:
c = c + aT * b
cij = cij + ∑k=1:n { aki * bkj}static void
multAddTransAB
(float alpha, FMatrix1Row a, FMatrix1Row b, FMatrix1Row c) Performs the following operation:
c = c + α * aT * bT
cij = cij + α * ∑k=1:n { aki * bjk}static void
multAddTransAB
(FMatrix1Row a, FMatrix1Row b, FMatrix1Row c) Performs the following operation:
c = c + aT * bT
cij = cij + ∑k=1:n { aki * bjk}static void
multAddTransB
(float alpha, FMatrix1Row a, FMatrix1Row b, FMatrix1Row c) Performs the following operation:
c = c + α * a * bT
cij = cij + α * ∑k=1:n { aik * bjk}static void
multAddTransB
(FMatrix1Row a, FMatrix1Row b, FMatrix1Row c) Performs the following operation:
c = c + a * bT
cij = cij + ∑k=1:n { aik * bjk}static void
multCols
(FMatrixRMaj A, float[] values) Multiplies every element in column i by value[i].static <T extends FMatrix1Row>
TmultInner
(T a, T output) Computes the matrix multiplication inner product:
c = aT * a
cij = ∑k=1:n { aki * akj}static <T extends FMatrix1Row>
TmultOuter
(T a, T output) Computes the matrix multiplication outer product:
c = a * aT
cij = ∑k=1:m { aik * ajk}static void
multRows
(float[] values, FMatrixRMaj A) Multiplies every element in row i by value[i].static <T extends FMatrix1Row>
TmultTransA
(float alpha, T a, T b, T output) Performs the following operation:
c = α * aT * b
cij = α ∑k=1:n { aki * bkj}static <T extends FMatrix1Row>
TmultTransA
(T a, T b, T output) Performs the following operation:
c = aT * b
cij = ∑k=1:n { aki * bkj}static <T extends FMatrix1Row>
TmultTransAB
(float alpha, T a, T b, T output) Performs the following operation:
c = α * aT * bT
cij = α ∑k=1:n { aki * bjk}static <T extends FMatrix1Row>
TmultTransAB
(T a, T b, T output) Performs the following operation:
c = aT * bT
cij = ∑k=1:n { aki * bjk}static <T extends FMatrix1Row>
TmultTransB
(float alpha, T a, T b, T output) Performs the following operation:
c = α * a * bT
cij = α ∑k=1:n { aik * bjk}static <T extends FMatrix1Row>
TmultTransB
(T a, T b, T output) Performs the following operation:
c = a * bT
cij = ∑k=1:n { aik * bjk}static FMatrixRMaj
permuteRowInv
(int[] pinv, FMatrixRMaj input, FMatrixRMaj output) Applies the row permutation specified by the vector to the input matrix and save the results in the output matrix.static void
pinv
(FMatrixRMaj A, FMatrixRMaj invA) Computes the Moore-Penrose pseudo-inverse:
pinv(A) = (ATA)-1 AT
or
pinv(A) = AT(AAT)-1static void
removeColumns
(FMatrixRMaj A, int col0, int col1) Removes columns from the matrix.static FMatrixRMaj[]
rowsToVector
(FMatrixRMaj A, @Nullable FMatrixRMaj[] v) Converts the rows in a matrix into a set of vectors.static FMatrixRMaj
rref
(FMatrixRMaj A, int numUnknowns, @Nullable FMatrixRMaj reduced) Puts the augmented system matrix into reduced row echelon form (RREF) using Gauss-Jordan elimination with row (partial) pivots.static void
Performs an in-place element by element scalar multiplication.
aij = α*aijstatic void
Performs an element by element scalar multiplication.
bij = α*aijstatic void
scaleCol
(float alpha, FMatrixRMaj A, int col) In-place scaling of a column in Astatic void
scaleRow
(float alpha, FMatrixRMaj A, int row) In-place scaling of a row in Astatic void
setIdentity
(FMatrix1Row mat) Sets all the diagonal elements equal to one and everything else equal to zero.static boolean
solve
(FMatrixRMaj a, FMatrixRMaj b, FMatrixRMaj x) Solves for x in the following equation:
A*x = bstatic boolean
solveSPD
(FMatrixRMaj A, FMatrixRMaj b, FMatrixRMaj x) Linear solver for systems which are symmetric positive definite.
A*x = bstatic <T extends FMatrixD1>
Tsubtract
(float val, T a, T output) Performs matrix scalar subtraction:
c = val - a
cij = val - aijstatic <T extends FMatrixD1>
Tsubtract
(T a, float val, T output) Performs matrix scalar subtraction:
c = a - val
cij = aij - valstatic <T extends FMatrixD1>
Tsubtract
(T a, T b, T output) Performs the following subtraction operation:
c = a - b
cij = aij - bijstatic void
subtractEquals
(FMatrixD1 a, FMatrixD1 b) Performs the following subtraction operation:
a = a - b
aij = aij - bijstatic FMatrixRMaj
sumCols
(FMatrixRMaj input, @Nullable FMatrixRMaj output) Computes the sum of each column in the input matrix and returns the results in a vector:
bj = sum(i=1:m ; aij)static FMatrixRMaj
sumRows
(FMatrixRMaj input, @Nullable FMatrixRMaj output) Computes the sum of each row in the input matrix and returns the results in a vector:
bj = sum(i=1:n ; aji)static void
Given a symmetric matrix which is represented by a lower triangular matrix convert it back into a full symmetric matrix.static void
Given a symmetric matrix which is represented by a lower triangular matrix convert it back into a full symmetric matrix.static float
trace
(FMatrix1Row a) Computes the matrix trace:
trace = ∑i=1:n { aii }
where n = min(numRows,numCols)static void
transpose
(FMatrixRMaj mat) Performs an "in-place" transpose.static FMatrixRMaj
transpose
(FMatrixRMaj A, @Nullable FMatrixRMaj A_tran) Transposes matrix 'a' and stores the results in 'b':
bij = aji
where 'b' is the transpose of 'a'.
-
Method Details
-
mult
Performs the following operation:
c = a * b
cij = ∑k=1:n { aik * bkj}- Parameters:
a
- The left matrix in the multiplication operation. Not modified.b
- The right matrix in the multiplication operation. Not modified.output
- Where the results of the operation are stored. Modified.
-
mult
Performs the following operation:
c = α * a * b
cij = α ∑k=1:n { * aik * bkj}- Parameters:
alpha
- Scaling factor.a
- The left matrix in the multiplication operation. Not modified.b
- The right matrix in the multiplication operation. Not modified.output
- Where the results of the operation are stored. Modified.
-
multTransA
Performs the following operation:
c = aT * b
cij = ∑k=1:n { aki * bkj}- Parameters:
a
- The left matrix in the multiplication operation. Not modified.b
- The right matrix in the multiplication operation. Not modified.output
- Where the results of the operation are stored. Modified.
-
multTransA
Performs the following operation:
c = α * aT * b
cij = α ∑k=1:n { aki * bkj}- Parameters:
alpha
- Scaling factor.a
- The left matrix in the multiplication operation. Not modified.b
- The right matrix in the multiplication operation. Not modified.output
- Where the results of the operation are stored. Modified.
-
multTransB
Performs the following operation:
c = a * bT
cij = ∑k=1:n { aik * bjk}- Parameters:
a
- The left matrix in the multiplication operation. Not modified.b
- The right matrix in the multiplication operation. Not modified.output
- Where the results of the operation are stored. Modified.
-
multTransB
Performs the following operation:
c = α * a * bT
cij = α ∑k=1:n { aik * bjk}- Parameters:
alpha
- Scaling factor.a
- The left matrix in the multiplication operation. Not modified.b
- The right matrix in the multiplication operation. Not modified.output
- Where the results of the operation are stored. Modified.
-
multTransAB
Performs the following operation:
c = aT * bT
cij = ∑k=1:n { aki * bjk}- Parameters:
a
- The left matrix in the multiplication operation. Not modified.b
- The right matrix in the multiplication operation. Not modified.output
- Where the results of the operation are stored. Modified.
-
multTransAB
Performs the following operation:
c = α * aT * bT
cij = α ∑k=1:n { aki * bjk}- Parameters:
alpha
- Scaling factor.a
- The left matrix in the multiplication operation. Not modified.b
- The right matrix in the multiplication operation. Not modified.output
- Where the results of the operation are stored. Modified.
-
dot
Computes the dot product or inner product between two vectors. If the two vectors are columns vectors then it is defined as:
dot(a,b) = a<sup>T</sup> * b
If the vectors are column or row or both is ignored by this function.- Parameters:
a
- Vectorb
- Vector- Returns:
- Dot product of the two vectors
-
multInner
Computes the matrix multiplication inner product:
c = aT * a
cij = ∑k=1:n { aki * akj}Is faster than using a generic matrix multiplication by taking advantage of symmetry. For vectors there is an even faster option, see
VectorVectorMult_FDRM.innerProd(FMatrixD1, FMatrixD1)
- Parameters:
a
- The matrix being multiplied. Not modified.output
- Where the results of the operation are stored. Modified.
-
multOuter
Computes the matrix multiplication outer product:
c = a * aT
cij = ∑k=1:m { aik * ajk}Is faster than using a generic matrix multiplication by taking advantage of symmetry.
- Parameters:
a
- The matrix being multiplied. Not modified.output
- Where the results of the operation are stored. Modified.
-
multAdd
Performs the following operation:
c = c + a * b
cij = cij + ∑k=1:n { aik * bkj}- Parameters:
a
- The left matrix in the multiplication operation. Not modified.b
- The right matrix in the multiplication operation. Not modified.c
- Where the results of the operation are stored. Modified.
-
multAdd
Performs the following operation:
c = c + α * a * b
cij = cij + α * ∑k=1:n { aik * bkj}- Parameters:
alpha
- scaling factor.a
- The left matrix in the multiplication operation. Not modified.b
- The right matrix in the multiplication operation. Not modified.c
- Where the results of the operation are stored. Modified.
-
multAddTransA
Performs the following operation:
c = c + aT * b
cij = cij + ∑k=1:n { aki * bkj}- Parameters:
a
- The left matrix in the multiplication operation. Not modified.b
- The right matrix in the multiplication operation. Not modified.c
- Where the results of the operation are stored. Modified.
-
multAddTransA
Performs the following operation:
c = c + α * aT * b
cij =cij + α * ∑k=1:n { aki * bkj}- Parameters:
alpha
- scaling factora
- The left matrix in the multiplication operation. Not modified.b
- The right matrix in the multiplication operation. Not modified.c
- Where the results of the operation are stored. Modified.
-
multAddTransB
Performs the following operation:
c = c + a * bT
cij = cij + ∑k=1:n { aik * bjk}- Parameters:
a
- The left matrix in the multiplication operation. Not modified.b
- The right matrix in the multiplication operation. Not modified.c
- Where the results of the operation are stored. Modified.
-
multAddTransB
Performs the following operation:
c = c + α * a * bT
cij = cij + α * ∑k=1:n { aik * bjk}- Parameters:
alpha
- Scaling factor.a
- The left matrix in the multiplication operation. Not modified.b
- The right matrix in the multiplication operation. Not modified.c
- Where the results of the operation are stored. Modified.
-
multAddTransAB
Performs the following operation:
c = c + aT * bT
cij = cij + ∑k=1:n { aki * bjk}- Parameters:
a
- The left matrix in the multiplication operation. Not Modified.b
- The right matrix in the multiplication operation. Not Modified.c
- Where the results of the operation are stored. Modified.
-
multAddTransAB
Performs the following operation:
c = c + α * aT * bT
cij = cij + α * ∑k=1:n { aki * bjk}- Parameters:
alpha
- Scaling factor.a
- The left matrix in the multiplication operation. Not Modified.b
- The right matrix in the multiplication operation. Not Modified.c
- Where the results of the operation are stored. Modified.
-
solve
Solves for x in the following equation:
A*x = bIf the system could not be solved then false is returned. If it returns true that just means the algorithm finished operating, but the results could still be bad because 'A' is singular or nearly singular.
If repeat calls to solve are being made then one should consider using
LinearSolverFactory_FDRM
instead.It is ok for 'b' and 'x' to be the same matrix.
- Parameters:
a
- A matrix that is m by n. Not modified.b
- A matrix that is n by k. Not modified.x
- A matrix that is m by k. Modified.- Returns:
- true if it could invert the matrix false if it could not.
-
solveSPD
Linear solver for systems which are symmetric positive definite.
A*x = b- Parameters:
A
- A matrix that is n by n and SPD. Not modified.b
- A matrix that is n by k. Not modified.x
- A matrix that is n by k. Modified.- Returns:
- true if it could invert the matrix false if it could not.
- See Also:
-
transpose
Performs an "in-place" transpose.
For square matrices the transpose is truly in-place and does not require additional memory. For non-square matrices, internally a temporary matrix is declared and
transpose(FMatrixRMaj, FMatrixRMaj)
is invoked.- Parameters:
mat
- The matrix that is to be transposed. Modified.
-
transpose
Transposes matrix 'a' and stores the results in 'b':
bij = aji
where 'b' is the transpose of 'a'.- Parameters:
A
- The original matrix. Not modified.A_tran
- Where the transpose is stored. If null a new matrix is created. Modified.- Returns:
- The transposed matrix.
-
trace
Computes the matrix trace:
trace = ∑i=1:n { aii }
where n = min(numRows,numCols)- Parameters:
a
- (Input) A matrix
-
det
Returns the determinant of the matrix. If the inverse of the matrix is also needed, then usingLUDecomposition_F32
directly (or any similar algorithm) can be more efficient.- Parameters:
mat
- The matrix whose determinant is to be computed. Not modified.- Returns:
- The determinant.
-
invert
Performs a matrix inversion operation on the specified matrix and stores the results in the same matrix.
a = a-1If the algorithm could not invert the matrix then false is returned. If it returns true that just means the algorithm finished. The results could still be bad because the matrix is singular or nearly singular.
- Parameters:
mat
- The matrix that is to be inverted. Results are stored here. Modified.- Returns:
- true if it could invert the matrix false if it could not.
-
invert
Performs a matrix inversion operation that does not modify the original and stores the results in another matrix. The two matrices must have the same dimension.
b = a-1If the algorithm could not invert the matrix then false is returned. If it returns true that just means the algorithm finished. The results could still be bad because the matrix is singular or nearly singular.
For medium to large matrices there might be a slight performance boost to using
LinearSolverFactory_FDRM
instead.- Parameters:
mat
- The matrix that is to be inverted. Not modified.result
- Where the inverse matrix is stored. Modified.- Returns:
- true if it could invert the matrix false if it could not.
-
invertSPD
Matrix inverse for symmetric positive definite matrices. For small matrices an unrolled cholesky is used. Otherwise a standard decomposition.- Parameters:
mat
- (Input) SPD matrixresult
- (Output) Inverted matrix.- Returns:
- true if it could invert the matrix false if it could not.
- See Also:
-
pinv
Computes the Moore-Penrose pseudo-inverse:
pinv(A) = (ATA)-1 AT
or
pinv(A) = AT(AAT)-1
Internally it uses
SolvePseudoInverseSvd_FDRM
to compute the inverse. For performance reasons, this should only be used when a matrix is singular or nearly singular.- Parameters:
A
- A m by n Matrix. Not modified.invA
- Where the computed pseudo inverse is stored. n by m. Modified.
-
columnsToVector
Converts the columns in a matrix into a set of vectors.- Parameters:
A
- Matrix. Not modified.- Returns:
- An array of vectors.
-
rowsToVector
Converts the rows in a matrix into a set of vectors.- Parameters:
A
- Matrix. Not modified.- Returns:
- An array of vectors.
-
setIdentity
Sets all the diagonal elements equal to one and everything else equal to zero. If this is a square matrix then it will be an identity matrix.- Parameters:
mat
- A square matrix.- See Also:
-
identity
Creates an identity matrix of the specified size.
aij = 0 if i ≠ j
aij = 1 if i = j
- Parameters:
width
- The width and height of the identity matrix.- Returns:
- A new instance of an identity matrix.
-
identity
Creates a rectangular matrix which is zero except along the diagonals.- Parameters:
numRows
- Number of rows in the matrix.numCols
- NUmber of columns in the matrix.- Returns:
- A matrix with diagonal elements equal to one.
-
diag
Creates a new square matrix whose diagonal elements are specified by diagEl and all the other elements are zero.
aij = 0 if i ≤ j
aij = diag[i] if i = j
- Parameters:
diagEl
- Contains the values of the diagonal elements of the resulting matrix.- Returns:
- A new matrix.
- See Also:
-
diag
- See Also:
-
diagR
Creates a new rectangular matrix whose diagonal elements are specified by diagEl and all the other elements are zero.
aij = 0 if i ≤ j
aij = diag[i] if i = j
- Parameters:
numRows
- Number of rows in the matrix.numCols
- Number of columns in the matrix.diagEl
- Contains the values of the diagonal elements of the resulting matrix.- Returns:
- A new matrix.
- See Also:
-
kron
The Kronecker product of two matrices is defined as:
Cij = aijB
where Cij is a sub matrix inside of C ∈ ℜ m*k × n*l, A ∈ ℜ m × n, and B ∈ ℜ k × l.- Parameters:
A
- The left matrix in the operation. Not modified.B
- The right matrix in the operation. Not modified.C
- Where the results of the operation are stored. Nullable. Modified.
-
extract
public static void extract(FMatrix src, int srcY0, int srcY1, int srcX0, int srcX1, FMatrix dst, int dstY0, int dstX0) Extracts a submatrix from 'src' and inserts it in a submatrix in 'dst'.
si-y0 , j-x0 = oij for all y0 ≤ i < y1 and x0 ≤ j < x1
where 'sij' is an element in the submatrix and 'oij' is an element in the original matrix.- Parameters:
src
- The original matrix which is to be copied. Not modified.srcX0
- Start column.srcX1
- Stop column+1.srcY0
- Start row.srcY1
- Stop row+1.dst
- Where the submatrix are stored. Modified.dstY0
- Start row in dst.dstX0
- start column in dst.
-
extract
Extract where the destination is reshaped to match the extracted region- Parameters:
src
- The original matrix which is to be copied. Not modified.srcX0
- Start column.srcX1
- Stop column+1.srcY0
- Start row.srcY1
- Stop row+1.dst
- Where the submatrix are stored. Modified.
-
extract
Extracts a submatrix from 'src' and inserts it in a submatrix in 'dst'. Uses the shape of dst to determine the size of the matrix extracted.
- Parameters:
src
- The original matrix which is to be copied. Not modified.srcY0
- Start row in src.srcX0
- Start column in src.dst
- Where the matrix is extracted into.
-
extract
Creates a new matrix which is the specified submatrix of 'src'
si-y0 , j-x0 = oij for all y0 ≤ i < y1 and x0 ≤ j < x1
where 'sij' is an element in the submatrix and 'oij' is an element in the original matrix.- Parameters:
src
- The original matrix which is to be copied. Not modified.srcX0
- Start column.srcX1
- Stop column+1.srcY0
- Start row.srcY1
- Stop row+1.- Returns:
- Extracted submatrix.
-
extract
public static FMatrixRMaj extract(FMatrixRMaj src, int[] rows, int rowsSize, int[] cols, int colsSize, @Nullable @Nullable FMatrixRMaj dst) Extracts out a matrix from source given a sub matrix with arbitrary rows and columns specified in two array lists- Parameters:
src
- Source matrix. Not modified.rows
- array of row indexesrowsSize
- maximum element in row arraycols
- array of column indexescolsSize
- maximum element in column arraydst
- output matrix. Must be correct shape.
-
extract
public static FMatrixRMaj extract(FMatrixRMaj src, int[] indexes, int length, @Nullable @Nullable FMatrixRMaj dst) Extracts the elements from the source matrix by their 1D index.- Parameters:
src
- Source matrix. Not modified.indexes
- array of row indexeslength
- maximum element in row arraydst
- output matrix. Must be a vector of the correct length.
-
insert
public static void insert(FMatrixRMaj src, FMatrixRMaj dst, int[] rows, int rowsSize, int[] cols, int colsSize) Inserts into the specified elements of dst the source matrix.for i in len(rows): for j in len(cols): dst(rows[i],cols[j]) = src(i,j)
- Parameters:
src
- Source matrix. Not modified.dst
- output matrix. Must be correct shape.rows
- array of row indexes.rowsSize
- maximum element in row arraycols
- array of column indexescolsSize
- maximum element in column array
-
extractDiag
Extracts the diagonal elements 'src' write it to the 'dst' vector. 'dst' can either be a row or column vector.
- Parameters:
src
- Matrix whose diagonal elements are being extracted. Not modified.dst
- A vector the results will be written into. Modified.
-
extractRow
Extracts the row from a matrix.- Parameters:
a
- Input matrixrow
- Which row is to be extractedout
- output. Storage for the extracted row. If null then a new vector will be returned.- Returns:
- The extracted row.
-
extractColumn
public static FMatrixRMaj extractColumn(FMatrixRMaj a, int column, @Nullable @Nullable FMatrixRMaj out) Extracts the column from a matrix.- Parameters:
a
- Input matrixcolumn
- Which column is to be extractedout
- output. Storage for the extracted column. If null then a new vector will be returned.- Returns:
- The extracted column.
-
removeColumns
Removes columns from the matrix.- Parameters:
A
- Matrix. Modifiedcol0
- First columncol1
- Last column, inclusive.
-
insert
Inserts matrix 'src' into matrix 'dest' with the (0,0) of src at (row,col) in dest. This is equivalent to calling extract(src,0,src.numRows,0,src.numCols,dest,destY0,destX0).- Parameters:
src
- matrix that is being copied into dest. Not modified.dest
- Where src is being copied into. Modified.destY0
- Start row for the copy into dest.destX0
- Start column for the copy into dest.
-
elementMax
Returns the value of the element in the matrix that has the largest value.
Max{ aij } for all i and j
- Parameters:
a
- A matrix. Not modified.- Returns:
- The max element value of the matrix.
-
elementMax
Returns the value of the element in the matrix that has the largest value.
Max{ aij } for all i and j
- Parameters:
a
- A matrix. Not modified.loc
- (Output) Location of selected element.- Returns:
- The max element value of the matrix.
-
elementMaxAbs
Returns the absolute value of the element in the matrix that has the largest absolute value.
Max{ |aij| } for all i and j
- Parameters:
a
- A matrix. Not modified.- Returns:
- The max abs element value of the matrix.
-
elementMaxAbs
Returns the absolute value of the element in the matrix that has the largest absolute value.
Max{ |aij| } for all i and j
- Parameters:
a
- A matrix. Not modified.loc
- (Output) Location of element element.- Returns:
- The max abs element value of the matrix.
-
elementMin
Returns the value of the element in the matrix that has the minimum value.
Min{ aij } for all i and j
- Parameters:
a
- A matrix. Not modified.- Returns:
- The value of element in the matrix with the minimum value.
-
elementMin
Returns the value of the element in the matrix that has the minimum value.
Min{ aij } for all i and j
- Parameters:
a
- A matrix. Not modified.loc
- (Output) Location of selected element.- Returns:
- The value of element in the matrix with the minimum value.
-
elementMinAbs
Returns the absolute value of the element in the matrix that has the smallest absolute value.
Min{ |aij| } for all i and j
- Parameters:
a
- A matrix. Not modified.- Returns:
- The max element value of the matrix.
-
elementMinAbs
Returns the absolute value of the element in the matrix that has the smallest absolute value.
Min{ |aij| } for all i and j
- Parameters:
a
- (Input) A matrix. Not modified.loc
- (Output) Location of selected element.- Returns:
- The max element value of the matrix.
-
elementMult
Performs the an element by element multiplication operation:
aij = aij * bij
- Parameters:
A
- The left matrix in the multiplication operation. Modified.B
- The right matrix in the multiplication operation. Not modified.
-
elementMult
Performs the an element by element multiplication operation:
cij = aij * bij
- Parameters:
A
- The left matrix in the multiplication operation. Not modified.B
- The right matrix in the multiplication operation. Not modified.output
- Where the results of the operation are stored. Modified.
-
elementDiv
Performs the an element by element division operation:
aij = aij / bij
- Parameters:
A
- The left matrix in the division operation. Modified.B
- The right matrix in the division operation. Not modified.
-
elementDiv
Performs the an element by element division operation:
cij = aij / bij
- Parameters:
A
- The left matrix in the division operation. Not modified.B
- The right matrix in the division operation. Not modified.output
- Where the results of the operation are stored. Modified.
-
elementSum
Computes the sum of all the elements in the matrix:
sum(i=1:m , j=1:n ; aij)- Parameters:
mat
- An m by n matrix. Not modified.- Returns:
- The sum of the elements.
-
elementSumAbs
Computes the sum of the absolute value all the elements in the matrix:
sum(i=1:m , j=1:n ; |aij|)- Parameters:
mat
- An m by n matrix. Not modified.- Returns:
- The sum of the absolute value of each element.
-
elementPower
Element-wise power operation
cij = aij ^ bij- Parameters:
A
- left sideB
- right sideoutput
- output (modified)
-
elementPower
Element-wise power operation
cij = a ^ bij- Parameters:
a
- left scalarB
- right sideoutput
- output (modified)
-
elementPower
Element-wise power operation
cij = aij ^ b- Parameters:
A
- left sideb
- right scalaroutput
- output (modified)
-
elementLog
Element-wise log operation
cij = (float)Math.log(aij)- Parameters:
A
- (input) A matrixoutput
- (input/output) Storage for results. can be null. (modified)- Returns:
- The results
-
elementExp
Element-wise exp operation
cij = (float)Math.exp(aij)- Parameters:
A
- (input) A matrixoutput
- (input/output) Storage for results. can be null. (modified)- Returns:
- The results
-
multRows
Multiplies every element in row i by value[i].- Parameters:
values
- array. Not modified.A
- Matrix. Modified.
-
divideRows
Divides every element in row i by value[i].- Parameters:
values
- array. Not modified.A
- Matrix. Modified.
-
multCols
Multiplies every element in column i by value[i].- Parameters:
A
- Matrix. Modified.values
- array. Not modified.
-
divideCols
Divides every element in column i by value[i].- Parameters:
A
- Matrix. Modified.values
- array. Not modified.
-
divideRowsCols
public static void divideRowsCols(float[] diagA, int offsetA, FMatrixRMaj B, float[] diagC, int offsetC) Equivalent to multiplying a matrix B by the inverse of two diagonal matrices. B = inv(A)*B*inv(C), where A=diag(a) and C=diag(c).- Parameters:
diagA
- Array of length offsteA + B.numRowsoffsetA
- First index in AB
- Rectangular matrixdiagC
- Array of length indexC + B.numColsoffsetC
- First index in C
-
sumRows
Computes the sum of each row in the input matrix and returns the results in a vector:
bj = sum(i=1:n ; aji)- Parameters:
input
- INput matrix whose rows are summed.output
- Optional storage for output. Reshaped into a column. Modified.- Returns:
- Vector containing the sum of each row in the input.
-
minRows
Finds the element with the minimum value along each row in the input matrix and returns the results in a vector:
bj = min(i=1:n ; aji)- Parameters:
input
- Input matrixoutput
- Optional storage for output. Reshaped into a column. Modified.- Returns:
- Vector containing the sum of each row in the input.
-
maxRows
Finds the element with the maximum value along each row in the input matrix and returns the results in a vector:
bj = max(i=1:n ; aji)- Parameters:
input
- Input matrixoutput
- Optional storage for output. Reshaped into a column. Modified.- Returns:
- Vector containing the sum of each row in the input.
-
sumCols
Computes the sum of each column in the input matrix and returns the results in a vector:
bj = sum(i=1:m ; aij)- Parameters:
input
- Input matrixoutput
- Optional storage for output. Reshaped into a row vector. Modified.- Returns:
- Vector containing the sum of each column
-
minCols
Finds the element with the minimum value along column in the input matrix and returns the results in a vector:
bj = min(i=1:m ; aij)- Parameters:
input
- Input matrixoutput
- Optional storage for output. Reshaped into a row vector. Modified.- Returns:
- Vector containing the minimum of each column
-
maxCols
Finds the element with the minimum value along column in the input matrix and returns the results in a vector:
bj = min(i=1:m ; aij)- Parameters:
input
- Input matrixoutput
- Optional storage for output. Reshaped into a row vector. Modified.- Returns:
- Vector containing the maximum of each column
-
addEquals
Performs the following operation:
a = a + b
aij = aij + bij
- Parameters:
a
- (input/output) A Matrix. Modified.b
- (input) A Matrix. Not modified.
-
addEquals
Performs the following operation:
a = a + β * b
aij = aij + β * bij- Parameters:
beta
- The number that matrix 'b' is multiplied by.a
- (input/output) A Matrix. Modified.b
- (input) A Matrix. Not modified.
-
add
Performs the following operation:
c = a + b
cij = aij + bij
Matrix C can be the same instance as Matrix A and/or B.
- Parameters:
a
- A Matrix. Not modified.b
- A Matrix. Not modified.output
- (output) A Matrix where the results are stored. Can be null. Modified.- Returns:
- The results.
-
add
Performs the following operation:
c = a + β * b
cij = aij + β * bij
Matrix C can be the same instance as Matrix A and/or B.
- Parameters:
a
- A Matrix. Not modified.beta
- Scaling factor for matrix b.b
- A Matrix. Not modified.output
- (output) A Matrix where the results are stored. Can be null. Modified.- Returns:
- The results.
-
add
Performs the following operation:
c = α * a + β * b
cij = α * aij + β * bij
Matrix C can be the same instance as Matrix A and/or B.
- Parameters:
alpha
- A scaling factor for matrix a.a
- A Matrix. Not modified.beta
- A scaling factor for matrix b.b
- A Matrix. Not modified.output
- (output) A Matrix where the results are stored. Can be null. Modified.- Returns:
- The results.
-
add
Performs the following operation:
c = α * a + b
cij = α * aij + bij
Matrix C can be the same instance as Matrix A and/or B.
- Parameters:
alpha
- A scaling factor for matrix a.a
- A Matrix. Not modified.b
- A Matrix. Not modified.output
- (output) A Matrix where the results are stored. Can be null. Modified.- Returns:
- The results.
-
add
Performs an in-place scalar addition:
a = a + val
aij = aij + val
- Parameters:
a
- A matrix. Modified.val
- The value that's added to each element.
-
add
Performs scalar addition:
c = a + val
cij = aij + val
- Parameters:
a
- A matrix. Not modified.val
- The value that's added to each element.output
- (output) Storage for results. Can be null. Modified.- Returns:
- The resulting matrix
-
subtract
Performs matrix scalar subtraction:
c = a - val
cij = aij - val
- Parameters:
a
- (input) A matrix. Not modified.val
- (input) The value that's subtracted to each element.output
- (output) Storage for results. Can be null. Modified.- Returns:
- The resulting matrix
-
subtract
Performs matrix scalar subtraction:
c = val - a
cij = val - aij
- Parameters:
val
- (input) The value that's subtracted to each element.a
- (input) A matrix. Not modified.output
- (output) Storage for results. Can be null. Modified.- Returns:
- The resulting matrix
-
subtractEquals
Performs the following subtraction operation:
a = a - b
aij = aij - bij- Parameters:
a
- (input) A Matrix. Modified.b
- (input) A Matrix. Not modified.
-
subtract
Performs the following subtraction operation:
c = a - b
cij = aij - bijMatrix C can be the same instance as Matrix A and/or B.
- Parameters:
a
- (input) A Matrix. Not modified.b
- (input) A Matrix. Not modified.output
- (output) A Matrix. Can be null. Modified.- Returns:
- The resulting matrix
-
scale
Performs an in-place element by element scalar multiplication.
aij = α*aij- Parameters:
a
- The matrix that is to be scaled. Modified.alpha
- the amount each element is multiplied by.
-
scale
Performs an element by element scalar multiplication.
bij = α*aij- Parameters:
alpha
- the amount each element is multiplied by.a
- The matrix that is to be scaled. Not modified.b
- Where the scaled matrix is stored. Modified.
-
scaleRow
In-place scaling of a row in A- Parameters:
alpha
- scale factorA
- matrixrow
- which row in A
-
scaleCol
In-place scaling of a column in A- Parameters:
alpha
- scale factorA
- matrixcol
- which row in A
-
divide
Performs an in-place element by element scalar division with the scalar on top.
aij = α/aij- Parameters:
a
- (input/output) The matrix whose elements are divide the scalar. Modified.alpha
- top value in division
-
divide
Performs an in-place element by element scalar division with the scalar on bottom.
aij = aij/α- Parameters:
a
- (input/output) The matrix whose elements are to be divided. Modified.alpha
- the amount each element is divided by.
-
divide
Performs an element by element scalar division with the scalar on top.
bij = α/aij- Parameters:
alpha
- The numerator.input
- The matrix whose elements are the divisor. Not modified.output
- Where the results are stored. Modified. Can be null.- Returns:
- The resulting matrix
-
divide
Performs an element by element scalar division with the scalar on botton.
bij = aij /α- Parameters:
input
- The matrix whose elements are to be divided. Not modified.alpha
- the amount each element is divided by.output
- Where the results are stored. Modified. Can be null.- Returns:
- The resulting matrix
-
changeSign
Changes the sign of every element in the matrix.
aij = -aij- Parameters:
a
- A matrix. Modified.
-
changeSign
Changes the sign of every element in the matrix.
outputij = -inputij- Parameters:
input
- A matrix. Modified.
-
fill
Sets every element in the matrix to the specified value.
aij = value- Parameters:
a
- A matrix whose elements are about to be set. Modified.value
- The value each element will have.
-
rref
public static FMatrixRMaj rref(FMatrixRMaj A, int numUnknowns, @Nullable @Nullable FMatrixRMaj reduced) Puts the augmented system matrix into reduced row echelon form (RREF) using Gauss-Jordan elimination with row (partial) pivots. A matrix is said to be in RREF is the following conditions are true:
- If a row has non-zero entries, then the first non-zero entry is 1. This is known as the leading one.
- If a column contains a leading one then all other entries in that column are zero.
- If a row contains a leading 1, then each row above contains a leading 1 further to the left.
[1] Page 19 in, Otter Bretscherm "Linear Algebra with Applications" Prentice-Hall Inc, 1997
- Parameters:
A
- Input matrix. Unmodified.numUnknowns
- Number of unknowns/columns that are reduced. Set to -1 to default to A.numCols, which works for most applications.reduced
- Storage for reduced echelon matrix. If null then a new matrix is returned. Modified.- Returns:
- Reduced echelon form of A
- See Also:
-
elementLessThan
public static BMatrixRMaj elementLessThan(FMatrixRMaj A, float value, @Nullable @Nullable BMatrixRMaj output) Applies the > operator to each element in A. Results are stored in a boolean matrix.- Parameters:
A
- Input matrxvalue
- value each element is compared againstoutput
- (Optional) Storage for results. Can be null. Is reshaped.- Returns:
- Boolean matrix with results
- See Also:
-
elementLessThanOrEqual
public static BMatrixRMaj elementLessThanOrEqual(FMatrixRMaj A, float value, @Nullable @Nullable BMatrixRMaj output) Applies the ≥ operator to each element in A. Results are stored in a boolean matrix.- Parameters:
A
- Input matrixvalue
- value each element is compared againstoutput
- (Optional) Storage for results. Can be null. Is reshaped.- Returns:
- Boolean matrix with results
- See Also:
-
elementMoreThan
public static BMatrixRMaj elementMoreThan(FMatrixRMaj A, float value, @Nullable @Nullable BMatrixRMaj output) Applies the > operator to each element in A. Results are stored in a boolean matrix.- Parameters:
A
- Input matrixvalue
- value each element is compared againstoutput
- (Optional) Storage for results. Can be null. Is reshaped.- Returns:
- Boolean matrix with results
- See Also:
-
elementMoreThanOrEqual
public static BMatrixRMaj elementMoreThanOrEqual(FMatrixRMaj A, float value, @Nullable @Nullable BMatrixRMaj output) Applies the ≥ operator to each element in A. Results are stored in a boolean matrix.- Parameters:
A
- Input matrixvalue
- value each element is compared againstoutput
- (Optional) Storage for results. Can be null. Is reshaped.- Returns:
- Boolean matrix with results
- See Also:
-
elementLessThan
public static BMatrixRMaj elementLessThan(FMatrixRMaj A, FMatrixRMaj B, @Nullable @Nullable BMatrixRMaj output) Applies the < operator to each element in A. Results are stored in a boolean matrix.- Parameters:
A
- Input matrixB
- Input matrixoutput
- (Optional) Storage for results. Can be null. Is reshaped.- Returns:
- Boolean matrix with results
- See Also:
-
elementLessThanOrEqual
public static BMatrixRMaj elementLessThanOrEqual(FMatrixRMaj A, FMatrixRMaj B, @Nullable @Nullable BMatrixRMaj output) Applies the A ≤ B operator to each element. Results are stored in a boolean matrix.- Parameters:
A
- Input matrixB
- Input matrixoutput
- (Optional) Storage for results. Can be null. Is reshaped.- Returns:
- Boolean matrix with results
- See Also:
-
elements
public static FMatrixRMaj elements(FMatrixRMaj A, BMatrixRMaj marked, @Nullable @Nullable FMatrixRMaj output) Returns a row matrix which contains all the elements in A which are flagged as true in 'marked'- Parameters:
A
- Input matrixmarked
- Input matrix marking elements in Aoutput
- Storage for output row vector. Can be null. Will be reshaped.- Returns:
- Row vector with marked elements
-
countTrue
Counts the number of elements in A which are true- Parameters:
A
- input matrix- Returns:
- number of true elements
-
concatColumns
public static FMatrixRMaj concatColumns(FMatrixRMaj a, FMatrixRMaj b, @Nullable @Nullable FMatrixRMaj output) output = [a , b] -
concatColumnsMulti
Concatenates all the matrices together along their columns. If the rows do not match the upper elements are set to zero.
A = [ m[0] , ... , m[n-1] ]- Parameters:
m
- Set of matrices- Returns:
- Resulting matrix
-
concatRows
output = [a ; b] -
concatRowsMulti
Concatenates all the matrices together along their columns. If the rows do not match the upper elements are set to zero.
A = [ m[0] ; ... ; m[n-1] ]- Parameters:
m
- Set of matrices- Returns:
- Resulting matrix
-
permuteRowInv
Applies the row permutation specified by the vector to the input matrix and save the results in the output matrix. output[perm[j],:] = input[j,:]- Parameters:
pinv
- (Input) Inverse permutation vector. Specifies new order of the rows.input
- (Input) Matrix which is to be permutedoutput
- (Output) Matrix which has the permutation stored in it. Is reshaped.
-
abs
Performs absolute value of a matrix:
c = abs(a)
cij = abs(aij)- Parameters:
a
- A matrix. Not modified.c
- A matrix. Modified.
-
abs
Performs absolute value of a matrix:
a = abs(a)
aij = abs(aij)- Parameters:
a
- A matrix. Modified.
-
symmLowerToFull
Given a symmetric matrix which is represented by a lower triangular matrix convert it back into a full symmetric matrix.- Parameters:
A
- (Input) Lower triangular matrix (Output) symmetric matrix
-
symmUpperToFull
Given a symmetric matrix which is represented by a lower triangular matrix convert it back into a full symmetric matrix.- Parameters:
A
- (Input) Lower triangular matrix (Output) symmetric matrix
-
apply
public static FMatrixRMaj apply(FMatrixRMaj input, FOperatorUnary func, @Nullable @Nullable FMatrixRMaj output) This applies a given unary function on every value stored in the matrixoutput[i,j] = func(input[i,j])
A and B can be the same instance.- Parameters:
input
- (Input) input matrix. Not modifiedfunc
- Unary function accepting a floatoutput
- (Output) Matrix. Can be same instance as A. Modified.- Returns:
- The output matrix
-
apply
-
elementBoolean
public static BMatrixRMaj elementBoolean(FMatrixRMaj input, DElementCoorBoolean func, @Nullable @Nullable BMatrixRMaj output) Applies a binary operator to even element in the input matrix. In the lambda, the coordinate (row, col), and the value at that element is provided. This is designed to enable arbitrary operations.
For example, to apply an arbitrary boolean operatorto elements between two matrices, you can do the following:BMatrixRMaj found = CommonOps_FDRM.elementBoolean(A, ( row, col, value ) -> B.get(row, col) < value, null);
- Parameters:
input
- Input matrixfunc
- Element wise function that outputs a boolean valueoutput
- (Optional) Output matrix.- Returns:
- Resulting binary matrix
-