Class RealComplexCsrOps
java.lang.Object
org.flag4j.linalg.ops.sparse.csr.real_complex.RealComplexCsrOps
This class contains low-level implementations for element-wise ops on real/complex CSR matrices.
-
Method Summary
Modifier and TypeMethodDescriptionstatic CsrCMatrix
add
(CsrCMatrix a, CsrMatrix b) Computes the element-wise sum of two matrices.static CMatrix
addToEachCol
(CsrCMatrix src1, Vector src2) Adds a vector to each column of a matrix.static CMatrix
addToEachCol
(CsrCMatrix src1, CooVector src2) Adds a vector to each column of a matrix.static CMatrix
addToEachRow
(CsrCMatrix src1, Vector src2) Adds a vector to each row of a matrix.static CMatrix
addToEachRow
(CsrCMatrix src1, CooVector src2) Adds a vector to each row of a matrix.static CsrCMatrix
applyBinOpp
(CsrCMatrix src1, CsrMatrix src2, BiFunction<Complex128, Double, Complex128> opp, UnaryOperator<Double> uOpp) Applies an element-wise binary operation to twoCSR Matrices
.static CsrCMatrix
applyBinOpp
(CsrMatrix src1, CsrCMatrix src2, BiFunction<Double, Complex128, Complex128> opp, UnaryOperator<Complex128> uOpp) Applies an element-wise binary operation to twoCSR Matrices
.static CsrCMatrix
elemMult
(CsrCMatrix src1, CsrMatrix src2) Computes the element-wise multiplication between a complex sparse matrix and a real sparse matrix.static CsrCMatrix
sub
(CsrCMatrix a, CsrMatrix b) Computes the element-wise difference of two matrices.static CsrCMatrix
sub
(CsrMatrix a, CsrCMatrix b) Computes the element-wise difference of two matrices.
-
Method Details
-
applyBinOpp
public static CsrCMatrix applyBinOpp(CsrMatrix src1, CsrCMatrix src2, BiFunction<Double, Complex128, Complex128> opp, UnaryOperator<Complex128> uOpp) Applies an element-wise binary operation to twoCSR Matrices
.
Note, this methods efficiency relies heavily on the assumption that both operand matrices are very large and very sparse. If the two matrices are not large and very sparse, this method will likely be significantly slower than simply converting the matrices to dense matrix and using a dense matrix addition algorithm.- Parameters:
src1
- The first matrix in the operation.src2
- The second matrix in the operation.opp
- Binary operator to apply element-wise tosrc1
andsrc2
.uOpp
- Unary operator for use with binary ops which are not commutative such as subtraction. If the operation is commutative this should benull
. If the binary operation is not commutative, it needs to be decomposable to one commutative binary operationopp
and one unary operationuOpp
such that it is equivalent toopp.apply(x, uOpp.apply(y))
.- Returns:
- The result of applying the specified binary operation to
src1
andsrc2
element-wise. - Throws:
IllegalArgumentException
- Ifsrc1
andsrc2
do not have the same shape.
-
applyBinOpp
public static CsrCMatrix applyBinOpp(CsrCMatrix src1, CsrMatrix src2, BiFunction<Complex128, Double, Complex128> opp, UnaryOperator<Double> uOpp) Applies an element-wise binary operation to twoCSR Matrices
.
Note, this methods efficiency relies heavily on the assumption that both operand matrices are very large and very sparse. If the two matrices are not large and very sparse, this method will likely be significantly slower than simply converting the matrices to dense matrices and using a dense matrix addition algorithm.- Parameters:
src1
- The first matrix in the operation.src2
- The second matrix in the operation.opp
- Binary operator to apply element-wise tosrc1
andsrc2
.uOpp
- Unary operator for use with binary ops which are not commutative such as subtraction. If the operation is commutative this should benull
. If the binary operation is not commutative, it needs to be decomposable to one commutative binary operationopp
and one unary operationuOpp
such that it is equivalent toopp.apply(x, uOpp.apply(y))
.- Returns:
- The result of applying the specified binary operation to
src1
andsrc2
element-wise. - Throws:
IllegalArgumentException
- Ifsrc1
andsrc2
do not have the same shape.
-
elemMult
Computes the element-wise multiplication between a complex sparse matrix and a real sparse matrix.- Parameters:
src1
- The first matrix in the element-wise multiplication.src2
- The second matrix in the element-wise multiplication.- Returns:
- The result of the element-wise multiplication between
src1
andsrc2
. - Throws:
IllegalArgumentException
- Ifsrc1
andsrc2
do not have the same shape.
-
add
Computes the element-wise sum of two matrices.- Parameters:
a
- First matrix in sum.b
- Second matrix in sum.- Returns:
- The element-wise sum of
a
andb
.
-
sub
Computes the element-wise difference of two matrices.- Parameters:
a
- First matrix in difference.b
- Second matrix in difference.- Returns:
- The element-wise difference of
a
andb
.
-
sub
Computes the element-wise difference of two matrices.- Parameters:
a
- First matrix in difference.b
- Second matrix in difference.- Returns:
- The element-wise difference of
a
andb
.
-
addToEachCol
Adds a vector to each column of a matrix. The vector need not be a column vector. If it is a row vector it will be treated as if it were a column vector.- Parameters:
src1
- CSR matrix to add vector to each column of.src2
- Vector to add to each column of this matrix.- Returns:
- The result of adding the vector src2 to each column of this matrix.
-
addToEachCol
Adds a vector to each column of a matrix. The vector need not be a column vector. If it is a row vector it will be treated as if it were a column vector.- Parameters:
src1
- CSR matrix to add vector to each column of.src2
- Vector to add to each column of this matrix.- Returns:
- The result of adding the vector src2 to each column of this matrix.
-
addToEachRow
Adds a vector to each row of a matrix. The vector need not be a row vector. If it is a column vector it will be treated as if it were a row vector for this operation.- Parameters:
src1
- CSR matrix to add vector to each row of.src2
- Vector to add to each row of this matrix.- Returns:
- The result of adding the vector src2 to each row of this matrix.
-
addToEachRow
Adds a vector to each row of a matrix. The vector need not be a row vector. If it is a column vector it will be treated as if it were a row vector for this operation.- Parameters:
src1
- CSR matrix to add vector to each row of.src2
- Vector to add to each row of this matrix.- Returns:
- The result of adding the vector src2 to each row of this matrix.
-