Class CsrConversions
java.lang.Object
org.flag4j.linalg.ops.sparse.csr.CsrConversions
Utility class for converting CSR matrices to flat matrices, dense matrices, etc.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Shapeflatten(Shape shape, T[] entries, int[] rowPointers, int[] colIndices, int axis, int[] destRowPointers, int[] destColIndices) Computes the new row pointers and column indices for a sparse CSR matrix flattened along someaxis.static <T> voidtoCoo(Shape shape, T[] entries, int[] rowPointers, int[] colIndices, T[] destEntries, int[] destRowIndices, int[] destColIndices) Converts a sparse CSR matrix to an equivalent sparse COO matrix.static <T> voidConverts a sparse CSR matrix to a dense matrix.
-
Method Details
-
flatten
public static <T> Shape flatten(Shape shape, T[] entries, int[] rowPointers, int[] colIndices, int axis, int[] destRowPointers, int[] destColIndices) Computes the new row pointers and column indices for a sparse CSR matrix flattened along someaxis.- Parameters:
shape- Shape of the CSR matrix to be flattened.entries- Non-zero data of the CSR matrix.rowPointers- Non-zero row pointers of the CSR matrix.colIndices- Non-zero column indices of the CSR matrix.axis- Axis along which to flatten matrix. Must be 0 or 1.- If
axis==0then the matrix will be flattened to a single row. - If
axis==1then the matrix will be flattened to a single column.
- If
destRowPointers- Array to store the non-zero row pointers resulting from flattening the CSR matrix along the specified axis.destColIndices- Array to store the non-zero column indices resulting from flattening the CSR matrix along the specified axis.- Returns:
- The shape of the flattened matrix.
- Throws:
LinearAlgebraException- Ifaxis != 0 || axis != 1.
-
toDense
public static <T> void toDense(Shape shape, T[] entries, int[] rowPointers, int[] colIndices, T[] dest, T zero) Converts a sparse CSR matrix to a dense matrix.- Parameters:
shape- Shape of the CSR matrix. Must be rank 2.entries- Non-zero data of the CSR matrix.rowPointers- Non-zero row pointers of the CSR matrix.colIndices- Non-zero column indices of the CSR matrix.dest- Array to store the dense result in.zero- Zero element to fill zero value of the sparse matrix with.- Throws:
IllegalArgumentException- Ifdest.length < shape.totalEntriesIntValueExact()
-
toCoo
public static <T> void toCoo(Shape shape, T[] entries, int[] rowPointers, int[] colIndices, T[] destEntries, int[] destRowIndices, int[] destColIndices) Converts a sparse CSR matrix to an equivalent sparse COO matrix.- Parameters:
shape- Shape of the CSR matrix.entries- Non-zero data of the CSR matrix.rowPointers- Non-zero row pointers of the CSR matrix.colIndices- Non-zero column indices of the CSR matrix.destEntries- Array to store the non-zero data of the COO matrix.destColIndices- Array to store the non-zero column indices of the COO matrix.rowIndices- Array to store the non-zero row indices of the COO matrix.
-