Class SemiringCsrMatMult
java.lang.Object
org.flag4j.linalg.ops.sparse.csr.semiring_ops.SemiringCsrMatMult
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Semiring<T>>
voidstandard
(Shape shape1, T[] src1Entries, int[] src1RowPointers, int[] src1ColIndices, Shape shape2, T[] src2Entries, int[] src2RowPointers, int[] src2ColIndices, T[] destEntries, Semiring<T> zero) Computes the matrix multiplication between two sparse CSR matrices.static <T extends Semiring<T>>
SparseMatrixData<T> standardToSparse
(Shape shape1, T[] src1Entries, int[] src1RowPointers, int[] src1ColIndices, Shape shape2, T[] src2Entries, int[] src2RowPointers, int[] src2ColIndices) Computes the matrix multiplication between two sparse CSR matrices and returns the result as a sparse matrix.static <T extends Semiring<T>>
voidstandardVector
(Shape shape, T[] src1, int[] rowPointers, int[] colIndices, int size, T[] src2, int[] indices, T[] dest, T zero) Computes the matrix-vector multiplication between a sparse CSR matrix and a sparse COO vector.
-
Method Details
-
standard
public static <T extends Semiring<T>> void standard(Shape shape1, T[] src1Entries, int[] src1RowPointers, int[] src1ColIndices, Shape shape2, T[] src2Entries, int[] src2RowPointers, int[] src2ColIndices, T[] destEntries, Semiring<T> zero) Computes the matrix multiplication between two sparse CSR matrices. The result is a dense matrix.- Parameters:
shape1
- Shape of the first matrix in the matrix multiplication.src1Entries
- Non-zero data of the first CSR matrix in the matrix multiplication.src1RowPointers
- Non-zero row pointers of the first CSR matrix in the matrix multiplication.src1ColIndices
- Non-zero column indices of the first CSR matrix in the matrix multiplication.shape2
- Shape of the second matrix in the matrix multiplication.src2Entries
- Non-zero data of the second CSR matrix in the matrix multiplication.src2RowPointers
- Non-zero row pointers of the second CSR matrix in the matrix multiplication.src2ColIndices
- Non-zero column indices of the second CSR matrix in the matrix multiplication.destEntries
- Array to store the dense result of the matrix multiplication in (modified).zero
- The zero value of the semiring.
-
standardToSparse
public static <T extends Semiring<T>> SparseMatrixData<T> standardToSparse(Shape shape1, T[] src1Entries, int[] src1RowPointers, int[] src1ColIndices, Shape shape2, T[] src2Entries, int[] src2RowPointers, int[] src2ColIndices) Computes the matrix multiplication between two sparse CSR matrices and returns the result as a sparse matrix.
Warning: This method may be slower than
standard(Shape, Semiring[], int[], int[], Shape, Semiring[], int[], int[], Semiring[], Semiring)
if the result of multiplying this matrix withsrc2
is not very sparse. Further, multiplying two sparse matrices (even very sparse matrices) may result in a dense matrix so this method should be used with caution.- Parameters:
shape1
- Shape of the first matrix in the matrix multiplication.src1Entries
- Non-zero data of the first CSR matrix in the matrix multiplication.src1RowPointers
- Non-zero row pointers of the first CSR matrix in the matrix multiplication.src1ColIndices
- Non-zero column indices of the first CSR matrix in the matrix multiplication.shape2
- Shape of the second matrix in the matrix multiplication.src2Entries
- Non-zero data of the second CSR matrix in the matrix multiplication.src2RowPointers
- Non-zero row pointers of the second CSR matrix in the matrix multiplication.src2ColIndices
- Non-zero column indices of the second CSR matrix in the matrix multiplication.- Returns:
- Sparse CSR matrix resulting from the matrix multiplication of the two sparse CSR matrices.
-
standardVector
public static <T extends Semiring<T>> void standardVector(Shape shape, T[] src1, int[] rowPointers, int[] colIndices, int size, T[] src2, int[] indices, T[] dest, T zero) Computes the matrix-vector multiplication between a sparse CSR matrix and a sparse COO vector.- Parameters:
shape
- Shape of the CSR matrix.src1
- Non-zero data of the CSR matrixrowPointers
- Non-zero row pointers of the CSR matrix.colIndices
- Non-zero column indices of the CSR matrix.size
- Full size of the COO vector.src2
- Non-zero data of the COO vector.indices
- Non-zero indices of the COO Vector.dest
- Array to store the dense result of the matrix-vector multiplication in.zero
- Zero element of the semiring. Ifnull
then the zero value will attempt to be discerned fromsrc1
. However, ifzero == null && src1.length == 0
, then zeros in the resulting dense vector will instead benull
.- Throws:
IllegalArgumentException
- Ifshape.get(1) != size
ordest.length != size
.
-