Class AbstractCsrSemiringMatrix<T extends AbstractCsrSemiringMatrix<T,U,V,W>,U extends AbstractDenseSemiringMatrix<U,?,W>,V extends AbstractCooSemiringVector<V,?,?,U,W>,W extends Semiring<W>>            
- Type Parameters:
- T- Type of this CSR field matrix.
- U- Type of dense field matrix equivalent to- T.
- V- Type of vector equivalent to- V.
- Y- Type of field element of this matrix.
- All Implemented Interfaces:
- Serializable,- MatrixMixin<T,,- U, - V, - W> - SemiringTensorMixin<T,,- U, - W> - TensorOverSemiring<T,- U, - W[], - W> 
- Direct Known Subclasses:
- AbstractCsrRingMatrix,- CsrSemiringMatrix
A sparse matrix stored in compressed sparse row (CSR) format. The AbstractTensor.data of this CSR matrix are
 elements of a Semiring.
 
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 + 1
- The column indicesof the non-zero values in the sparse matrix.
rowPointers[i] indicates the starting index within data and colData of all values in row
     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 sortIndices().
- See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionfinal int[]Column indices for non-zero values of this sparse CSR matrix.final intNumber of non-zero data in this CSR matrix.final intThe number of columns in this matrix.final intThe number of rows in this matrix.final int[]Pointers indicating starting index of each row within thecolIndicesandAbstractTensor.dataarrays.protected final doubleThe sparsity of this matrix.protected WThe zero element for the semiring that this tensor's elements belong to.Fields inherited from class org.flag4j.arrays.backend.AbstractTensordata, rank, shape
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedAbstractCsrSemiringMatrix(Shape shape, W[] entries, int[] rowPointers, int[] colIndices) Creates a sparse CSR matrix with the specifiedshape, non-zero data, row pointers, and non-zero column indices.protectedAbstractCsrSemiringMatrix(Shape shape, W[] entries, 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 SummaryModifier and TypeMethodDescriptionComputes the element-wise sum between two tensors of the same shape.Stacks matrices along rows.Augments a vector to this matrix.coalesce()Coalesces this sparse CSR matrix.coalesce(BinaryOperator<W> aggregator) Coalesces this sparse COO matrix.copy()Creates a deep copy of this tensor.intGets the length of the data array which backs this matrix.doubledensity()Gets the density of this matrix as a decimal percentage.Warning: throwsUnsupportedOperationExceptionas division is not defined for general semiring matrices.Computes the element-wise multiplication of two tensors of the same shape.flatten()Flattens tensor to single dimension while preserving order of data.flatten(int axis) Flattens a tensor along the specified axis.get(int... indices) Gets the element of this tensor at the specified indices.get(int row, int col) Gets the element of this matrix at this specifiedrowandcol.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.booleanChecks if a matrix is Hermitian.booleanisI()Checks if this matrix is the identity matrix.booleanChecks if this matrix is orthogonal.booleanChecks if a matrix is symmetric.booleanisTriL()Checks if this matrix is lower triangular.booleanisTriU()Checks if this matrix is upper triangular.abstract AbstractCooSemiringMatrix<?, U, V, W> makeLikeCooMatrix(Shape shape, W[] entries, int[] rowIndices, int[] colIndices) Constructs a sparse COO matrix of a similar type to this sparse CSR matrix.abstract UmakeLikeDenseTensor(Shape shape, W[] entries) Constructs a dense matrix which is of a similar type to this sparse CSR matrix.abstract TConstructs a CSR matrix with the specified shape, non-zero data, and non-zero indices.abstract TmakeLikeTensor(Shape shape, W[] entries, int[] rowPointers, int[] colIndices) Constructs a sparse CSR tensor of the same type as this tensor with the specified non-zero data and indices.Computes the matrix multiplication between two matrices.multToSparse(T b) Computes the matrix multiplication between two sparse CSR matrices and stores the result in a sparse matrix.multTranspose(T b) Multiplies this matrix with the transpose of thebtensor as if bythis.mult(b.T()).intnumCols()Gets the number of columns in this matrix.intnumRows()Gets the number of rows in this matrix.removeCol(int colIndex) Removes a specified column from this matrix.removeCols(int... colIndices) Removes a specified set of columns from this matrix.removeRow(int rowIndex) Removes a specified row from this matrix.removeRows(int... rowIndices) Removes a specified set of rows from this matrix.Copies and reshapes this tensor.Sets the element of this tensor at the specified indices.Sets an index of this matrix to the specified value.Sets a specified column of this matrix to a vector.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.voidsetZeroElement(W zeroElement) Sets the zero element for the semiring of this tensor.voidSorts the indices of this tensor in lexicographical order while maintaining the associated value for each index.doublesparsity()Gets the sparsity of this matrix as a decimal percentage.Stacks matrices along columns.Warning: throwsUnsupportedOperationExceptionas subtraction is not defined for general semiring matrices.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 exchangingaxis1andaxis2.tensorTr(int axis1, int axis2) Computes the generalized trace of this tensor along the specified axes.abstract AbstractCooSemiringMatrixtoCoo()Converts this sparse CSR matrix to an equivalent sparse COO matrix.toDense()Converts this sparse CSR matrix to an equivalent dense matrix.abstract AbstractCooSemiringTensor<?, ?, W> toTensor()Converts this CSR matrix to an equivalent sparse COO tensor.Converts this CSR matrix to an equivalent COO tensor with the specified shape.toVector()Converts this sparse CSR matrix to an equivalent vector.tr()Computes the trace of this matrix.Methods inherited from class org.flag4j.arrays.backend.AbstractTensorgetData, getRank, getShape, makeLikeTensor, reshape, sameShape, totalEntriesMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.flag4j.arrays.backend.MatrixMixinaccept, fib, getCol, getCol, getDiag, getDiag, getRow, getRow, getShape, getTriL, getTriU, isDiag, isSquare, isTri, isVector, mult, stack, trace, vectorTypeMethods inherited from interface org.flag4j.arrays.backend.semiring_arrays.SemiringTensorMixinadd, addEq, argmax, argmin, isOnes, isZeros, makeEmptyDataArray, max, min, mult, multEq, prod, sumMethods inherited from interface org.flag4j.arrays.backend.semiring_arrays.TensorOverSemiringgetData, getRank, getShape, makeLikeTensor, tensorDot, tensorDot, tensorDot, tensorDot, tensorTr
- 
Field Details- 
zeroElement
- 
rowPointerspublic final int[] rowPointersPointers indicating starting index of each row within the colIndicesandAbstractTensor.dataarrays. Has lengthnumRows + 1.The range [ data[rowPointers[i]], data[rowPointers[i+1]]) contains allnon-zero datawithin rowi.Similarly, [ colData[rowPointers[i]], colData[rowPointers[i+1]]) contains allcolumn indicesfor the data in rowi.
- 
colIndicespublic final int[] colIndicesColumn indices for non-zero values of this sparse CSR matrix.
- 
nnzpublic final int nnzNumber of non-zero data in this CSR matrix.
- 
numRowspublic final int numRowsThe number of rows in this matrix.
- 
numColspublic final int numColsThe number of columns in this matrix.
- 
sparsityprotected final double sparsityThe sparsity of this matrix.
 
- 
- 
Constructor Details- 
AbstractCsrSemiringMatrixCreates a sparse CSR matrix with the specifiedshape, non-zero data, row pointers, and non-zero column indices.- Parameters:
- shape- Shape of this tensor.
- entries- 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 within- dataand- colDataof all values in row- i.
- colIndices- Column indices for each non-zero value in this sparse CSR matrix. Must satisfy- data.length == colData.length.
 
- 
AbstractCsrSemiringMatrixprotected AbstractCsrSemiringMatrix(Shape shape, W[] entries, 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.
- entries- 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 within- dataand- colDataof all values in row- i.
- colIndices- Column indices for each non-zero value in this sparse CSR matrix. Must satisfy- data.length == colData.length.
- dummy- Dummy object to distinguish this constructor from the safe variant. It is completely ignored in this constructor.
 
 
- 
- 
Method Details- 
makeLikeTensorConstructs a sparse CSR tensor of the same type as this tensor with the specified non-zero data and indices.- Parameters:
- shape- Shape of the matrix.
- entries- Non-zero data of the CSR matrix.
- rowPointers- Row pointers for the non-zero values in the CSR matrix.
- colIndices- Non-zero column indices of the CSR matrix.
- Returns:
- A sparse CSR tensor of the same type as this tensor with the specified non-zero data and indices.
 
- 
makeLikeTensorpublic abstract T makeLikeTensor(Shape shape, List<W> entries, List<Integer> rowPointers, List<Integer> colIndices) Constructs a CSR matrix with the specified shape, non-zero data, and non-zero indices.- Parameters:
- shape- Shape of the matrix.
- entries- Non-zero values of the CSR matrix.
- rowPointers- Row pointers for the non-zero values in the CSR matrix.
- colIndices- Non-zero column indices of the CSR matrix.
- Returns:
- A CSR matrix with the specified shape, non-zero data, and non-zero indices.
 
- 
makeLikeDenseTensorConstructs a dense matrix which is of a similar type to this sparse CSR matrix.- Parameters:
- shape- Shape of the dense matrix.
- entries- Entries of the dense matrix.
- Returns:
- A dense matrix which is of a similar type to this sparse CSR matrix with the specified shapeanddata.
 
- 
makeLikeCooMatrixpublic abstract AbstractCooSemiringMatrix<?,U, makeLikeCooMatrixV, W> (Shape shape, W[] entries, int[] rowIndices, int[] colIndices) Constructs a sparse COO matrix of a similar type to this sparse CSR matrix. Note: this method constructs a new COO matrix with the specified data and indices. It does not convert this matrix to a CSR matrix. To convert this matrix to a sparse COO matrix use toCoo().- Parameters:
- shape- Shape of the COO matrix.
- entries- Non-zero data of the COO matrix.
- rowIndices- Non-zero row indices of the sparse COO matrix.
- colIndices- Non-zero column indices of the Sparse COO matrix.
- Returns:
- A sparse COO matrix of a similar type to this sparse CSR matrix.
 
- 
sparsitypublic double sparsity()Gets the sparsity of this matrix as a decimal percentage. That is, the percentage of data in this matrix that are zero.- Returns:
- The sparsity of this matrix as a decimal percentage.
- See Also:
 
- 
densitypublic double density()Gets the density of this matrix as a decimal percentage. That is, the percentage of data in this matrix that are non-zero.- Returns:
- The density of this matrix as a decimal percentage.
- See Also:
 
- 
dataLengthpublic int dataLength()Gets the length of the data array which backs this matrix.- Specified by:
- dataLengthin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Specified by:
- dataLengthin class- AbstractTensor<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - W extends Semiring<W>[], - W extends Semiring<W>> 
- Returns:
- The length of the data array which backs this matrix.
 
- 
getZeroElementGets the zero element for the semiring of this tensor.- Returns:
- The zero element for the semiring of this tensor. If it could not be determined during construction of this object
 and has not been set explicitly by setZeroElement(Semiring)thennullwill be returned.
- See Also:
 
- 
setZeroElementSets the zero element for the semiring of this tensor.- Parameters:
- zeroElement- The zero element of this tensor.
- Throws:
- IllegalArgumentException- If- zeroElementis not an additive identity for the semiring.
- See Also:
 
- 
getGets the element of this tensor at the specified indices.- Specified by:
- getin class- AbstractTensor<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - W extends Semiring<W>[], - W extends Semiring<W>> 
- Parameters:
- indices- Indices of the element to get.
- Returns:
- The element of this tensor at the specified indices.
- Throws:
- ArrayIndexOutOfBoundsException- If any indices are not within this tensor.
 
- 
setSets the element of this tensor at the specified indices.- Specified by:
- setin class- AbstractTensor<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - W extends Semiring<W>[], - W extends Semiring<W>> 
- Parameters:
- value- New value to set the specified index of this tensor to.
- indices- Indices of the element to set.
- Returns:
- If this tensor is dense, a reference to this tensor is returned. If this tensor is sparse, a copy of this tensor with the updated value is returned.
- Throws:
- IndexOutOfBoundsException- If- indicesis not within the bounds of this tensor.
 
- 
flatten
- 
flattenFlattens a tensor along the specified axis. Unlikeflatten()- Specified by:
- flattenin class- AbstractTensor<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - W extends Semiring<W>[], - W extends Semiring<W>> 
- Parameters:
- axis- Axis along which to flatten tensor.
- Throws:
- ArrayIndexOutOfBoundsException- If the axis is not positive or larger than- this.{@link #getRank()}-1.
- See Also:
 
- 
reshapeCopies and reshapes this tensor.- Specified by:
- reshapein class- AbstractTensor<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - W extends Semiring<W>[], - W extends Semiring<W>> 
- Parameters:
- newShape- New shape for the tensor.
- Returns:
- A copy of this tensor with the new shape.
- Throws:
- TensorShapeException- If- newShapeis not broadcastable to- this.shape.
 
- 
TComputes the transpose of a tensor by exchanging the first and last axes of this tensor.- Specified by:
- Tin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Overrides:
- Tin class- AbstractTensor<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - W extends Semiring<W>[], - W extends Semiring<W>> 
- Returns:
- The transpose of this tensor.
- See Also:
 
- 
addComputes the element-wise sum between two tensors of the same shape.- Specified by:
- addin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Specified by:
- addin interface- TensorOverSemiring<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Parameters:
- b- Second tensor in the element-wise sum.
- Returns:
- The sum of this tensor with b.
- Throws:
- TensorShapeException- If this tensor and- bdo not have the same shape.
 
- 
elemMultComputes the element-wise multiplication of two tensors of the same shape.- Specified by:
- elemMultin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Specified by:
- elemMultin interface- TensorOverSemiring<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Parameters:
- b- Second tensor in the element-wise product.
- Returns:
- The element-wise product between this tensor and b.
- Throws:
- IllegalArgumentException- If this tensor and- bdo not have the same shape.
 
- 
tensorTrComputes the generalized trace of this tensor along the specified axes. The generalized tensor trace is the sum along the diagonal values of the 2D sub-arrays of this tensor specified by axis1andaxis2. The shape of the resulting tensor is equal to this tensor with theaxis1andaxis2removed.- Specified by:
- tensorTrin interface- TensorOverSemiring<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Parameters:
- axis1- First axis for 2D sub-array.
- axis2- Second axis for 2D sub-array.
- Returns:
- The generalized trace of this tensor along axis1andaxis2.
- Throws:
- IndexOutOfBoundsException- If the two axes are not both larger than zero and less than this tensors rank.
- IllegalArgumentException- If- axis1 == axis2or- this.shape.get(axis1) != this.shape.get(axis1)(i.e. the axes are equal or the tensor does not have the same length along the two axes.)
 
- 
TComputes the transpose of a tensor by exchangingaxis1andaxis2.- Specified by:
- Tin class- AbstractTensor<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - W extends Semiring<W>[], - W extends Semiring<W>> 
- Parameters:
- axis1- First axis to exchange.
- axis2- Second axis to exchange.
- Returns:
- The transpose of this tensor according to the specified axes.
- Throws:
- IndexOutOfBoundsException- If either- axis1or- axis2are out of bounds for the rank of this tensor.
- See Also:
 
- 
TComputes the transpose of this tensor. That is, permutes the axes of this tensor so that it matches the permutation specified byaxes.- Specified by:
- Tin class- AbstractTensor<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - W extends Semiring<W>[], - W extends Semiring<W>> 
- Parameters:
- axes- Permutation of tensor axis. If the tensor has rank- N, then this must be an array of length- Nwhich is a permutation of- {0, 1, 2, ..., N-1}.
- Returns:
- The transpose of this tensor with its axes permuted by the axesarray.
- Throws:
- IndexOutOfBoundsException- If any element of- axesis out of bounds for the rank of this tensor.
- IllegalArgumentException- If- axesis not a permutation of- {1, 2, 3, ... N-1}.
- See Also:
 
- 
numRowspublic int numRows()Gets the number of rows in this matrix.- Specified by:
- numRowsin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Returns:
- The number of rows in this matrix.
 
- 
numColspublic int numCols()Gets the number of columns in this matrix.- Specified by:
- numColsin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Returns:
- The number of columns in this matrix.
 
- 
getGets the element of this matrix at this specifiedrowandcol.- Specified by:
- getin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Parameters:
- row- Row index of the item to get from this matrix.
- col- Column index of the item to get from this matrix.
- Returns:
- The element of this matrix at the specified index.
 
- 
trComputes the trace of this matrix. That is, the sum of elements along the principle diagonal of this matrix. Same as MatrixMixin.trace().- Specified by:
- trin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Returns:
- The trace of this matrix.
- Throws:
- IllegalArgumentException- If this matrix is not square.
 
- 
isTriUpublic boolean isTriU()Checks if this matrix is upper triangular.- Specified by:
- isTriUin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Returns:
- trueis this matrix is upper triangular;- falseotherwise.
- See Also:
 
- 
isTriLpublic boolean isTriL()Checks if this matrix is lower triangular.- Specified by:
- isTriLin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Returns:
- trueis this matrix is lower triangular;- falseotherwise.
- See Also:
 
- 
isIpublic boolean isI()Checks if this matrix is the identity matrix. That is, checks if this matrix is square and contains only ones along the principle diagonal and zeros everywhere else.- Specified by:
- isIin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Returns:
- trueif this matrix is the identity matrix;- falseotherwise.
 
- 
multComputes the matrix multiplication between two matrices.- Specified by:
- multin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Parameters:
- b- Second matrix in the matrix multiplication.
- Returns:
- The result of matrix multiplying this matrix with matrix b.
- Throws:
- LinearAlgebraException- If- this.numCols() != b.numRows().
- See Also:
 
- 
multToSparseComputes the matrix multiplication between two sparse CSR matrices and stores the result in a sparse matrix. Warning: this method should be used with caution as sparse-sparse matrix multiplication may result in a dense matrix. In such a case, this method will likely be significantly slower than mult(AbstractCsrSemiringMatrix).- Parameters:
- b-
- Returns:
 
- 
multTransposeMultiplies this matrix with the transpose of thebtensor as if bythis.mult(b.T()). For large matrices, this method may be significantly faster than directly computing the transpose followed by the multiplication asthis.mult(b.T()).- Specified by:
- multTransposein interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Parameters:
- b- The second matrix in the multiplication and the matrix to transpose.
- Returns:
- The result of multiplying this matrix with the transpose of b.
 
- 
stackStacks matrices along columns.- Specified by:
- stackin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Parameters:
- b- Matrix to stack to this matrix.
- Returns:
- The result of stacking this matrix on top of the matrix b.
- Throws:
- IllegalArgumentException- If this matrix and matrix- bhave a different number of columns.
- See Also:
 
- 
augmentStacks matrices along rows.- Specified by:
- augmentin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Parameters:
- b- Matrix to stack to this matrix.
- Returns:
- The result of stacking bto the right of this matrix.
- Throws:
- IllegalArgumentException- If this matrix and matrix- bhave a different number of rows.
- See Also:
 
- 
augmentAugments a vector to this matrix.- Specified by:
- augmentin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Parameters:
- b- The vector to augment to this matrix.
- Returns:
- The result of augmenting bto this matrix.
 
- 
setRowSets a specified row of this matrix to a vector.- Specified by:
- setRowin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Parameters:
- row- Vector to replace specified row in this matrix.
- rowIdx- Index of the row to set.
- Returns:
- If this matrix is dense, the row set operation is done in place and a reference to this matrix is returned. If this matrix is sparse a copy will be created with the new row and returned.
 
- 
setColSets a specified column of this matrix to a vector.- Specified by:
- setColin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Parameters:
- col- Vector to replace specified column in this matrix.
- colIdx- Index of the column to set.
- Returns:
- If this matrix is dense, the column set operation is done in place and a reference to this matrix is returned. If this matrix is sparse a copy will be created with the new column and returned.
 
- 
swapRowsSwaps specified rows in the matrix. This is done in place.- Specified by:
- swapRowsin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Parameters:
- rowIndex1- Index of the first row to swap.
- rowIndex2- Index of the second row to swap.
- Returns:
- A reference to this matrix.
- Throws:
- ArrayIndexOutOfBoundsException- If either index is outside the matrix bounds.
 
- 
swapColsSwaps specified columns in the matrix. This is done in place.- Specified by:
- swapColsin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Parameters:
- colIndex1- Index of the first column to swap.
- colIndex2- Index of the second column to swap.
- Returns:
- A reference to this matrix.
- Throws:
- ArrayIndexOutOfBoundsException- If either index is outside the matrix bounds.
 
- 
isSymmetricpublic boolean isSymmetric()Checks if a matrix is symmetric. That is, if the matrix is square and equal to its transpose.- Specified by:
- isSymmetricin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Returns:
- trueif this matrix is symmetric;- falseotherwise.
 
- 
isHermitianpublic boolean isHermitian()Checks if a matrix is Hermitian. That is, if the matrix is square and equal to its conjugate transpose.- Specified by:
- isHermitianin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Returns:
- trueif this matrix is Hermitian;- falseotherwise.
 
- 
isOrthogonalpublic boolean isOrthogonal()Checks if this matrix is orthogonal. That is, if the inverse of this matrix is equal to its transpose.- Specified by:
- isOrthogonalin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Returns:
- trueif this matrix it is orthogonal;- falseotherwise.
 
- 
removeRowRemoves a specified row from this matrix.- Specified by:
- removeRowin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Parameters:
- rowIndex- Index of the row to remove from this matrix.
- Returns:
- A copy of this matrix with the specified row removed.
 
- 
removeRowsRemoves a specified set of rows from this matrix.- Specified by:
- removeRowsin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Parameters:
- rowIndices- The indices of the rows to remove from this matrix. Assumed to contain unique values.
- Returns:
- A copy of this matrix with the specified column removed.
 
- 
removeColRemoves a specified column from this matrix.- Specified by:
- removeColin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Parameters:
- colIndex- Index of the column to remove from this matrix.
- Returns:
- A copy of this matrix with the specified column removed.
 
- 
removeColsRemoves a specified set of columns from this matrix.- Specified by:
- removeColsin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Parameters:
- colIndices- Indices of the columns to remove from this matrix. Assumed to contain unique values.
- Returns:
- A copy of this matrix with the specified column removed.
 
- 
setSliceCopyCreates a copy of this matrix and sets a slice of the copy to the specified values. The rowStart and colStart parameters specify the upper left index location of the slice to set.- Specified by:
- setSliceCopyin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Parameters:
- values- New values for the specified slice.
- rowStart- Starting row index for the slice (inclusive).
- colStart- Starting column index for the slice (inclusive).
- Returns:
- A copy of this matrix with the given slice set to the specified values.
- Throws:
- IndexOutOfBoundsException- If rowStart or colStart are not within the matrix.
- IllegalArgumentException- If the values slice, with upper left corner at the specified location, does not fit completely within this matrix.
 
- 
getSliceGets a specified slice of this matrix.- Specified by:
- getSlicein interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Parameters:
- rowStart- Starting row index of slice (inclusive).
- rowEnd- Ending row index of slice (exclusive).
- colStart- Starting column index of slice (inclusive).
- colEnd- Ending row index of slice (exclusive).
- Returns:
- The specified slice of this matrix. This is a completely new matrix and NOT a view into the matrix.
- Throws:
- ArrayIndexOutOfBoundsException- If any of the indices are out of bounds of this matrix.
- IllegalArgumentException- If- rowEndis not greater than- rowStartor if- colEndis not greater than- colStart.
 
- 
setSets an index of this matrix to the specified value.- Specified by:
- setin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Parameters:
- value- Value to set.
- row- Row index to set.
- col- Column index to set.
- Returns:
- A reference to this matrix.
 
- 
getTriUExtracts the upper-triangular portion of this matrix with a specified diagonal offset. All other data of the resulting matrix will be zero.- Specified by:
- getTriUin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Parameters:
- diagOffset- Diagonal offset for upper-triangular portion to extract:- If zero, then all data at and above the principle diagonal of this matrix are extracted.
- If positive, then all data at and above the equivalent super-diagonal are extracted.
- If negative, then all data at and above the equivalent sub-diagonal are extracted.
 
- Returns:
- The upper-triangular portion of this matrix with a specified diagonal offset. All other data of the returned matrix will be zero.
- Throws:
- IllegalArgumentException- If- diagOffsetis not in the range (-numRows, numCols).
 
- 
getTriLExtracts the lower-triangular portion of this matrix with a specified diagonal offset. All other data of the resulting matrix will be zero.- Specified by:
- getTriLin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Parameters:
- diagOffset- Diagonal offset for lower-triangular portion to extract:- If zero, then all data at and above the principle diagonal of this matrix are extracted.
- If positive, then all data at and above the equivalent super-diagonal are extracted.
- If negative, then all data at and above the equivalent sub-diagonal are extracted.
 
- Returns:
- The lower-triangular portion of this matrix with a specified diagonal offset. All other data of the returned matrix will be zero.
- Throws:
- IllegalArgumentException- If- diagOffsetis not in the range (-numRows, numCols).
 
- 
copyCreates a deep copy of this tensor.- Specified by:
- copyin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Specified by:
- copyin class- AbstractTensor<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - W extends Semiring<W>[], - W extends Semiring<W>> 
- Returns:
- A deep copy of this tensor.
 
- 
HComputes the Hermitian transpose of this matrix.- Specified by:
- Hin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Returns:
- The Hermitian transpose of this matrix.
 
- 
sortIndicespublic void sortIndices()Sorts the indices of this tensor in lexicographical order while maintaining the associated value for each index.
- 
toDenseConverts this sparse CSR matrix to an equivalent dense matrix. The zero data of this CSR matrix will be attempted to be filled with a zero value if it could be determined during construction of this sparse CSR matrix. If the zero value could not be determined the zero data will be filled with null(this only happens whennnz==0). To avoid this, the zero element of the semiring for this matrix can be set explicitly usingsetZeroElement(Semiring).- Returns:
- A dense matrix which is equivalent to this sparse CSR matrix.
 
- 
toCooConverts this sparse CSR matrix to an equivalent sparse COO matrix.- Returns:
- A sparse COO matrix equivalent to this sparse CSR matrix.
 
- 
toTensorConverts this CSR matrix to an equivalent sparse COO tensor.- Returns:
- An sparse COO tensor equivalent to this CSR matrix.
 
- 
toTensorConverts this CSR matrix to an equivalent COO tensor with the specified shape.- Parameters:
- newShape- New shape for the COO tensor. Can be any rank but must be broadcastable to- this.shape.
- Returns:
- A COO tensor equivalent to this CSR matrix which has been reshaped to newShape
 
- 
toVectorConverts this sparse CSR matrix to an equivalent vector. If this matrix is not a row or column vector it will be flattened before conversion.- Specified by:
- toVectorin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Returns:
- A vector equivalent to this CSR matrix.
 
- 
subWarning: throws UnsupportedOperationExceptionas subtraction is not defined for general semiring matrices.Computes the element-wise difference of two matrices. - Specified by:
- subin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Parameters:
- b- Second matrix in the element-wise difference.
- Returns:
- The element-wise difference of this matrix and b.
 
- 
divWarning: throws UnsupportedOperationExceptionas division is not defined for general semiring matrices.Computes the element-wise quotient of two matrices. - Specified by:
- divin interface- MatrixMixin<T extends AbstractCsrSemiringMatrix<T,- U, - V, - W>, - U extends AbstractDenseSemiringMatrix<U, - ?, - W>, - V extends AbstractCooSemiringVector<V, - ?, - ?, - U, - W>, - W extends Semiring<W>> 
- Parameters:
- b- Second matrix in the element-wise quotient.
- Returns:
- The element-wise quotient of this matrix and b.
 
- 
coalesceCoalesces this sparse CSR matrix. An uncoalesced matrix is a sparse matrix with multiple data for a single index. This method will ensure that each index only has one non-zero value by summing duplicated data. If another form of aggregation other than summing is desired, usecoalesce(BinaryOperator).- Returns:
- A new coalesced sparse CSR matrix which is equivalent to this CSR matrix.
- See Also:
 
- 
coalesceCoalesces this sparse COO matrix. An uncoalesced matrix is a sparse matrix with multiple data for a single index. This method will ensure that each index only has one non-zero value by aggregating duplicated data usingaggregator.- Parameters:
- aggregator- Custom aggregation function to combine multiple.
- Returns:
- A new coalesced sparse COO matrix which is equivalent to this COO matrix.
- See Also:
 
 
-