Package jline.util.matrix
Class SparseMatrix
java.lang.Object
jline.util.matrix.BaseMatrix
jline.util.matrix.SparseMatrix
- All Implemented Interfaces:
Serializable
Base class for sparse matrix implementations, containing the core data structure
and methods that directly manipulate the underlying sparse matrix representation.
This class encapsulates all interactions with EJML's DMatrixSparseCSC and
CommonOps_DSCC classes, providing a clean abstraction layer for sparse matrix
operations. It serves as the foundation for concrete sparse matrix implementations like
Matrix.
The class provides:
- Basic matrix operations (get, set, dimensions)
- Encapsulated CommonOps_DSCC method calls
- Memory management for sparse matrix data structures
- Utility methods for matrix manipulation
- Since:
- 1.0
- Author:
- QORE Lab, Imperial College London
- See Also:
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedProtected constructor for delayed initialization.SparseMatrix(int numRows, int numCols) Constructs an empty sparse matrix with specified dimensions.SparseMatrix(int numRows, int numCols, int arrayLength) Constructs a sparse matrix with specified dimensions and initial capacity.protectedSparseMatrix(SparseMatrix matrix) Copy constructor for creating a new sparse matrix from an existing one.SparseMatrix(org.ejml.data.DMatrix matrix) Constructs a sparse matrix by copying an existing EJML sparse matrix. -
Method Summary
Modifier and TypeMethodDescriptionvoidabsEq()Replaces each value in the matrix with its absolute value, in-place.protected voidadd(double alpha, org.ejml.data.DMatrix A, double beta, org.ejml.data.DMatrix B, org.ejml.data.DMatrix output) Performs the operation: output = alpha*A + beta*B.protected org.ejml.data.DMatrixaddMatrices(double alpha, org.ejml.data.DMatrix A, double beta, org.ejml.data.DMatrix B, org.ejml.data.DMatrix output) Performs the operation: output = alpha*A + beta*B.protected voidaddMatricesInPlace(double alpha, org.ejml.data.DMatrix A, double beta, org.ejml.data.DMatrix B, org.ejml.data.DMatrix output) protected static voidaddMatricesInPlaceStatic(double alpha, org.ejml.data.DMatrix A, double beta, org.ejml.data.DMatrix B, org.ejml.data.DMatrix output) protected static org.ejml.data.DMatrixSparseCSCaddMatricesStatic(double alpha, org.ejml.data.DMatrix A, double beta, org.ejml.data.DMatrix B, org.ejml.data.DMatrix output) booleanany()Checks if the current matrix contains any non-zero elements.protected voidapplyConditionalTransform(double source, double target, double tol, String operation) Applies a transformation to matrix elements based on conditions.protected voidprotected static voidchangeSignStatic(org.ejml.data.DMatrix input, org.ejml.data.DMatrix output) voidcolIncrease(int col, double a) Adds a scalar value to each element in the specified column.protected org.ejml.data.DMatrixSparseCSCconcatColumns(org.ejml.data.DMatrix left, org.ejml.data.DMatrix right, org.ejml.data.DMatrix output) protected voidconcatColumnsInPlace(org.ejml.data.DMatrix left, org.ejml.data.DMatrix right, org.ejml.data.DMatrix output) Concatenates matrices column-wise.protected static voidconcatColumnsInPlaceStatic(org.ejml.data.DMatrix left, org.ejml.data.DMatrix right, org.ejml.data.DMatrix output) protected static org.ejml.data.DMatrixSparseCSCconcatColumnsStatic(org.ejml.data.DMatrix left, org.ejml.data.DMatrix right, org.ejml.data.DMatrix output) protected org.ejml.data.DMatrixSparseCSCconcatRows(org.ejml.data.DMatrix top, org.ejml.data.DMatrix bottom, org.ejml.data.DMatrix output) protected voidconcatRowsInPlace(org.ejml.data.DMatrix top, org.ejml.data.DMatrix bottom, org.ejml.data.DMatrix output) Concatenates matrices row-wise.protected static voidconcatRowsInPlaceStatic(org.ejml.data.DMatrix top, org.ejml.data.DMatrix bottom, org.ejml.data.DMatrix output) protected static org.ejml.data.DMatrixSparseCSCconcatRowsStatic(org.ejml.data.DMatrix top, org.ejml.data.DMatrix bottom, org.ejml.data.DMatrix output) abstract BaseMatrixcopy()Creates and returns a deep copy of this sparse matrix.countEachRow(double val) Counts occurrences of each unique value in each row.protected abstract BaseMatrixcreateNewInstance(int rows, int cols, int nzLength) Creates a new instance of the concrete sparse matrix implementation.protected doubleprotected static doubledeterminantStatic(org.ejml.data.DMatrix matrix) protected static org.ejml.data.DMatrixSparseCSCdiagStatic(double[] values) protected static org.ejml.data.DMatrixSparseCSCdiagWithMatrixStatic(org.ejml.data.DMatrixSparseCSC A, double[] values, int offset, int length) protected static org.ejml.data.DMatrixSparseCSCdiagWithRetStatic(org.ejml.data.DMatrixSparseCSC ret, double[] values, int offset, int length) protected voiddivideInPlace(double scalar) protected static voiddivideInPlaceStatic(org.ejml.data.DMatrix matrix, double scalar) protected voiddivideMatrix(double scalar, org.ejml.data.DMatrix output) protected static voiddivideMatrixStatic(org.ejml.data.DMatrix input, double scalar, org.ejml.data.DMatrix output) protected voiddivideRowsByArray(double[] diag, int offset) protected static voiddivideRowsByArrayStatic(double[] diag, int offset, org.ejml.data.DMatrix matrix) protected voiddivideScalarByMatrix(double scalar, org.ejml.data.DMatrix output) protected static voiddivideScalarByMatrixStatic(double scalar, org.ejml.data.DMatrix input, org.ejml.data.DMatrix output) protected doubleprotected doubleprotected doubleprotected org.ejml.data.DMatrixelementMult(org.ejml.data.DMatrix A, org.ejml.data.DMatrix B, org.ejml.data.DMatrix output) protected static org.ejml.data.DMatrixSparseCSCelementMultStatic(org.ejml.data.DMatrix A, org.ejml.data.DMatrix B, org.ejml.data.DMatrix output) protected doubleabstract booleanIndicates whether some other object is "equal to" this sparse matrix.protected org.ejml.data.DMatrixSparseCSCextractColumn(org.ejml.data.DMatrix input, int column, org.ejml.data.DMatrix output) protected voidextractColumnInPlace(org.ejml.data.DMatrix input, int column, org.ejml.data.DMatrix output) protected static voidextractColumnInPlaceStatic(org.ejml.data.DMatrix input, int column, org.ejml.data.DMatrix output) protected static org.ejml.data.DMatrixSparseCSCextractColumnStatic(org.ejml.data.DMatrix input, int column, org.ejml.data.DMatrix output) protected voidextractDiag(org.ejml.data.DMatrix input, org.ejml.data.DMatrix output) protected static voidextractDiagStatic(org.ejml.data.DMatrix input, org.ejml.data.DMatrix output) protected voidextractMatrix(org.ejml.data.DMatrix src, int srcX0, int srcX1, int srcY0, int srcY1, org.ejml.data.DMatrix dst, int dstY0, int dstX0) protected static voidextractMatrixStatic(org.ejml.data.DMatrix src, int srcX0, int srcX1, int srcY0, int srcY1, org.ejml.data.DMatrix dst, int dstY0, int dstX0) protected org.ejml.data.DMatrixSparseCSCextractRows(org.ejml.data.DMatrix input, int row0, int row1, org.ejml.data.DMatrix output) protected voidextractRowsInPlace(org.ejml.data.DMatrix input, int row0, int row1, org.ejml.data.DMatrix output) protected static voidextractRowsInPlaceStatic(org.ejml.data.DMatrix input, int row0, int row1, org.ejml.data.DMatrix output) protected static org.ejml.data.DMatrixSparseCSCextractRowsStatic(org.ejml.data.DMatrix input, int row0, int row1, org.ejml.data.DMatrix output) protected voidfillMatrix(double value) Fills the matrix with the specified value.protected static voidfillMatrixStatic(org.ejml.data.DMatrix matrix, double value) Returns a matrix containing indices of all non-negative elements.doubleget(int row, int col) Returns the value at the specified matrix position.protected intgetColumnIndex(int col) protected int[]protected int[]org.ejml.data.DMatrixSparseCSCgetData()Returns the underlying EJML sparse matrix data structure.intReturns the number of stored non-zero elements.protected intgetNonZeroRow(int index) int[]Returns array of row indices of non-zero entries.intReturns the number of non-zero elements in the matrix.protected doublegetNonZeroValue(int index) double[]Returns array of non-zero values.intReturns the number of columns in the matrix.protected intintReturns the number of non-zero elements in the matrix.intReturns the number of rows in the matrix.protected intbooleanChecks if the matrix contains duplicate values.booleanChecks if the matrix contains any finite (non-infinite, non-NaN) values.booleanChecks if the matrix contains any infinite values.booleanChecks if more than one finite value exists.booleanhasNaN()Checks if the matrix contains any NaN values.protected static org.ejml.data.DMatrixSparseCSCidentityStatic(int length) protected static voidinvertStatic(org.ejml.data.DMatrix input, org.ejml.data.DMatrixRMaj output) protected voidmult(org.ejml.data.DMatrix A, org.ejml.data.DMatrix B, org.ejml.data.DMatrix output) Performs matrix multiplication: output = A * B.protected org.ejml.data.DMatrixmultMatrix(org.ejml.data.DMatrix B, org.ejml.data.DMatrix output) Performs matrix multiplication with sparse matrices.protected static org.ejml.data.DMatrixSparseCSCmultMatrixStatic(org.ejml.data.DMatrix A, org.ejml.data.DMatrix B, org.ejml.data.DMatrix output) protected voidRemoves zero-valued elements from the sparse matrix with default tolerance.protected voidremoveZerosWithTol(double tolerance) Removes zero-valued elements from the matrix with specified tolerance.protected static voidremoveZerosWithTolStatic(org.ejml.data.DMatrix matrix, double tolerance) voidreshape(int numRows, int numCols) Reshapes the matrix to the specified dimensions.protected voidscaleInPlace(double alpha) Scales the matrix in-place by the specified factor.protected voidscaleMatrix(double scalar, org.ejml.data.DMatrix output) protected static voidscaleMatrixStatic(double scalar, org.ejml.data.DMatrix input, org.ejml.data.DMatrix output) voidset(int row, int col, double value) Sets the value at the specified matrix position.protected voidsetColumnIndex(int col, int value) protected voidSets the underlying data structure for BaseMatrix compatibility.voidsetData(org.ejml.data.DMatrixSparseCSC newData) Sets the underlying EJML sparse matrix data structure.protected voidsetNonZeroLength(int length) protected voidsetNonZeroRow(int index, int row) protected voidsetNonZeroValue(int index, double value) voidshrinkNumCols(int newmax) Reduce the maximum number of columns by setting the internal column count.voidshrinkNumRows(int newmax) Reduce the maximum number of rows by setting the internal row count.protected static booleansolveStatic(org.ejml.data.DMatrix a, org.ejml.data.DMatrix b, org.ejml.data.DMatrix x) protected org.ejml.data.DMatrixprotected static org.ejml.data.DMatrixRMajsumColsStatic(org.ejml.data.DMatrix matrix) protected org.ejml.data.DMatrixprotected static org.ejml.data.DMatrixRMajsumRowsStatic(org.ejml.data.DMatrix matrix) toString()Returns a string representation of the matrix.protected voidtranspose(org.ejml.data.DMatrix input, org.ejml.data.DMatrix output) Computes the transpose of the input matrix.protected voidtransposeMatrix(org.ejml.data.DMatrix output) Computes the transpose of this matrix.protected static voidtransposeMatrixStatic(org.ejml.data.DMatrix input, org.ejml.data.DMatrix output) voidzero()Sets all elements in the matrix to zero.
-
Constructor Details
-
SparseMatrix
public SparseMatrix(int numRows, int numCols, int arrayLength) Constructs a sparse matrix with specified dimensions and initial capacity.- Parameters:
numRows- the number of rows in the matrixnumCols- the number of columns in the matrixarrayLength- the initial capacity for non-zero elements
-
SparseMatrix
public SparseMatrix(int numRows, int numCols) Constructs an empty sparse matrix with specified dimensions.- Parameters:
numRows- the number of rows in the matrixnumCols- the number of columns in the matrix
-
SparseMatrix
public SparseMatrix(org.ejml.data.DMatrix matrix) Constructs a sparse matrix by copying an existing EJML sparse matrix.- Parameters:
matrix- the EJML sparse matrix to copy
-
SparseMatrix
Copy constructor for creating a new sparse matrix from an existing one.- Parameters:
matrix- the sparse matrix to copy
-
SparseMatrix
protected SparseMatrix()Protected constructor for delayed initialization. Subclasses must ensure that data is properly initialized.
-
-
Method Details
-
addMatricesInPlaceStatic
protected static void addMatricesInPlaceStatic(double alpha, org.ejml.data.DMatrix A, double beta, org.ejml.data.DMatrix B, org.ejml.data.DMatrix output) -
addMatricesStatic
protected static org.ejml.data.DMatrixSparseCSC addMatricesStatic(double alpha, org.ejml.data.DMatrix A, double beta, org.ejml.data.DMatrix B, org.ejml.data.DMatrix output) -
changeSignStatic
protected static void changeSignStatic(org.ejml.data.DMatrix input, org.ejml.data.DMatrix output) -
concatColumnsInPlaceStatic
protected static void concatColumnsInPlaceStatic(org.ejml.data.DMatrix left, org.ejml.data.DMatrix right, org.ejml.data.DMatrix output) -
concatColumnsStatic
protected static org.ejml.data.DMatrixSparseCSC concatColumnsStatic(org.ejml.data.DMatrix left, org.ejml.data.DMatrix right, org.ejml.data.DMatrix output) -
concatRowsInPlaceStatic
protected static void concatRowsInPlaceStatic(org.ejml.data.DMatrix top, org.ejml.data.DMatrix bottom, org.ejml.data.DMatrix output) -
concatRowsStatic
protected static org.ejml.data.DMatrixSparseCSC concatRowsStatic(org.ejml.data.DMatrix top, org.ejml.data.DMatrix bottom, org.ejml.data.DMatrix output) -
determinantStatic
protected static double determinantStatic(org.ejml.data.DMatrix matrix) -
diagStatic
protected static org.ejml.data.DMatrixSparseCSC diagStatic(double[] values) -
diagWithMatrixStatic
protected static org.ejml.data.DMatrixSparseCSC diagWithMatrixStatic(org.ejml.data.DMatrixSparseCSC A, double[] values, int offset, int length) -
diagWithRetStatic
protected static org.ejml.data.DMatrixSparseCSC diagWithRetStatic(org.ejml.data.DMatrixSparseCSC ret, double[] values, int offset, int length) -
divideInPlaceStatic
protected static void divideInPlaceStatic(org.ejml.data.DMatrix matrix, double scalar) -
divideMatrixStatic
protected static void divideMatrixStatic(org.ejml.data.DMatrix input, double scalar, org.ejml.data.DMatrix output) -
divideRowsByArrayStatic
protected static void divideRowsByArrayStatic(double[] diag, int offset, org.ejml.data.DMatrix matrix) -
divideScalarByMatrixStatic
protected static void divideScalarByMatrixStatic(double scalar, org.ejml.data.DMatrix input, org.ejml.data.DMatrix output) -
elementMultStatic
protected static org.ejml.data.DMatrixSparseCSC elementMultStatic(org.ejml.data.DMatrix A, org.ejml.data.DMatrix B, org.ejml.data.DMatrix output) -
extractColumnInPlaceStatic
protected static void extractColumnInPlaceStatic(org.ejml.data.DMatrix input, int column, org.ejml.data.DMatrix output) -
extractColumnStatic
protected static org.ejml.data.DMatrixSparseCSC extractColumnStatic(org.ejml.data.DMatrix input, int column, org.ejml.data.DMatrix output) -
extractDiagStatic
protected static void extractDiagStatic(org.ejml.data.DMatrix input, org.ejml.data.DMatrix output) -
extractMatrixStatic
protected static void extractMatrixStatic(org.ejml.data.DMatrix src, int srcX0, int srcX1, int srcY0, int srcY1, org.ejml.data.DMatrix dst, int dstY0, int dstX0) -
extractRowsInPlaceStatic
protected static void extractRowsInPlaceStatic(org.ejml.data.DMatrix input, int row0, int row1, org.ejml.data.DMatrix output) -
extractRowsStatic
protected static org.ejml.data.DMatrixSparseCSC extractRowsStatic(org.ejml.data.DMatrix input, int row0, int row1, org.ejml.data.DMatrix output) -
fillMatrixStatic
protected static void fillMatrixStatic(org.ejml.data.DMatrix matrix, double value) -
identityStatic
protected static org.ejml.data.DMatrixSparseCSC identityStatic(int length) -
invertStatic
protected static void invertStatic(org.ejml.data.DMatrix input, org.ejml.data.DMatrixRMaj output) -
multMatrixStatic
protected static org.ejml.data.DMatrixSparseCSC multMatrixStatic(org.ejml.data.DMatrix A, org.ejml.data.DMatrix B, org.ejml.data.DMatrix output) -
removeZerosWithTolStatic
protected static void removeZerosWithTolStatic(org.ejml.data.DMatrix matrix, double tolerance) -
scaleMatrixStatic
protected static void scaleMatrixStatic(double scalar, org.ejml.data.DMatrix input, org.ejml.data.DMatrix output) -
solveStatic
protected static boolean solveStatic(org.ejml.data.DMatrix a, org.ejml.data.DMatrix b, org.ejml.data.DMatrix x) -
sumColsStatic
protected static org.ejml.data.DMatrixRMaj sumColsStatic(org.ejml.data.DMatrix matrix) -
sumRowsStatic
protected static org.ejml.data.DMatrixRMaj sumRowsStatic(org.ejml.data.DMatrix matrix) -
transposeMatrixStatic
protected static void transposeMatrixStatic(org.ejml.data.DMatrix input, org.ejml.data.DMatrix output) -
absEq
public void absEq()Replaces each value in the matrix with its absolute value, in-place.- Specified by:
absEqin classBaseMatrix
-
add
protected void add(double alpha, org.ejml.data.DMatrix A, double beta, org.ejml.data.DMatrix B, org.ejml.data.DMatrix output) Performs the operation: output = alpha*A + beta*B.- Parameters:
alpha- scalar coefficient for matrix AA- first input matrixbeta- scalar coefficient for matrix BB- second input matrixoutput- the result matrix
-
addMatrices
protected org.ejml.data.DMatrix addMatrices(double alpha, org.ejml.data.DMatrix A, double beta, org.ejml.data.DMatrix B, org.ejml.data.DMatrix output) Description copied from class:BaseMatrixPerforms the operation: output = alpha*A + beta*B.- Specified by:
addMatricesin classBaseMatrix- Parameters:
alpha- scalar coefficient for matrix AA- first input matrixbeta- scalar coefficient for matrix BB- second input matrixoutput- the result matrix
-
addMatricesInPlace
protected void addMatricesInPlace(double alpha, org.ejml.data.DMatrix A, double beta, org.ejml.data.DMatrix B, org.ejml.data.DMatrix output) -
any
public boolean any()Checks if the current matrix contains any non-zero elements.- Specified by:
anyin classBaseMatrix- Returns:
trueif at least one non-zero element exists;falseotherwise.
-
applyConditionalTransform
protected void applyConditionalTransform(double source, double target, double tol, String operation) Applies a transformation to matrix elements based on conditions. Replaces elements matching the condition with the target value.- Specified by:
applyConditionalTransformin classBaseMatrix
-
changeSign
protected void changeSign()- Specified by:
changeSignin classBaseMatrix
-
copy
Creates and returns a deep copy of this sparse matrix.- Specified by:
copyin classBaseMatrix- Returns:
- a new sparse matrix that is a copy of this instance
-
colIncrease
public void colIncrease(int col, double a) Adds a scalar value to each element in the specified column.- Specified by:
colIncreasein classBaseMatrix- Parameters:
col- Column index to update.a- Scalar value to add to each element in the column.
-
concatColumns
protected org.ejml.data.DMatrixSparseCSC concatColumns(org.ejml.data.DMatrix left, org.ejml.data.DMatrix right, org.ejml.data.DMatrix output) -
concatColumnsInPlace
protected void concatColumnsInPlace(org.ejml.data.DMatrix left, org.ejml.data.DMatrix right, org.ejml.data.DMatrix output) Description copied from class:BaseMatrixConcatenates matrices column-wise.- Specified by:
concatColumnsInPlacein classBaseMatrix- Parameters:
left- the left matrixright- the right matrixoutput- the result matrix
-
concatRows
protected org.ejml.data.DMatrixSparseCSC concatRows(org.ejml.data.DMatrix top, org.ejml.data.DMatrix bottom, org.ejml.data.DMatrix output) -
concatRowsInPlace
protected void concatRowsInPlace(org.ejml.data.DMatrix top, org.ejml.data.DMatrix bottom, org.ejml.data.DMatrix output) Description copied from class:BaseMatrixConcatenates matrices row-wise.- Specified by:
concatRowsInPlacein classBaseMatrix- Parameters:
top- the top matrixbottom- the bottom matrixoutput- the result matrix
-
countEachRow
Counts occurrences of each unique value in each row.- Specified by:
countEachRowin classBaseMatrix
-
createNewInstance
Creates a new instance of the concrete sparse matrix implementation. This factory method allows the base class to create instances of the correct subtype.- Specified by:
createNewInstancein classBaseMatrix- Parameters:
rows- the number of rows for the new matrixcols- the number of columns for the new matrixnzLength- the initial capacity for non-zero elements- Returns:
- a new instance of the concrete sparse matrix type
-
determinant
protected double determinant()- Specified by:
determinantin classBaseMatrix
-
divideInPlace
protected void divideInPlace(double scalar) - Specified by:
divideInPlacein classBaseMatrix
-
divideMatrix
protected void divideMatrix(double scalar, org.ejml.data.DMatrix output) - Specified by:
divideMatrixin classBaseMatrix
-
divideRowsByArray
protected void divideRowsByArray(double[] diag, int offset) - Specified by:
divideRowsByArrayin classBaseMatrix
-
divideScalarByMatrix
protected void divideScalarByMatrix(double scalar, org.ejml.data.DMatrix output) - Specified by:
divideScalarByMatrixin classBaseMatrix
-
elementMax
protected double elementMax()- Specified by:
elementMaxin classBaseMatrix
-
elementMaxAbs
protected double elementMaxAbs()- Specified by:
elementMaxAbsin classBaseMatrix
-
elementMin
protected double elementMin()- Specified by:
elementMinin classBaseMatrix
-
elementMult
protected org.ejml.data.DMatrix elementMult(org.ejml.data.DMatrix A, org.ejml.data.DMatrix B, org.ejml.data.DMatrix output) - Specified by:
elementMultin classBaseMatrix
-
elementSum
protected double elementSum()- Specified by:
elementSumin classBaseMatrix
-
equals
Indicates whether some other object is "equal to" this sparse matrix.- Specified by:
equalsin classBaseMatrix- Parameters:
obj- the reference object with which to compare- Returns:
trueif this object is the same as the obj argument;falseotherwise
-
extractColumn
protected org.ejml.data.DMatrixSparseCSC extractColumn(org.ejml.data.DMatrix input, int column, org.ejml.data.DMatrix output) -
extractColumnInPlace
protected void extractColumnInPlace(org.ejml.data.DMatrix input, int column, org.ejml.data.DMatrix output) -
extractDiag
protected void extractDiag(org.ejml.data.DMatrix input, org.ejml.data.DMatrix output) -
extractMatrix
protected void extractMatrix(org.ejml.data.DMatrix src, int srcX0, int srcX1, int srcY0, int srcY1, org.ejml.data.DMatrix dst, int dstY0, int dstX0) - Specified by:
extractMatrixin classBaseMatrix
-
extractRows
protected org.ejml.data.DMatrixSparseCSC extractRows(org.ejml.data.DMatrix input, int row0, int row1, org.ejml.data.DMatrix output) -
extractRowsInPlace
protected void extractRowsInPlace(org.ejml.data.DMatrix input, int row0, int row1, org.ejml.data.DMatrix output) -
fillMatrix
protected void fillMatrix(double value) Description copied from class:BaseMatrixFills the matrix with the specified value.- Specified by:
fillMatrixin classBaseMatrix- Parameters:
value- the value to fill the matrix with
-
findNonNegative
Returns a matrix containing indices of all non-negative elements.- Specified by:
findNonNegativein classBaseMatrix
-
get
public double get(int row, int col) Returns the value at the specified matrix position.- Specified by:
getin classBaseMatrix- Parameters:
row- the row indexcol- the column index- Returns:
- the value at position (row, col)
-
getColumnIndex
protected int getColumnIndex(int col) - Specified by:
getColumnIndexin classBaseMatrix
-
getColumnIndices
protected int[] getColumnIndices() -
getColumnIndicesArray
protected int[] getColumnIndicesArray()- Specified by:
getColumnIndicesArrayin classBaseMatrix
-
getData
public org.ejml.data.DMatrixSparseCSC getData()Returns the underlying EJML sparse matrix data structure. This method provides direct access to the internal data for subclasses.- Specified by:
getDatain classBaseMatrix- Returns:
- the underlying
DMatrixSparseCSCinstance
-
setData
public void setData(org.ejml.data.DMatrixSparseCSC newData) Sets the underlying EJML sparse matrix data structure. This method allows subclasses to replace the internal data.- Parameters:
newData- the newDMatrixSparseCSCinstance to use
-
setData
Sets the underlying data structure for BaseMatrix compatibility.- Specified by:
setDatain classBaseMatrix- Parameters:
newData- the new data structure (must be DMatrixSparseCSC)
-
getNonZeroLength
public int getNonZeroLength()Description copied from class:BaseMatrixReturns the number of stored non-zero elements. This may be different from actual non-zero count for dense matrices.- Specified by:
getNonZeroLengthin classBaseMatrix- Returns:
- number of stored non-zero elements
-
setNonZeroLength
protected void setNonZeroLength(int length) - Specified by:
setNonZeroLengthin classBaseMatrix
-
getNonZeroRow
protected int getNonZeroRow(int index) - Specified by:
getNonZeroRowin classBaseMatrix
-
getNonZeroRows
public int[] getNonZeroRows()Description copied from class:BaseMatrixReturns array of row indices of non-zero entries. For dense matrices, this may compute row indices dynamically. For sparse matrices, this returns the compressed row index array.- Specified by:
getNonZeroRowsin classBaseMatrix- Returns:
- array of row indices
-
getNonZeroValue
protected double getNonZeroValue(int index) - Specified by:
getNonZeroValuein classBaseMatrix
-
getNonZeroValues
public double[] getNonZeroValues()Description copied from class:BaseMatrixReturns array of non-zero values. For dense matrices, this may return all values or only actual non-zeros. For sparse matrices, this returns the compressed storage array.- Specified by:
getNonZeroValuesin classBaseMatrix- Returns:
- array of non-zero values
-
getNonZeros
public int getNonZeros()Returns the number of non-zero elements in the matrix.- Specified by:
getNonZerosin classBaseMatrix- Returns:
- the number of non-zero elements
-
getNumCols
public int getNumCols()Returns the number of columns in the matrix.- Specified by:
getNumColsin classBaseMatrix- Returns:
- the number of columns
-
getNumColsInternal
protected int getNumColsInternal() -
getNumNonZeros
public int getNumNonZeros()Returns the number of non-zero elements in the matrix. This is an alias forgetNonZeros().- Overrides:
getNumNonZerosin classBaseMatrix- Returns:
- the number of non-zero elements
-
getNumRows
public int getNumRows()Returns the number of rows in the matrix.- Specified by:
getNumRowsin classBaseMatrix- Returns:
- the number of rows
-
getNumRowsInternal
protected int getNumRowsInternal() -
hasDuplicates
public boolean hasDuplicates()Checks if the matrix contains duplicate values.- Specified by:
hasDuplicatesin classBaseMatrix- Returns:
- true if duplicates exist
-
hasFinite
public boolean hasFinite()Checks if the matrix contains any finite (non-infinite, non-NaN) values.- Specified by:
hasFinitein classBaseMatrix- Returns:
- true if at least one finite value exists
-
hasInfinite
public boolean hasInfinite()Checks if the matrix contains any infinite values.- Specified by:
hasInfinitein classBaseMatrix- Returns:
- true if at least one infinite value exists
-
hasMultipleFinite
public boolean hasMultipleFinite()Checks if more than one finite value exists.- Specified by:
hasMultipleFinitein classBaseMatrix- Returns:
- true if more than one finite value exists
-
hasNaN
public boolean hasNaN()Checks if the matrix contains any NaN values.- Specified by:
hasNaNin classBaseMatrix- Returns:
- true if at least one NaN exists
-
mult
protected void mult(org.ejml.data.DMatrix A, org.ejml.data.DMatrix B, org.ejml.data.DMatrix output) Performs matrix multiplication: output = A * B.- Parameters:
A- the left matrixB- the right matrixoutput- the result matrix
-
multMatrix
protected org.ejml.data.DMatrix multMatrix(org.ejml.data.DMatrix B, org.ejml.data.DMatrix output) Description copied from class:BaseMatrixPerforms matrix multiplication with sparse matrices.- Specified by:
multMatrixin classBaseMatrix- Parameters:
B- the right matrixoutput- the result matrix
-
removeZeros
protected void removeZeros()Removes zero-valued elements from the sparse matrix with default tolerance.- Specified by:
removeZerosin classBaseMatrix
-
removeZerosWithTol
protected void removeZerosWithTol(double tolerance) Description copied from class:BaseMatrixRemoves zero-valued elements from the matrix with specified tolerance.- Specified by:
removeZerosWithTolin classBaseMatrix- Parameters:
tolerance- the tolerance for considering values as zero
-
reshape
public void reshape(int numRows, int numCols) Reshapes the matrix to the specified dimensions.- Specified by:
reshapein classBaseMatrix- Parameters:
numRows- the new number of rowsnumCols- the new number of columns
-
scaleInPlace
protected void scaleInPlace(double alpha) Scales the matrix in-place by the specified factor.- Specified by:
scaleInPlacein classBaseMatrix- Parameters:
alpha- the scaling factor
-
scaleMatrix
protected void scaleMatrix(double scalar, org.ejml.data.DMatrix output) - Specified by:
scaleMatrixin classBaseMatrix
-
set
public void set(int row, int col, double value) Sets the value at the specified matrix position.- Specified by:
setin classBaseMatrix- Parameters:
row- the row indexcol- the column indexvalue- the value to set
-
setColumnIndex
protected void setColumnIndex(int col, int value) - Specified by:
setColumnIndexin classBaseMatrix
-
setNonZeroRow
protected void setNonZeroRow(int index, int row) - Specified by:
setNonZeroRowin classBaseMatrix
-
setNonZeroValue
protected void setNonZeroValue(int index, double value) - Specified by:
setNonZeroValuein classBaseMatrix
-
shrinkNumCols
public void shrinkNumCols(int newmax) Reduce the maximum number of columns by setting the internal column count.- Specified by:
shrinkNumColsin classBaseMatrix- Parameters:
newmax- the new maximum number of columns
-
shrinkNumRows
public void shrinkNumRows(int newmax) Reduce the maximum number of rows by setting the internal row count.- Specified by:
shrinkNumRowsin classBaseMatrix- Parameters:
newmax- the new maximum number of rows
-
sumColsRaw
protected org.ejml.data.DMatrix sumColsRaw()- Specified by:
sumColsRawin classBaseMatrix
-
sumRowsRaw
protected org.ejml.data.DMatrix sumRowsRaw()- Specified by:
sumRowsRawin classBaseMatrix
-
toString
Returns a string representation of the matrix. Elements are formatted to 4 decimal places in a grid layout.- Overrides:
toStringin classBaseMatrix- Returns:
- a formatted string representation of the matrix
-
transpose
protected void transpose(org.ejml.data.DMatrix input, org.ejml.data.DMatrix output) Computes the transpose of the input matrix.- Parameters:
input- the matrix to transposeoutput- the transposed matrix
-
transposeMatrix
protected void transposeMatrix(org.ejml.data.DMatrix output) Description copied from class:BaseMatrixComputes the transpose of this matrix.- Specified by:
transposeMatrixin classBaseMatrix- Parameters:
output- the transposed matrix
-
zero
public void zero()Sets all elements in the matrix to zero.- Specified by:
zeroin classBaseMatrix
-