Class RealCsrOperations
java.lang.Object
org.flag4j.operations.sparse.csr.real.RealCsrOperations
This class contains low-level implementations for element-wise operations on CSR matrices.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic CMatrix
addToEachCol
(CsrMatrix src1, CVector src2) Adds a vector to each column of a matrix.static Matrix
addToEachCol
(CsrMatrix src1, Vector src2) Adds a vector to each column of a matrix.static CMatrix
addToEachCol
(CsrMatrix src1, CooCVector src2) Adds a vector to each column of a matrix.static Matrix
addToEachCol
(CsrMatrix src1, CooVector src2) Adds a vector to each column of a matrix.static CMatrix
addToEachRow
(CsrMatrix src1, CVector src2) Adds a vector to each row of a matrix.static Matrix
addToEachRow
(CsrMatrix src1, Vector src2) Adds a vector to each row of a matrix.static CMatrix
addToEachRow
(CsrMatrix src1, CooCVector src2) Adds a vector to each row of a matrix.static Matrix
addToEachRow
(CsrMatrix src1, CooVector src2) Adds a vector to each row of a matrix.static CsrMatrix
applyBinOpp
(CsrMatrix src1, CsrMatrix src2, BinaryOperator<Double> opp, UnaryOperator<Double> uOpp) Applies an element-wise binary operation to twoCSR Matrices
.static CsrMatrix
Gets a specified slice of a CSR matrix.static CsrMatrix
Transposes a sparse CSR matrix.
-
Constructor Details
-
RealCsrOperations
private RealCsrOperations()
-
-
Method Details
-
applyBinOpp
public static CsrMatrix applyBinOpp(CsrMatrix src1, CsrMatrix src2, BinaryOperator<Double> 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 todense 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 operations 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.
-
transpose
-
getSlice
Gets a specified slice of a CSR matrix.- Parameters:
src
- Sparse CSR matrix to extract slice from.rowStart
- Starting row index of slice (inclusive).rowEnd
- Ending row index of slice (exclusive).colStart
- Starting column index of slice (inclusive).colEnd
- Ending row index of slice (exclusive).- Returns:
- The specified slice of this matrix. This is a completely new matrix and NOT a view into the matrix.
- Throws:
ArrayIndexOutOfBoundsException
- If any of the indices are out of bounds of this matrix.IllegalArgumentException
- IfrowEnd
is not greater thanrowStart
or ifcolEnd
is not greater thancolStart
.
-
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.
-
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.
-
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.
-