Class AbstractCooSemiringMatrix<T extends AbstractCooSemiringMatrix<T,U,V,W>,U extends AbstractDenseSemiringMatrix<U,?,W>,V extends AbstractCooSemiringVector<V,?,T,U,W>,W extends Semiring<W>>

java.lang.Object
org.flag4j.arrays.backend.AbstractTensor<T,W[],W>
org.flag4j.arrays.backend.semiring_arrays.AbstractCooSemiringMatrix<T,U,V,W>
Type Parameters:
T - Type of this sparse COO matrix.
U - Type of dense matrix which is similar to T.
V - Type of sparse COO vector which is similar to T.
W - Type of the semiring element in this matrix.
All Implemented Interfaces:
Serializable, MatrixMixin<T,U,V,W>, SemiringTensorMixin<T,U,W>, TensorOverSemiring<T,U,W[],W>
Direct Known Subclasses:
AbstractCooRingMatrix, CooSemiringMatrix

public abstract class AbstractCooSemiringMatrix<T extends AbstractCooSemiringMatrix<T,U,V,W>,U extends AbstractDenseSemiringMatrix<U,?,W>,V extends AbstractCooSemiringVector<V,?,T,U,W>,W extends Semiring<W>> extends AbstractTensor<T,W[],W> implements SemiringTensorMixin<T,U,W>, MatrixMixin<T,U,V,W>

