Class AbstractCsrRingMatrix<T extends AbstractCsrRingMatrix<T,U,V,W>,U extends AbstractDenseRingMatrix<U,?,W>,V extends AbstractCooRingVector<V,?,?,U,W>,W extends Ring<W>>
- Type Parameters:
T- Type of this CSR field matrix.U- Type of dense field matrix equivalent toT.V- Type of vector equivalent toV.W- Type of field element of this matrix.
- All Implemented Interfaces:
Serializable,MatrixMixin<T,,U, V, W> RingTensorMixin<T,,U, W> TensorOverRing<T,,U, W[], W> SemiringTensorMixin<T,,U, W> TensorOverSemiring<T,U, W[], W>
- Direct Known Subclasses:
AbstractCsrFieldMatrix,CsrRingMatrix
A sparse matrix stored in compressed sparse row (CSR) format. The AbstractTensor.data of this CSR matrix are
elements of a Ring.
The non-zero data and non-zero indices of a CSR matrix are mutable but the AbstractTensor.shape
and total number of non-zero data is fixed.
Sparse matrices allow for the efficient storage of and ops on matrices that contain many zero values.
A sparse CSR matrix is stored as:
- The full
shapeof the matrix. - The non-zero
AbstractTensor.dataof the matrix. All other data in the matrix are assumed to be zero. Zero values can also explicitly be stored inAbstractTensor.data. - The
row pointersof the non-zero values in the CSR matrix. Has sizenumRows + 1rowPointers[i]indicates the starting index withindataandcolDataof all values in row - The
column indicesof the non-zero values in the sparse matrix.
i.
Note: many ops assume that the data of the CSR matrix are sorted lexicographically by the row and column indices. (i.e.) by row indices first then column indices. However, this is not explicitly verified. Any ops implemented in this class will preserve the lexicographical sorting.
If indices need to be sorted, call AbstractCsrSemiringMatrix.sortIndices().
- See Also:
-
Field Summary
Fields inherited from class org.flag4j.arrays.backend.semiring_arrays.AbstractCsrSemiringMatrix
colIndices, nnz, numCols, numRows, rowPointers, sparsity, zeroElementFields inherited from class org.flag4j.arrays.backend.AbstractTensor
data, rank, shape -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractCsrRingMatrix(Shape shape, W[] data, int[] rowPointers, int[] colIndices) Creates a sparse CSR matrix with the specifiedshape, non-zero data, row pointers, and non-zero column indices.protectedAbstractCsrRingMatrix(Shape shape, W[] data, int[] rowPointers, int[] colIndices, Object dummy) Creates a sparse CSR matrix with the specifiedshape, non-zero data, row pointers, and non-zero column indices. -
Method Summary
Modifier and TypeMethodDescriptionbooleanChecks if two sparse CSR ring matrices are element-wise equal within the following tolerance for two entriesxandy:booleanChecks if two matrices are element-wise equal within the tolerance specified byrelTolandabsTol.Warning: throwsUnsupportedOperationExceptionas division is not defined for general ring matrices.H()Computes the Hermitian transpose of this matrix.H(int... axes) Computes the conjugate transpose of this tensor.H(int axis1, int axis2) Computes the conjugate transpose of a tensor by conjugating and exchangingaxis1andaxis2.Computes the element-wise difference between two tensors of the same shape.Methods inherited from class org.flag4j.arrays.backend.semiring_arrays.AbstractCsrSemiringMatrix
add, augment, augment, coalesce, coalesce, copy, dataLength, density, elemMult, flatten, flatten, get, get, getSlice, getTriL, getTriU, getZeroElement, isHermitian, isI, isOrthogonal, isSymmetric, isTriL, isTriU, makeLikeCooMatrix, makeLikeDenseTensor, makeLikeTensor, makeLikeTensor, mult, multToSparse, multTranspose, numCols, numRows, removeCol, removeCols, removeRow, removeRows, reshape, set, set, setCol, setRow, setSliceCopy, setZeroElement, sortIndices, sparsity, stack, swapCols, swapRows, T, T, T, tensorTr, toCoo, toDense, toTensor, toTensor, toVector, trMethods inherited from class org.flag4j.arrays.backend.AbstractTensor
getData, getRank, getShape, makeLikeTensor, reshape, sameShape, totalEntriesMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.flag4j.arrays.backend.MatrixMixin
accept, add, augment, augment, copy, dataLength, elemMult, fib, get, getCol, getCol, getDiag, getDiag, getRow, getRow, getShape, getSlice, getTriL, getTriL, getTriU, getTriU, isDiag, isHermitian, isI, isOrthogonal, isSquare, isSymmetric, isTri, isTriL, isTriU, isVector, mult, mult, multTranspose, numCols, numRows, removeCol, removeCols, removeRow, removeRows, set, setCol, setRow, setSliceCopy, stack, stack, swapCols, swapRows, T, toVector, tr, trace, vectorTypeMethods inherited from interface org.flag4j.arrays.backend.ring_arrays.RingTensorMixin
add, addEq, argmax, argmaxAbs, argmin, argminAbs, conj, isOnes, isZeros, makeEmptyDataArray, max, maxAbs, min, minAbs, mult, multEq, norm, norm, prod, sub, subEq, sumMethods inherited from interface org.flag4j.arrays.backend.semiring_arrays.SemiringTensorMixin
argmax, argmin, max, minMethods inherited from interface org.flag4j.arrays.backend.ring_arrays.TensorOverRing
abs
-
Constructor Details
-
AbstractCsrRingMatrix
Creates a sparse CSR matrix with the specifiedshape, non-zero data, row pointers, and non-zero column indices.- Parameters:
shape- Shape of this tensor.data- The non-zero data of this CSR matrix.rowPointers- The row pointers for the non-zero values in the sparse CSR matrix.rowPointers[i]indicates the starting index withindataandcolDataof all values in rowi.colIndices- Column indices for each non-zero value in this sparse CSR matrix. Must satisfydata.length == colData.length.
-
AbstractCsrRingMatrix
protected AbstractCsrRingMatrix(Shape shape, W[] data, int[] rowPointers, int[] colIndices, Object dummy) Creates a sparse CSR matrix with the specifiedshape, non-zero data, row pointers, and non-zero column indices.- Parameters:
shape- Shape of this tensor.data- The non-zero data of this CSR matrix.rowPointers- The row pointers for the non-zero values in the sparse CSR matrix.rowPointers[i]indicates the starting index withindataandcolDataof all values in rowi.colIndices- Column indices for each non-zero value in this sparse CSR matrix. Must satisfydata.length == colData.length.dummy- Dummy object to distinguish this constructor from the safe variant. It is completely ignored in this constructor.
-
-
Method Details
-
sub
Computes the element-wise difference between two tensors of the same shape.- Specified by:
subin interfaceMatrixMixin<T extends AbstractCsrRingMatrix<T,U, V, W>, U extends AbstractDenseRingMatrix<U, ?, W>, V extends AbstractCooRingVector<V, ?, ?, U, W>, W extends Ring<W>> - Specified by:
subin interfaceTensorOverRing<T extends AbstractCsrRingMatrix<T,U, V, W>, U extends AbstractDenseRingMatrix<U, ?, W>, V extends AbstractCooRingVector<V, ?, ?, U, W>, W extends Ring<W>> - Overrides:
subin classAbstractCsrSemiringMatrix<T extends AbstractCsrRingMatrix<T,U, V, W>, U extends AbstractDenseRingMatrix<U, ?, W>, V extends AbstractCooRingVector<V, ?, ?, U, W>, W extends Ring<W>> - Parameters:
b- Second tensor in the element-wise difference.- Returns:
- The difference of this tensor with
b. - Throws:
TensorShapeException- If this tensor andbdo not have the same shape.
-
div
Warning: throws
UnsupportedOperationExceptionas division is not defined for general ring matrices.Warning: throws
UnsupportedOperationExceptionas division is not defined for general semiring matrices.Computes the element-wise quotient of two matrices.
- Specified by:
divin interfaceMatrixMixin<T extends AbstractCsrRingMatrix<T,U, V, W>, U extends AbstractDenseRingMatrix<U, ?, W>, V extends AbstractCooRingVector<V, ?, ?, U, W>, W extends Ring<W>> - Overrides:
divin classAbstractCsrSemiringMatrix<T extends AbstractCsrRingMatrix<T,U, V, W>, U extends AbstractDenseRingMatrix<U, ?, W>, V extends AbstractCooRingVector<V, ?, ?, U, W>, W extends Ring<W>> - Parameters:
b- Second matrix in the element-wise quotient.- Returns:
- The element-wise quotient of this matrix and
b.
-
H
Computes the Hermitian transpose of this matrix.- Specified by:
Hin interfaceMatrixMixin<T extends AbstractCsrRingMatrix<T,U, V, W>, U extends AbstractDenseRingMatrix<U, ?, W>, V extends AbstractCooRingVector<V, ?, ?, U, W>, W extends Ring<W>> - Specified by:
Hin interfaceTensorOverRing<T extends AbstractCsrRingMatrix<T,U, V, W>, U extends AbstractDenseRingMatrix<U, ?, W>, V extends AbstractCooRingVector<V, ?, ?, U, W>, W extends Ring<W>> - Overrides:
Hin classAbstractCsrSemiringMatrix<T extends AbstractCsrRingMatrix<T,U, V, W>, U extends AbstractDenseRingMatrix<U, ?, W>, V extends AbstractCooRingVector<V, ?, ?, U, W>, W extends Ring<W>> - Returns:
- The Hermitian transpose of this matrix.
- See Also:
-
H
Computes the conjugate transpose of a tensor by conjugating and exchangingaxis1andaxis2.- Specified by:
Hin interfaceTensorOverRing<T extends AbstractCsrRingMatrix<T,U, V, W>, U extends AbstractDenseRingMatrix<U, ?, W>, V extends AbstractCooRingVector<V, ?, ?, U, W>, W extends Ring<W>> - Parameters:
axis1- First axis to exchange and conjugate.axis2- Second axis to exchange and conjugate.- Returns:
- The conjugate transpose of this tensor according to the specified axes.
- Throws:
IndexOutOfBoundsException- If eitheraxis1oraxis2are out of bounds for the rank of this tensor.- See Also:
-
H
Computes the conjugate transpose of this tensor. That is, conjugates and permutes the axes of this tensor so that it matches the permutation specified byaxes.- Specified by:
Hin interfaceTensorOverRing<T extends AbstractCsrRingMatrix<T,U, V, W>, U extends AbstractDenseRingMatrix<U, ?, W>, V extends AbstractCooRingVector<V, ?, ?, U, W>, W extends Ring<W>> - Parameters:
axes- Permutation of tensor axis. If the tensor has rankN, then this must be an array of lengthNwhich is a permutation of{0, 1, 2, ..., N-1}.- Returns:
- The conjugate transpose of this tensor with its axes permuted by the
axesarray. - Throws:
IndexOutOfBoundsException- If any element ofaxesis out of bounds for the rank of this tensor.IllegalArgumentException- Ifaxesis not a permutation of{1, 2, 3, ... N-1}.- See Also:
-
allClose
Checks if two sparse CSR ring matrices are element-wise equal within the following tolerance for two entriesxandy:
To specify the relative and absolute tolerances use|x-y| <= (1e-08 + 1e-05*|y|)allClose(AbstractCsrRingMatrix, double, double)- Returns:
trueif this matrix andbelement-wise equal within the tolerance|x-y| <= (1e-08 + 1e-05*|y|).- See Also:
-
allClose
Checks if two matrices are element-wise equal within the tolerance specified byrelTolandabsTol. Two elementsxandyare considered "close" if they satisfy the following:|x-y| <= (absTol + relTol*|y|)- Parameters:
b- Matrix to compare to this matrix.absTol- Absolute tolerance.relTol- Relative tolerance.- Returns:
trueif thesrc1matrix is the same shape as thesrc2matrix and all data are 'close', i.e. elementsaandbat the same positions in the two matrices respectively satisfy|a-b| <= (absTol + relTol*|b|). Otherwise, returnsfalse.- See Also:
-