Class AbstractDenseSemiringMatrix<T extends AbstractDenseSemiringMatrix<T,U,V>,U extends AbstractDenseSemiringVector<U,T,V>,V extends Semiring<V>>
java.lang.Object
org.flag4j.arrays.backend.AbstractTensor<T,V[],V>
org.flag4j.arrays.backend.semiring_arrays.AbstractDenseSemiringTensor<T,V>
org.flag4j.arrays.backend.semiring_arrays.AbstractDenseSemiringMatrix<T,U,V>
- Type Parameters:
T- The type of this matrix.U- The type of the vector which is of similar type toT.V- The type of the semiring the data of the matrix belong to.
- All Implemented Interfaces:
Serializable,MatrixMixin<T,,T, U, V> SemiringTensorMixin<T,,T, V> TensorOverSemiring<T,T, V[], V>
- Direct Known Subclasses:
AbstractDenseRingMatrix,SemiringMatrix
public abstract class AbstractDenseSemiringMatrix<T extends AbstractDenseSemiringMatrix<T,U,V>,U extends AbstractDenseSemiringVector<U,T,V>,V extends Semiring<V>>
extends AbstractDenseSemiringTensor<T,V>
implements MatrixMixin<T,T,U,V>
The base class for all dense matrices whose elements are members of a
Semiring.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionfinal intThe number of columns in this matrix.final intThe number of rows in this matrix.Fields inherited from class org.flag4j.arrays.backend.semiring_arrays.AbstractDenseSemiringTensor
zeroElementFields inherited from class org.flag4j.arrays.backend.AbstractTensor
data, rank, shape -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractDenseSemiringMatrix(Shape shape, V[] entries) Creates a tensor with the specified data and shape. -
Method Summary
Modifier and TypeMethodDescriptionStacks matrices along rows.Augments a vector to this matrix.intGets the length of the data array which backs this matrix.flatten()Flattens this matrix to a row vector.flatten(int axis) Flattens this matrix along the specified axis.get(int row, int col) Gets the element of this matrix at this specifiedrowandcol.getCol(int colIdx, int rowStart, int rowEnd) Gets a specified column of this matrix betweenrowStart(inclusive) androwEnd(exclusive).getDiag(int diagOffset) Gets the elements of this matrix along the specified diagonal.getRow(int rowIdx, int colStart, int colEnd) Gets a specified row of this matrix betweencolStart(inclusive) andcolEnd(exclusive).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.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.protected abstract AbstractCooSemiringMatrix<?, T, ?, V> makeLikeCooMatrix(Shape shape, V[] entries, int[] rowIndices, int[] colIndices) Constructs a sparse COO matrix which is of a similar type as this dense matrix.abstract AbstractCsrSemiringMatrix<?, T, ?, V> makeLikeCsrMatrix(Shape shape, V[] entries, int[] rowPointers, int[] colIndices) Constructs a sparse CSR matrix which is of a similar type as this dense matrix.protected abstract UmakeLikeVector(Shape shape, V[] entries) Constructs a vector of a similar type as this matrix.protected abstract UmakeLikeVector(V[] entries) Constructs a vector of a similar type as this matrix.Computes the matrix multiplication between two matrices.Computes the matrix-vector multiplication of a vector with this 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.Sets an index of this matrix to the specified value.Sets a specified column of this matrix to a vector.Sets a specified column of this matrix to an array.Sets a specified row of this matrix to a vector.Sets a specified row of this matrix to an array.Sets a slice of this matrix to the specified values.setSliceCopy(T values, int rowStart, int colStart) Creates a copy of this matrix and sets a slice of the copy to the specified values.Sets the value of this matrix using a 2D array.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.AbstractCooSemiringMatrix<?, ?, ?, V> toCoo()Converts this matrix to an equivalent sparse COO matrix.AbstractCooSemiringMatrix<?, ?, ?, V> toCoo(double estimatedSparsity) Converts this matrix to an equivalent sparse COO matrix.AbstractCsrSemiringMatrix<?, ?, ?, V> toCsr()Converts this matrix to an equivalent sparse CSR matrix.AbstractCsrSemiringMatrix<?, ?, ?, V> toCsr(double estimatedSparsity) Converts this matrix to an equivalent sparse CSR matrix.abstract AbstractDenseSemiringTensor<?, V> toTensor()Converts this matrix to an equivalent tensor.abstract AbstractDenseSemiringTensor<?, V> Converts this matrix to an equivalent tensor with the specifiednewShape.toVector()Converts this matrix to an equivalent vector.tr()Computes the trace of this matrix.Methods inherited from class org.flag4j.arrays.backend.semiring_arrays.AbstractDenseSemiringTensor
add, addEq, argmax, argmin, copy, elemMult, get, getZeroElement, makeLikeCooTensor, max, min, reshape, set, setZeroElement, T, T, tensorDot, tensorTrMethods 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, copy, div, elemMult, fib, getCol, getDiag, getRow, getShape, getTriL, getTriU, isDiag, isSquare, isTri, isVector, stack, sub, trace, vectorTypeMethods inherited from interface org.flag4j.arrays.backend.semiring_arrays.SemiringTensorMixin
add, addEq, isOnes, isZeros, makeEmptyDataArray, mult, multEq, prod, sumMethods inherited from interface org.flag4j.arrays.backend.semiring_arrays.TensorOverSemiring
getData, getRank, getShape, makeLikeTensor, tensorDot, tensorDot, tensorDot, tensorTr
-
Field Details
-
numRows
public final int numRowsThe number of rows in this matrix. -
numCols
public final int numColsThe number of columns in this matrix.
-
-
Constructor Details
-
AbstractDenseSemiringMatrix
Creates a tensor with the specified data and shape.- Parameters:
shape- Shape of this tensor.entries- Entries of this tensor. If this tensor is dense, this specifies all data within the tensor. If this tensor is sparse, this specifies only the non-zero data of the tensor.
-
-
Method Details
-
makeLikeVector
-
makeLikeVector
-
makeLikeCooMatrix
protected abstract AbstractCooSemiringMatrix<?,T, makeLikeCooMatrix?, V> (Shape shape, V[] entries, int[] rowIndices, int[] colIndices) Constructs a sparse COO matrix which is of a similar type as this dense matrix.- Parameters:
shape- Shape of the COO matrix.entries- Non-zero data of the COO matrix.rowIndices- Non-zero row indices of the COO matrix.colIndices- Non-zero column indices of the COO matrix.- Returns:
- A sparse COO matrix which is of a similar type as this dense matrix.
-
makeLikeCsrMatrix
public abstract AbstractCsrSemiringMatrix<?,T, makeLikeCsrMatrix?, V> (Shape shape, V[] entries, int[] rowPointers, int[] colIndices) Constructs a sparse CSR matrix which is of a similar type as this dense 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.- Returns:
- A sparse CSR matrix which is of a similar type as this dense matrix.
-
T
Computes the transpose of a tensor by exchanging the first and last axes of this tensor.- Specified by:
Tin interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - Overrides:
Tin classAbstractTensor<T extends AbstractDenseSemiringMatrix<T,U, V>, V extends Semiring<V>[], V extends Semiring<V>> - Returns:
- The transpose of this tensor.
- See Also:
-
numRows
public int numRows()Gets the number of rows in this matrix.- Specified by:
numRowsin interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - Returns:
- The number of rows in this matrix.
-
numCols
public int numCols()Gets the number of columns in this matrix.- Specified by:
numColsin interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - Returns:
- The number of columns in this matrix.
-
dataLength
public int dataLength()Gets the length of the data array which backs this matrix.- Specified by:
dataLengthin interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - Overrides:
dataLengthin classAbstractDenseSemiringTensor<T extends AbstractDenseSemiringMatrix<T,U, V>, V extends Semiring<V>> - Returns:
- The length of the data array which backs this matrix.
-
get
Gets the element of this matrix at this specifiedrowandcol.- Specified by:
getin interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - 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.
-
tr
Computes 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 interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - Returns:
- The trace of this matrix.
- Throws:
IllegalArgumentException- If this matrix is not square.
-
isTriU
public boolean isTriU()Checks if this matrix is upper triangular.- Specified by:
isTriUin interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - Returns:
trueis this matrix is upper triangular;falseotherwise.- See Also:
-
isTriL
public boolean isTriL()Checks if this matrix is lower triangular.- Specified by:
isTriLin interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - Returns:
trueis this matrix is lower triangular;falseotherwise.- See Also:
-
isI
public 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 interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - Returns:
trueif this matrix is the identity matrix;falseotherwise.
-
mult
Computes the matrix-vector multiplication of a vector with this matrix.- Specified by:
multin interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - Parameters:
b- Vector in the matrix-vector multiplication.- Returns:
- The result of multiplying this matrix with
b. - Throws:
LinearAlgebraException- If the number of columns in this matrix do not equal the size ofb.
-
mult
Computes the matrix multiplication between two matrices.- Specified by:
multin interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - Parameters:
b- Second matrix in the matrix multiplication.- Returns:
- The result of matrix multiplying this matrix with matrix
b. - Throws:
LinearAlgebraException- Ifthis.numCols() != b.numRows().
-
multTranspose
Multiplies this matrix with the transpose of thebtensor as if bythis.mult(b.T()). For large matrices, this method may, be noticeably faster than directly computing the transpose followed by the multiplication asthis.mult(b.T()).- Specified by:
multTransposein interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - 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.
-
stack
Stacks matrices along columns.- Specified by:
stackin interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - 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 matrixbhave a different number of columns.- See Also:
-
augment
Stacks matrices along rows.- Specified by:
augmentin interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - 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 matrixbhave a different number of rows.- See Also:
-
augment
Augments a vector to this matrix.- Specified by:
augmentin interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - Parameters:
b- The vector to augment to this matrix.- Returns:
- The result of augmenting
bto this matrix.
-
swapRows
Swaps specified rows in the matrix. This is done in place.- Specified by:
swapRowsin interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - Parameters:
rowIndex1- Index of the first row to swap.rowIndex2- Index of the second row to swap.- Returns:
- A reference to this matrix.
- Throws:
IndexOutOfBoundsException- If either index is outside the matrix bounds.
-
swapCols
Swaps specified columns in the matrix. This is done in place.- Specified by:
swapColsin interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - 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.
-
isSymmetric
public boolean isSymmetric()Checks if a matrix is symmetric. That is, if the matrix is square and equal to its transpose.- Specified by:
isSymmetricin interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - Returns:
trueif this matrix is symmetric;falseotherwise.
-
isHermitian
public boolean isHermitian()Checks if a matrix is Hermitian. That is, if the matrix is square and equal to its conjugate transpose.- Specified by:
isHermitianin interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - Returns:
trueif this matrix is Hermitian;falseotherwise.
-
isOrthogonal
public boolean isOrthogonal()Checks if this matrix is orthogonal. That is, if the inverse of this matrix is approximately equal to its transpose.- Specified by:
isOrthogonalin interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - Returns:
trueif this matrix it is orthogonal;falseotherwise.
-
removeRow
Removes a specified row from this matrix.- Specified by:
removeRowin interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - Parameters:
rowIndex- Index of the row to remove from this matrix.- Returns:
- A copy of this matrix with the specified row removed.
-
removeRows
Removes a specified set of rows from this matrix.- Specified by:
removeRowsin interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - 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.
-
removeCol
Removes a specified column from this matrix.- Specified by:
removeColin interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - Parameters:
colIndex- Index of the column to remove from this matrix.- Returns:
- a copy of this matrix with the specified column removed.
-
removeCols
Removes a specified set of columns from this matrix.- Specified by:
removeColsin interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - 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.
-
setSlice
Sets a slice of this matrix to the specified values. The rowStart and colStart parameters specify the upper left index location of the slice to set within this matrix.- 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 reference to this matrix.
- Throws:
IllegalArgumentException- 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.
-
setSliceCopy
Creates 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 interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - 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.
-
getSlice
Gets a specified slice of this matrix.- Specified by:
getSlicein interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - 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- IfrowEndis not greater thanrowStartor ifcolEndis not greater thancolStart.
-
set
Sets an index of this matrix to the specified value.- Specified by:
setin interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - Parameters:
value- Value to set.row- Row index to set.col- Column index to set.- Returns:
- A reference to this matrix.
-
setValues
Sets the value of this matrix using a 2D array.- Parameters:
values- New values of the matrix.- Returns:
- A reference to this matrix.
- Throws:
IllegalArgumentException- If the values array has a different shape then this matrix.
-
getTriU
Extracts 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 interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - 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- IfdiagOffsetis not in the range (-numRows, numCols).
-
getTriL
Extracts 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 interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - 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- IfdiagOffsetis not in the range (-numRows, numCols).
-
getDiag
Gets the elements of this matrix along the specified diagonal.- Specified by:
getDiagin interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - Parameters:
diagOffset- The diagonal to get within this matrix.- If
diagOffset == 0: Then the elements of the principle diagonal are collected. - If
diagOffset < 0: Then the elements of the sub-diagonaldiagOffsetbelow the principle diagonal are collected. - If
diagOffset > 0: Then the elements of the super-diagonaldiagOffsetabove the principle diagonal are collected.
- If
- Returns:
- The elements of the specified diagonal as a vector.
-
setRow
Sets a specified row of this matrix to a vector.- Specified by:
setRowin interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - 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.
-
setRow
Sets a specified row of this matrix to an array.- Parameters:
row- Array containing values 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.
-
setCol
Sets a specified column of this matrix to a vector.- Specified by:
setColin interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - 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.
-
setCol
Sets a specified column of this matrix to an array.- 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.
-
getRow
Gets a specified row of this matrix betweencolStart(inclusive) andcolEnd(exclusive).- Specified by:
getRowin interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - Parameters:
rowIdx- Index of the row of this matrix to get.colStart- Starting column of the row (inclusive).colEnd- Ending column of the row (exclusive).- Returns:
- The row at index
rowIdxof this matrix between thecolStartandcolEndindices. - Throws:
IndexOutOfBoundsException- If eithercolEndarecolStartout of bounds for the shape of this matrix.IllegalArgumentException- IfcolEndis less thancolStart.
-
getCol
Gets a specified column of this matrix betweenrowStart(inclusive) androwEnd(exclusive).- Specified by:
getColin interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - Parameters:
colIdx- Index of the column of this matrix to get.rowStart- Starting row of the column (inclusive).rowEnd- Ending row of the column (exclusive).- Returns:
- The column at index
colIdxof this matrix between therowStartandrowEndindices. - Throws:
IndexOutOfBoundsException- If eithercolEndarecolStartout of bounds for the shape of this matrix.IllegalArgumentException- IfrowEndis less thanrowStart.
-
flatten
-
flatten
Flattens this matrix along the specified axis.- Overrides:
flattenin classAbstractDenseSemiringTensor<T extends AbstractDenseSemiringMatrix<T,U, V>, V extends Semiring<V>> - Parameters:
axis- Axis along which to flatten tensor.- Returns:
- If
axis == 0a matrix with the shape(1, this.numRows*this.numCols)is returned. Ifaxis == 1a matrix with the shape(this.numRows*this.numCols, 1)is returned. - Throws:
ArrayIndexOutOfBoundsException- If the axis is not positive or larger thanthis.{@link #getRank()}-1.- See Also:
-
H
Computes the Hermitian transpose of this matrix.- Specified by:
Hin interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - Returns:
- The Hermitian transpose of this matrix.
-
toCoo
Converts this matrix to an equivalent sparse COO matrix.- Overrides:
toCooin classAbstractDenseSemiringTensor<T extends AbstractDenseSemiringMatrix<T,U, V>, V extends Semiring<V>> - Returns:
- A sparse COO matrix that is equivalent to this dense matrix.
- See Also:
-
toCoo
Converts this matrix to an equivalent sparse COO matrix.- Overrides:
toCooin classAbstractDenseSemiringTensor<T extends AbstractDenseSemiringMatrix<T,U, V>, V extends Semiring<V>> - Parameters:
estimatedSparsity- Estimated sparsity of the matrix. Must be between 0 and 1 inclusive. If this is an accurate estimation it may provide a slight speedup and can reduce unneeded memory consumption. If memory is a concern, it is better to over-estimate the sparsity. If speed is the concern it is better to under-estimate the sparsity.- Returns:
- A sparse COO matrix that is equivalent to this dense matrix.
- See Also:
-
toCsr
Converts this matrix to an equivalent sparse CSR matrix.- Returns:
- A sparse CSR matrix that is equivalent to this dense matrix.
- See Also:
-
toCsr
Converts this matrix to an equivalent sparse CSR matrix.- Parameters:
estimatedSparsity- Estimated sparsity of the matrix. Must be between 0 and 1 inclusive. If this is an accurate estimation it may provide a slight speedup and can reduce unneeded memory consumption. If memory is a concern, it is better to over-estimate the sparsity. If speed is the concern it is better to under-estimate the sparsity.- Returns:
- A sparse CSR matrix that is equivalent to this dense matrix.
- See Also:
-
toVector
Converts this matrix to an equivalent vector. If this matrix is not a row or column vector it will first be flattened then converted to a vector.- Specified by:
toVectorin interfaceMatrixMixin<T extends AbstractDenseSemiringMatrix<T,U, V>, T extends AbstractDenseSemiringMatrix<T, U, V>, U extends AbstractDenseSemiringVector<U, T, V>, V extends Semiring<V>> - Returns:
- A vector which contains the same data as this matrix.
-
toTensor
Converts this matrix to an equivalent tensor.- Returns:
- A tensor with the same shape and data as this matrix.
-
toTensor
Converts this matrix to an equivalent tensor with the specifiednewShape.- Parameters:
newShape- Shape of the tensor. Can be any rank but must be broadcastable to the shape of this matrix.- Returns:
- A tensor with the specified
newShapeand the same data as this matrix.
-