A sparse matrix stored in coordinate list (COO) format. The AbstractTensor.data of this COO vector are elements of a Semiring.

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:

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 sortIndices().

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final int[]
    column indices for non-zero value of this sparse COO matrix.
    final int
    Number of non-zero data in this COO matrix.
    final int
    The number of columns in this matrix.
    final int
    The number of rows in this matrix.
    final int[]
    Row indices for non-zero value of this sparse COO matrix.
    final double
    The sparsity of this matrix.
    protected W
    The zero element for the semiring that this tensor's elements belong to.

    Fields inherited from class org.flag4j.arrays.backend.AbstractTensor

    data, rank, shape
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    AbstractCooSemiringMatrix(Shape shape, W[] data, int[] rowIndices, int[] colIndices)
    Creates a sparse coo matrix with the specified non-zero data, non-zero indices, and shape.
    protected
    AbstractCooSemiringMatrix(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 Type
    Method
    Description
    add(T b)
    Computes the element-wise sum between two tensors of the same shape.
    int[]
    Finds the indices of the maximum value in this tensor.
    int[]
    Finds the indices of the minimum value in this tensor.
    Stacks matrices along rows.
    Augments a vector to this matrix.
    Coalesces this sparse COO matrix.
    coalesce(BinaryOperator<W> aggregator)
    Coalesces this sparse COO matrix.
    Creates a deep copy of this tensor.
    int
    Gets the length of the data array which backs this matrix.
    double
    Gets the density of this matrix as a decimal percentage.
    Drops any explicit zeros in this sparse COO matrix.
    Computes the element-wise multiplication of two tensors of the same shape.
    Flattens this matrix to a single row.
    flatten(int axis)
    Flattens a tensor along the specified axis.
    get(int... index)
    Gets the element of this tensor at the specified index.
    get(int row, int col)
    Gets the element of this matrix at this specified row and col.
    getCol(int colIdx, int start, int stop)
    Gets a range of a column of this matrix.
    getDiag(int diagOffset)
    Gets the elements of this matrix along the specified diagonal.
    getRow(int rowIdx, int start, int stop)
    Gets a range of a row of this matrix.
    getSlice(int rowStart, int rowEnd, int colStart, int colEnd)
    Gets a specified slice of this matrix.
    getTriL(int diagOffset)
    Extracts the lower-triangular portion of this matrix with a specified diagonal offset.
    getTriU(int diagOffset)
    Extracts the upper-triangular portion of this matrix with a specified diagonal offset.
    Gets the zero element for the semiring of this tensor.
    H()
    Computes the Hermitian transpose of this matrix.
    boolean
    Checks if a matrix is Hermitian.
    boolean
    isI()
    Checks if this matrix is the identity matrix.
    boolean
    Checks if this matrix is orthogonal.
    boolean
    Checks if a matrix is symmetric.
    boolean
    Checks if this matrix is lower triangular.
    boolean
    Checks if this matrix is upper triangular.
    makeLikeCsrMatrix(Shape shape, W[] entries, int[] rowPointers, int[] colIndices)
    Constructs a sparse CSR matrix of a similar type to this sparse COO matrix.
    abstract U
    makeLikeDenseTensor(Shape shape, W[] entries)
    Constructs a dense tensor with the specified shape and data which is a similar type to this sparse tensor.
    abstract T
    makeLikeTensor(Shape shape, List<W> entries, List<Integer> rowIndices, List<Integer> colIndices)
    Constructs a COO matrix with the specified shape, non-zero data, and non-zero indices.
    abstract T
    makeLikeTensor(Shape shape, W[] entries, int[] rowIndices, int[] colIndices)
    Constructs a sparse COO tensor of the same type as this tensor with the specified non-zero data and indices.
    abstract V
    makeLikeVector(Shape shape, W[] entries, int[] indices)
    Constructs a sparse COO vector of a similar type to this COO matrix.
    max()
    Finds the maximum value in this tensor.
    min()
    Finds the minimum value in this tensor.
    mult(T b)
    Computes the matrix multiplication between two matrices.
    Multiplies this matrix with the transpose of the b tensor as if by this.mult(b.T()).
    int
    Gets the number of columns in this matrix.
    int
    Gets the number of rows in this matrix.
    removeCol(int colIndex)
    Removes a specified column from this matrix.
    removeCols(int... colIdxs)
    Removes a specified set of columns from this matrix.
    removeRow(int rowIndex)
    Removes a specified row from this matrix.
    removeRows(int... rowIdxs)
    Removes a specified set of rows from this matrix.
    reshape(Shape newShape)
    Copies and reshapes this tensor.
    set(W value, int... indices)
    Sets the element of this tensor at the specified indices.
    set(W value, int row, int col)
    Sets an index of this matrix to the specified value.
    setCol(V col, int colIndex)
    Sets a column of this matrix at the given index to the specified vector.
    setRow(V row, int rowIdx)
    Sets a specified row of this matrix to a vector.
    setSliceCopy(T values, int rowStart, int colStart)
    Creates a copy of this matrix and sets a slice of the copy to the specified values.
    void
    setZeroElement(W zeroElement)
    Sets the zero element for the semiring of this tensor.
    Sorts the indices of this tensor in lexicographical order while maintaining the associated value for each index.
    double
    Gets the sparsity of this matrix as a decimal percentage.
    stack(T b)
    Stacks matrices along columns.
    swapCols(int colIndex1, int colIndex2)
    Swaps specified columns in the matrix.
    swapRows(int rowIndex1, int rowIndex2)
    Swaps specified rows in the matrix.
    T()
    Computes the transpose of a tensor by exchanging the first and last axes of this tensor.
    T(int... axes)
    Computes the transpose of this tensor.
    T(int axis1, int axis2)
    Computes the transpose of a tensor by exchanging axis1 and axis2.
    tensorTr(int axis1, int axis2)
    Computes the generalized trace of this tensor along the specified axes.
    Converts this sparse COO matrix to an equivalent sparse CSR matrix.
    Converts this sparse COO matrix to an equivalent dense matrix.
    Converts this matrix to an equivalent rank 2 tensor.
    toTensor(Shape newShape)
    Converts this matrix to an equivalent tensor with the specified shape.
    Converts this sparse CSR matrix to an equivalent vector.
    tr()
    Computes the trace of this matrix.

    Methods inherited from class org.flag4j.arrays.backend.AbstractTensor

    getData, getRank, getShape, makeLikeTensor, reshape, sameShape, totalEntries

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.flag4j.arrays.backend.MatrixMixin

    accept, div, fib, getCol, getDiag, getRow, getShape, getTriL, getTriU, isDiag, isSquare, isTri, isVector, mult, stack, sub, trace, vectorType

    Methods inherited from interface org.flag4j.arrays.backend.semiring_arrays.SemiringTensorMixin

    add, addEq, isOnes, isZeros, makeEmptyDataArray, mult, multEq, prod, sum

    Methods inherited from interface org.flag4j.arrays.backend.semiring_arrays.TensorOverSemiring

    getData, getRank, getShape, makeLikeTensor, tensorDot, tensorDot, tensorDot, tensorDot, tensorTr