Class AbstractCooFieldMatrix<T extends AbstractCooFieldMatrix<T,U,V,W>,U extends AbstractDenseFieldMatrix<U,?,W>,V extends AbstractCooFieldVector<V,?,T,U,W>,W extends Field<W>>
- Type Parameters:
T- Type of this sparse COO matrix.U- Type of dense matrix which is similar toT.V- Type of sparse COO vector which is similar toT.W- Type of the field element in this matrix.
- All Implemented Interfaces:
Serializable,FieldTensorMixin<T,,U, W> TensorOverField<T,,U, W[], W> 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:
CooCMatrix,CooFieldMatrix
A sparse matrix stored in coordinate list (COO) format. The AbstractTensor.data of this COO vector are
elements of a Field.
The non-zero data and non-zero indices of a COO 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.
COO matrices are optimized for hyper-sparse matrices (i.e. matrices which contain almost all zeros relative to the size of the matrix).
COO Representation:
A sparse COO 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 indicesof the non-zero values in the sparse matrix. - The
column indicesof the non-zero values in the sparse matrix.
Note: many ops assume that the data of the COO 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 but any ops implemented in this class will preserve the lexicographical sorting.
If indices need to be sorted, call AbstractCooSemiringMatrix.sortIndices().
- See Also:
-
Field Summary
Fields inherited from class org.flag4j.arrays.backend.semiring_arrays.AbstractCooSemiringMatrix
colIndices, nnz, numCols, numRows, rowIndices, sparsity, zeroElementFields inherited from class org.flag4j.arrays.backend.AbstractTensor
data, rank, shape -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractCooFieldMatrix(Shape shape, W[] data, int[] rowIndices, int[] colIndices) Creates a sparse coo matrix with the specified non-zero data, non-zero indices, and shape.protectedAbstractCooFieldMatrix(Shape shape, W[] data, int[] rowIndices, int[] colIndices, Object dummy) Creates a sparse coo matrix with the specified non-zero data, non-zero indices, and shape. -
Method Summary
Modifier and TypeMethodDescriptionabs()Computes the element-wise absolute value of this tensor.Computes the element-wise quotient between two tensors.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.booleanisFinite()Checks if this tensor only contains finite values.booleanChecks if this tensor contains at least one infinite value.booleanisNaN()Checks if this tensor contains at least one NaN value.abstract AbstractCsrFieldMatrix<?, U, V, W> makeLikeCsrMatrix(Shape shape, W[] entries, int[] rowPointers, int[] colIndices) Constructs a sparse CSR matrix of a similar type to this sparse COO matrix.multTranspose(T b) Multiplies this matrix with the transpose of thebtensor as if bythis.mult(b.H()).sqrt()Computes the element-wise square root of this tensor.toCsr()Converts this sparse COO matrix to an equivalent sparse CSR matrix.Methods inherited from class org.flag4j.arrays.backend.ring_arrays.AbstractCooRingMatrix
isCloseToI, sub, toTensor, toTensorMethods inherited from class org.flag4j.arrays.backend.semiring_arrays.AbstractCooSemiringMatrix
add, argmax, argmin, augment, augment, coalesce, coalesce, copy, dataLength, density, dropZeros, elemMult, flatten, flatten, get, get, getCol, getDiag, getRow, getSlice, getTriL, getTriU, getZeroElement, isHermitian, isI, isOrthogonal, isSymmetric, isTriL, isTriU, makeLikeDenseTensor, makeLikeTensor, makeLikeTensor, makeLikeVector, max, min, mult, numCols, numRows, removeCol, removeCols, removeRow, removeRows, reshape, set, set, setCol, setRow, setSliceCopy, setZeroElement, sortIndices, sparsity, stack, swapCols, swapRows, T, T, T, tensorTr, toDense, 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.field_arrays.FieldTensorMixin
add, add, addEq, addEq, argmax, argmaxAbs, argmin, argminAbs, conj, div, div, divEq, divEq, isOnes, isZeros, makeEmptyDataArray, max, maxAbs, min, minAbs, mult, mult, multEq, multEq, norm, norm, prod, recip, sub, sub, subEq, subEq, sumMethods 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, numCols, numRows, removeCol, removeCols, removeRow, removeRows, set, setCol, setRow, setSliceCopy, stack, stack, sub, swapCols, swapRows, T, toVector, tr, trace, vectorTypeMethods inherited from interface org.flag4j.arrays.backend.ring_arrays.TensorOverRing
sub
-
Constructor Details
-
AbstractCooFieldMatrix
Creates a sparse coo matrix with the specified non-zero data, non-zero indices, and shape.- Parameters:
shape- Shape of this tensor.data- Non-zero data of this sparse matrix.rowIndices- Non-zero row indices of this sparse matrix.colIndices- Non-zero column indies of this sparse matrix.
-
AbstractCooFieldMatrix
protected AbstractCooFieldMatrix(Shape shape, W[] data, int[] rowIndices, int[] colIndices, Object dummy) Creates a sparse coo matrix with the specified non-zero data, non-zero indices, and shape.- Parameters:
shape- Shape of this tensor.data- Non-zero data of this sparse matrix.rowIndices- Non-zero row indices of this sparse matrix.colIndices- Non-zero column indies of this sparse matrix.dummy- Dummy object to distinguish this constructor from the safe variant.
-
-
Method Details
-
makeLikeCsrMatrix
public abstract AbstractCsrFieldMatrix<?,U, makeLikeCsrMatrixV, W> (Shape shape, W[] entries, int[] rowPointers, int[] colIndices) Constructs a sparse CSR matrix of a similar type to this sparse COO matrix.- Specified by:
makeLikeCsrMatrixin classAbstractCooRingMatrix<T extends AbstractCooFieldMatrix<T,U, V, W>, U extends AbstractDenseFieldMatrix<U, ?, W>, V extends AbstractCooFieldVector<V, ?, T, U, W>, W extends Field<W>> - Parameters:
shape- Shape of the CSR matrix to construct.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.- Returns:
- A CSR matrix of a similar type to this sparse COO matrix.
-
multTranspose
Multiplies this matrix with the transpose of thebtensor as if bythis.mult(b.H()). For large matrices, this method may be significantly faster than directly computing the Hermitian transpose followed by the multiplication asthis.mult(b.H()).- Specified by:
multTransposein interfaceMatrixMixin<T extends AbstractCooFieldMatrix<T,U, V, W>, U extends AbstractDenseFieldMatrix<U, ?, W>, V extends AbstractCooFieldVector<V, ?, T, U, W>, W extends Field<W>> - Overrides:
multTransposein classAbstractCooSemiringMatrix<T extends AbstractCooFieldMatrix<T,U, V, W>, U extends AbstractDenseFieldMatrix<U, ?, W>, V extends AbstractCooFieldVector<V, ?, T, U, W>, W extends Field<W>> - Parameters:
b- The second matrix in the multiplication and the matrix to transpose.- Returns:
- The result of multiplying this matrix with the Hermitian transpose of
b.
-
abs
Computes the element-wise absolute value of this tensor. -
H
Computes the Hermitian transpose of this matrix.- Specified by:
Hin interfaceMatrixMixin<T extends AbstractCooFieldMatrix<T,U, V, W>, U extends AbstractDenseFieldMatrix<U, ?, W>, V extends AbstractCooFieldVector<V, ?, T, U, W>, W extends Field<W>> - Specified by:
Hin interfaceTensorOverRing<T extends AbstractCooFieldMatrix<T,U, V, W>, U extends AbstractDenseFieldMatrix<U, ?, W>, V extends AbstractCooFieldVector<V, ?, T, U, W>, W extends Field<W>> - Overrides:
Hin classAbstractCooRingMatrix<T extends AbstractCooFieldMatrix<T,U, V, W>, U extends AbstractDenseFieldMatrix<U, ?, W>, V extends AbstractCooFieldVector<V, ?, T, U, W>, W extends Field<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 AbstractCooFieldMatrix<T,U, V, W>, U extends AbstractDenseFieldMatrix<U, ?, W>, V extends AbstractCooFieldVector<V, ?, T, U, W>, W extends Field<W>> - Overrides:
Hin classAbstractCooRingMatrix<T extends AbstractCooFieldMatrix<T,U, V, W>, U extends AbstractDenseFieldMatrix<U, ?, W>, V extends AbstractCooFieldVector<V, ?, T, U, W>, W extends Field<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 AbstractCooFieldMatrix<T,U, V, W>, U extends AbstractDenseFieldMatrix<U, ?, W>, V extends AbstractCooFieldVector<V, ?, T, U, W>, W extends Field<W>> - Overrides:
Hin classAbstractCooRingMatrix<T extends AbstractCooFieldMatrix<T,U, V, W>, U extends AbstractDenseFieldMatrix<U, ?, W>, V extends AbstractCooFieldVector<V, ?, T, U, W>, W extends Field<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:
-
toCsr
Converts this sparse COO matrix to an equivalent sparse CSR matrix. -
div
Computes the element-wise quotient between two tensors.
WARNING: This method is not supported for sparse tensors. If called on a sparse tensor, an
UnsupportedOperationExceptionwill be thrown. Element-wise division is undefined for sparse matrices as it would almost certainly result in a division by zero.- Specified by:
divin interfaceMatrixMixin<T extends AbstractCooFieldMatrix<T,U, V, W>, U extends AbstractDenseFieldMatrix<U, ?, W>, V extends AbstractCooFieldVector<V, ?, T, U, W>, W extends Field<W>> - Specified by:
divin interfaceTensorOverField<T extends AbstractCooFieldMatrix<T,U, V, W>, U extends AbstractDenseFieldMatrix<U, ?, W>, V extends AbstractCooFieldVector<V, ?, T, U, W>, W extends Field<W>> - Parameters:
b- Second tensor in the element-wise quotient.- Returns:
- The element-wise quotient of this tensor with
b. - Throws:
UnsupportedOperationException- if this method is ever invoked on a sparse tensor.
-
sqrt
Computes the element-wise square root of this tensor. -
isFinite
public boolean isFinite()Checks if this tensor only contains finite values. -
isInfinite
public boolean isInfinite()Checks if this tensor contains at least one infinite value.- Specified by:
isInfinitein interfaceTensorOverField<T extends AbstractCooFieldMatrix<T,U, V, W>, U extends AbstractDenseFieldMatrix<U, ?, W>, V extends AbstractCooFieldVector<V, ?, T, U, W>, W extends Field<W>> - Returns:
trueif this tensor contains at least one infinite value;falseotherwise.- See Also:
-
isNaN
public boolean isNaN()Checks if this tensor contains at least one NaN value.
-