Class SparseMatrix

java.lang.Object
jline.util.matrix.BaseMatrix
jline.util.matrix.SparseMatrix
All Implemented Interfaces:
Serializable

public abstract class SparseMatrix extends BaseMatrix
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

    Constructors
    Modifier
    Constructor
    Description
    protected
    Protected 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.
    protected
    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 Type
    Method
    Description
    void
    Replaces each value in the matrix with its absolute value, in-place.
    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.
    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)
    Performs the operation: output = alpha*A + beta*B.
    protected void
    addMatricesInPlace(double alpha, org.ejml.data.DMatrix A, double beta, org.ejml.data.DMatrix B, org.ejml.data.DMatrix output)
     
    protected static void
    addMatricesInPlaceStatic(double alpha, org.ejml.data.DMatrix A, double beta, org.ejml.data.DMatrix B, org.ejml.data.DMatrix output)
     
    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)
     
    boolean
    any()
    Checks if the current matrix contains any non-zero elements.
    protected void
    applyConditionalTransform(double source, double target, double tol, String operation)
    Applies a transformation to matrix elements based on conditions.
    protected void
     
    protected static void
    changeSignStatic(org.ejml.data.DMatrix input, org.ejml.data.DMatrix output)
     
    void
    colIncrease(int col, double a)
    Adds a scalar value to each element in the specified column.
    protected org.ejml.data.DMatrixSparseCSC
    concatColumns(org.ejml.data.DMatrix left, org.ejml.data.DMatrix right, org.ejml.data.DMatrix output)
     
    protected void
    concatColumnsInPlace(org.ejml.data.DMatrix left, org.ejml.data.DMatrix right, org.ejml.data.DMatrix output)
    Concatenates matrices column-wise.
    protected static void
    concatColumnsInPlaceStatic(org.ejml.data.DMatrix left, org.ejml.data.DMatrix right, org.ejml.data.DMatrix output)
     
    protected static org.ejml.data.DMatrixSparseCSC
    concatColumnsStatic(org.ejml.data.DMatrix left, org.ejml.data.DMatrix right, org.ejml.data.DMatrix output)
     
    protected org.ejml.data.DMatrixSparseCSC
    concatRows(org.ejml.data.DMatrix top, org.ejml.data.DMatrix bottom, org.ejml.data.DMatrix output)
     
    protected void
    concatRowsInPlace(org.ejml.data.DMatrix top, org.ejml.data.DMatrix bottom, org.ejml.data.DMatrix output)
    Concatenates matrices row-wise.
    protected static void
    concatRowsInPlaceStatic(org.ejml.data.DMatrix top, org.ejml.data.DMatrix bottom, org.ejml.data.DMatrix output)
     
    protected static org.ejml.data.DMatrixSparseCSC
    concatRowsStatic(org.ejml.data.DMatrix top, org.ejml.data.DMatrix bottom, org.ejml.data.DMatrix output)
     
    abstract BaseMatrix
    Creates and returns a deep copy of this sparse matrix.
    countEachRow(double val)
    Counts occurrences of each unique value in each row.
    protected abstract BaseMatrix
    createNewInstance(int rows, int cols, int nzLength)
    Creates a new instance of the concrete sparse matrix implementation.
    protected double
     
    protected static double
    determinantStatic(org.ejml.data.DMatrix matrix)
     
    protected static org.ejml.data.DMatrixSparseCSC
    diagStatic(double[] values)
     
    protected static org.ejml.data.DMatrixSparseCSC
    diagWithMatrixStatic(org.ejml.data.DMatrixSparseCSC A, double[] values, int offset, int length)
     
    protected static org.ejml.data.DMatrixSparseCSC
    diagWithRetStatic(org.ejml.data.DMatrixSparseCSC ret, double[] values, int offset, int length)
     
    protected void
    divideInPlace(double scalar)
     
    protected static void
    divideInPlaceStatic(org.ejml.data.DMatrix matrix, double scalar)
     
    protected void
    divideMatrix(double scalar, org.ejml.data.DMatrix output)
     
    protected static void
    divideMatrixStatic(org.ejml.data.DMatrix input, double scalar, org.ejml.data.DMatrix output)
     
    protected void
    divideRowsByArray(double[] diag, int offset)
     
    protected static void
    divideRowsByArrayStatic(double[] diag, int offset, org.ejml.data.DMatrix matrix)
     
    protected void
    divideScalarByMatrix(double scalar, org.ejml.data.DMatrix output)
     
    protected static void
    divideScalarByMatrixStatic(double scalar, org.ejml.data.DMatrix input, org.ejml.data.DMatrix output)
     
    protected double
     
    protected double
     
    protected double
     
    protected org.ejml.data.DMatrix
    elementMult(org.ejml.data.DMatrix A, org.ejml.data.DMatrix B, org.ejml.data.DMatrix output)
     
    protected static org.ejml.data.DMatrixSparseCSC
    elementMultStatic(org.ejml.data.DMatrix A, org.ejml.data.DMatrix B, org.ejml.data.DMatrix output)
     
    protected double
     
    abstract boolean
    Indicates whether some other object is "equal to" this sparse matrix.
    protected org.ejml.data.DMatrixSparseCSC
    extractColumn(org.ejml.data.DMatrix input, int column, org.ejml.data.DMatrix output)
     
    protected void
    extractColumnInPlace(org.ejml.data.DMatrix input, int column, org.ejml.data.DMatrix output)
     
    protected static void
    extractColumnInPlaceStatic(org.ejml.data.DMatrix input, int column, org.ejml.data.DMatrix output)
     
    protected static org.ejml.data.DMatrixSparseCSC
    extractColumnStatic(org.ejml.data.DMatrix input, int column, org.ejml.data.DMatrix output)
     
    protected void
    extractDiag(org.ejml.data.DMatrix input, org.ejml.data.DMatrix output)
     
    protected static void
    extractDiagStatic(org.ejml.data.DMatrix input, org.ejml.data.DMatrix output)
     
    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)
     
    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)
     
    protected org.ejml.data.DMatrixSparseCSC
    extractRows(org.ejml.data.DMatrix input, int row0, int row1, org.ejml.data.DMatrix output)
     
    protected void
    extractRowsInPlace(org.ejml.data.DMatrix input, int row0, int row1, org.ejml.data.DMatrix output)
     
    protected static void
    extractRowsInPlaceStatic(org.ejml.data.DMatrix input, int row0, int row1, org.ejml.data.DMatrix output)
     
    protected static org.ejml.data.DMatrixSparseCSC
    extractRowsStatic(org.ejml.data.DMatrix input, int row0, int row1, org.ejml.data.DMatrix output)
     
    protected void
    fillMatrix(double value)
    Fills the matrix with the specified value.
    protected static void
    fillMatrixStatic(org.ejml.data.DMatrix matrix, double value)
     
    Returns a matrix containing indices of all non-negative elements.
    double
    get(int row, int col)
    Returns the value at the specified matrix position.
    protected int
    getColumnIndex(int col)
     
    protected int[]
     
    protected int[]
     
    org.ejml.data.DMatrixSparseCSC
    Returns the underlying EJML sparse matrix data structure.
    int
    Returns the number of stored non-zero elements.
    protected int
    getNonZeroRow(int index)
     
    int[]
    Returns array of row indices of non-zero entries.
    int
    Returns the number of non-zero elements in the matrix.
    protected double
    getNonZeroValue(int index)
     
    double[]
    Returns array of non-zero values.
    int
    Returns the number of columns in the matrix.
    protected int
     
    int
    Returns the number of non-zero elements in the matrix.
    int
    Returns the number of rows in the matrix.
    protected int
     
    boolean
    Checks if the matrix contains duplicate values.
    boolean
    Checks if the matrix contains any finite (non-infinite, non-NaN) values.
    boolean
    Checks if the matrix contains any infinite values.
    boolean
    Checks if more than one finite value exists.
    boolean
    Checks if the matrix contains any NaN values.
    protected static org.ejml.data.DMatrixSparseCSC
    identityStatic(int length)
     
    protected static void
    invertStatic(org.ejml.data.DMatrix input, org.ejml.data.DMatrixRMaj output)
     
    protected void
    mult(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.DMatrix
    multMatrix(org.ejml.data.DMatrix B, org.ejml.data.DMatrix output)
    Performs matrix multiplication with sparse matrices.
    protected static org.ejml.data.DMatrixSparseCSC
    multMatrixStatic(org.ejml.data.DMatrix A, org.ejml.data.DMatrix B, org.ejml.data.DMatrix output)
     
    protected void
    Removes zero-valued elements from the sparse matrix with default tolerance.
    protected void
    removeZerosWithTol(double tolerance)
    Removes zero-valued elements from the matrix with specified tolerance.
    protected static void
    removeZerosWithTolStatic(org.ejml.data.DMatrix matrix, double tolerance)
     
    void
    reshape(int numRows, int numCols)
    Reshapes the matrix to the specified dimensions.
    protected void
    scaleInPlace(double alpha)
    Scales the matrix in-place by the specified factor.
    protected void
    scaleMatrix(double scalar, org.ejml.data.DMatrix output)
     
    protected static void
    scaleMatrixStatic(double scalar, org.ejml.data.DMatrix input, org.ejml.data.DMatrix output)
     
    void
    set(int row, int col, double value)
    Sets the value at the specified matrix position.
    protected void
    setColumnIndex(int col, int value)
     
    protected void
    setData(Object newData)
    Sets the underlying data structure for BaseMatrix compatibility.
    void
    setData(org.ejml.data.DMatrixSparseCSC newData)
    Sets the underlying EJML sparse matrix data structure.
    protected void
    setNonZeroLength(int length)
     
    protected void
    setNonZeroRow(int index, int row)
     
    protected void
    setNonZeroValue(int index, double value)
     
    void
    shrinkNumCols(int newmax)
    Reduce the maximum number of columns by setting the internal column count.
    void
    shrinkNumRows(int newmax)
    Reduce the maximum number of rows by setting the internal row count.
    protected static boolean
    solveStatic(org.ejml.data.DMatrix a, org.ejml.data.DMatrix b, org.ejml.data.DMatrix x)
     
    protected org.ejml.data.DMatrix
     
    protected static org.ejml.data.DMatrixRMaj
    sumColsStatic(org.ejml.data.DMatrix matrix)
     
    protected org.ejml.data.DMatrix
     
    protected static org.ejml.data.DMatrixRMaj
    sumRowsStatic(org.ejml.data.DMatrix matrix)
     
    Returns a string representation of the matrix.
    protected void
    transpose(org.ejml.data.DMatrix input, org.ejml.data.DMatrix output)
    Computes the transpose of the input matrix.
    protected void
    transposeMatrix(org.ejml.data.DMatrix output)
    Computes the transpose of this matrix.
    protected static void
    transposeMatrixStatic(org.ejml.data.DMatrix input, org.ejml.data.DMatrix output)
     
    void
    Sets all elements in the matrix to zero.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • 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 matrix
      numCols - the number of columns in the matrix
      arrayLength - 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 matrix
      numCols - 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

      protected SparseMatrix(SparseMatrix matrix)
      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:
      absEq in class BaseMatrix
    • 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 A
      A - first input matrix
      beta - scalar coefficient for matrix B
      B - second input matrix
      output - 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: BaseMatrix
      Performs the operation: output = alpha*A + beta*B.
      Specified by:
      addMatrices in class BaseMatrix
      Parameters:
      alpha - scalar coefficient for matrix A
      A - first input matrix
      beta - scalar coefficient for matrix B
      B - second input matrix
      output - 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:
      any in class BaseMatrix
      Returns:
      true if at least one non-zero element exists; false otherwise.
    • 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:
      applyConditionalTransform in class BaseMatrix
    • changeSign

      protected void changeSign()
      Specified by:
      changeSign in class BaseMatrix
    • copy

      public abstract BaseMatrix copy()
      Creates and returns a deep copy of this sparse matrix.
      Specified by:
      copy in class BaseMatrix
      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:
      colIncrease in class BaseMatrix
      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: BaseMatrix
      Concatenates matrices column-wise.
      Specified by:
      concatColumnsInPlace in class BaseMatrix
      Parameters:
      left - the left matrix
      right - the right matrix
      output - 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: BaseMatrix
      Concatenates matrices row-wise.
      Specified by:
      concatRowsInPlace in class BaseMatrix
      Parameters:
      top - the top matrix
      bottom - the bottom matrix
      output - the result matrix
    • countEachRow

      public BaseMatrix countEachRow(double val)
      Counts occurrences of each unique value in each row.
      Specified by:
      countEachRow in class BaseMatrix
    • createNewInstance

      protected abstract BaseMatrix createNewInstance(int rows, int cols, int nzLength)
      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:
      createNewInstance in class BaseMatrix
      Parameters:
      rows - the number of rows for the new matrix
      cols - the number of columns for the new matrix
      nzLength - the initial capacity for non-zero elements
      Returns:
      a new instance of the concrete sparse matrix type
    • determinant

      protected double determinant()
      Specified by:
      determinant in class BaseMatrix
    • divideInPlace

      protected void divideInPlace(double scalar)
      Specified by:
      divideInPlace in class BaseMatrix
    • divideMatrix

      protected void divideMatrix(double scalar, org.ejml.data.DMatrix output)
      Specified by:
      divideMatrix in class BaseMatrix
    • divideRowsByArray

      protected void divideRowsByArray(double[] diag, int offset)
      Specified by:
      divideRowsByArray in class BaseMatrix
    • divideScalarByMatrix

      protected void divideScalarByMatrix(double scalar, org.ejml.data.DMatrix output)
      Specified by:
      divideScalarByMatrix in class BaseMatrix
    • elementMax

      protected double elementMax()
      Specified by:
      elementMax in class BaseMatrix
    • elementMaxAbs

      protected double elementMaxAbs()
      Specified by:
      elementMaxAbs in class BaseMatrix
    • elementMin

      protected double elementMin()
      Specified by:
      elementMin in class BaseMatrix
    • elementMult

      protected org.ejml.data.DMatrix elementMult(org.ejml.data.DMatrix A, org.ejml.data.DMatrix B, org.ejml.data.DMatrix output)
      Specified by:
      elementMult in class BaseMatrix
    • elementSum

      protected double elementSum()
      Specified by:
      elementSum in class BaseMatrix
    • equals

      public abstract boolean equals(Object obj)
      Indicates whether some other object is "equal to" this sparse matrix.
      Specified by:
      equals in class BaseMatrix
      Parameters:
      obj - the reference object with which to compare
      Returns:
      true if this object is the same as the obj argument; false otherwise
    • 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:
      extractMatrix in class BaseMatrix
    • 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: BaseMatrix
      Fills the matrix with the specified value.
      Specified by:
      fillMatrix in class BaseMatrix
      Parameters:
      value - the value to fill the matrix with
    • findNonNegative

      public BaseMatrix findNonNegative()
      Returns a matrix containing indices of all non-negative elements.
      Specified by:
      findNonNegative in class BaseMatrix
    • get

      public double get(int row, int col)
      Returns the value at the specified matrix position.
      Specified by:
      get in class BaseMatrix
      Parameters:
      row - the row index
      col - the column index
      Returns:
      the value at position (row, col)
    • getColumnIndex

      protected int getColumnIndex(int col)
      Specified by:
      getColumnIndex in class BaseMatrix
    • getColumnIndices

      protected int[] getColumnIndices()
    • getColumnIndicesArray

      protected int[] getColumnIndicesArray()
      Specified by:
      getColumnIndicesArray in class BaseMatrix
    • 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:
      getData in class BaseMatrix
      Returns:
      the underlying DMatrixSparseCSC instance
    • 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 new DMatrixSparseCSC instance to use
    • setData

      protected void setData(Object newData)
      Sets the underlying data structure for BaseMatrix compatibility.
      Specified by:
      setData in class BaseMatrix
      Parameters:
      newData - the new data structure (must be DMatrixSparseCSC)
    • getNonZeroLength

      public int getNonZeroLength()
      Description copied from class: BaseMatrix
      Returns the number of stored non-zero elements. This may be different from actual non-zero count for dense matrices.
      Specified by:
      getNonZeroLength in class BaseMatrix
      Returns:
      number of stored non-zero elements
    • setNonZeroLength

      protected void setNonZeroLength(int length)
      Specified by:
      setNonZeroLength in class BaseMatrix
    • getNonZeroRow

      protected int getNonZeroRow(int index)
      Specified by:
      getNonZeroRow in class BaseMatrix
    • getNonZeroRows

      public int[] getNonZeroRows()
      Description copied from class: BaseMatrix
      Returns 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:
      getNonZeroRows in class BaseMatrix
      Returns:
      array of row indices
    • getNonZeroValue

      protected double getNonZeroValue(int index)
      Specified by:
      getNonZeroValue in class BaseMatrix
    • getNonZeroValues

      public double[] getNonZeroValues()
      Description copied from class: BaseMatrix
      Returns 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:
      getNonZeroValues in class BaseMatrix
      Returns:
      array of non-zero values
    • getNonZeros

      public int getNonZeros()
      Returns the number of non-zero elements in the matrix.
      Specified by:
      getNonZeros in class BaseMatrix
      Returns:
      the number of non-zero elements
    • getNumCols

      public int getNumCols()
      Returns the number of columns in the matrix.
      Specified by:
      getNumCols in class BaseMatrix
      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 for getNonZeros().
      Overrides:
      getNumNonZeros in class BaseMatrix
      Returns:
      the number of non-zero elements
    • getNumRows

      public int getNumRows()
      Returns the number of rows in the matrix.
      Specified by:
      getNumRows in class BaseMatrix
      Returns:
      the number of rows
    • getNumRowsInternal

      protected int getNumRowsInternal()
    • hasDuplicates

      public boolean hasDuplicates()
      Checks if the matrix contains duplicate values.
      Specified by:
      hasDuplicates in class BaseMatrix
      Returns:
      true if duplicates exist
    • hasFinite

      public boolean hasFinite()
      Checks if the matrix contains any finite (non-infinite, non-NaN) values.
      Specified by:
      hasFinite in class BaseMatrix
      Returns:
      true if at least one finite value exists
    • hasInfinite

      public boolean hasInfinite()
      Checks if the matrix contains any infinite values.
      Specified by:
      hasInfinite in class BaseMatrix
      Returns:
      true if at least one infinite value exists
    • hasMultipleFinite

      public boolean hasMultipleFinite()
      Checks if more than one finite value exists.
      Specified by:
      hasMultipleFinite in class BaseMatrix
      Returns:
      true if more than one finite value exists
    • hasNaN

      public boolean hasNaN()
      Checks if the matrix contains any NaN values.
      Specified by:
      hasNaN in class BaseMatrix
      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 matrix
      B - the right matrix
      output - the result matrix
    • multMatrix

      protected org.ejml.data.DMatrix multMatrix(org.ejml.data.DMatrix B, org.ejml.data.DMatrix output)
      Description copied from class: BaseMatrix
      Performs matrix multiplication with sparse matrices.
      Specified by:
      multMatrix in class BaseMatrix
      Parameters:
      B - the right matrix
      output - the result matrix
    • removeZeros

      protected void removeZeros()
      Removes zero-valued elements from the sparse matrix with default tolerance.
      Specified by:
      removeZeros in class BaseMatrix
    • removeZerosWithTol

      protected void removeZerosWithTol(double tolerance)
      Description copied from class: BaseMatrix
      Removes zero-valued elements from the matrix with specified tolerance.
      Specified by:
      removeZerosWithTol in class BaseMatrix
      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:
      reshape in class BaseMatrix
      Parameters:
      numRows - the new number of rows
      numCols - the new number of columns
    • scaleInPlace

      protected void scaleInPlace(double alpha)
      Scales the matrix in-place by the specified factor.
      Specified by:
      scaleInPlace in class BaseMatrix
      Parameters:
      alpha - the scaling factor
    • scaleMatrix

      protected void scaleMatrix(double scalar, org.ejml.data.DMatrix output)
      Specified by:
      scaleMatrix in class BaseMatrix
    • set

      public void set(int row, int col, double value)
      Sets the value at the specified matrix position.
      Specified by:
      set in class BaseMatrix
      Parameters:
      row - the row index
      col - the column index
      value - the value to set
    • setColumnIndex

      protected void setColumnIndex(int col, int value)
      Specified by:
      setColumnIndex in class BaseMatrix
    • setNonZeroRow

      protected void setNonZeroRow(int index, int row)
      Specified by:
      setNonZeroRow in class BaseMatrix
    • setNonZeroValue

      protected void setNonZeroValue(int index, double value)
      Specified by:
      setNonZeroValue in class BaseMatrix
    • shrinkNumCols

      public void shrinkNumCols(int newmax)
      Reduce the maximum number of columns by setting the internal column count.
      Specified by:
      shrinkNumCols in class BaseMatrix
      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:
      shrinkNumRows in class BaseMatrix
      Parameters:
      newmax - the new maximum number of rows
    • sumColsRaw

      protected org.ejml.data.DMatrix sumColsRaw()
      Specified by:
      sumColsRaw in class BaseMatrix
    • sumRowsRaw

      protected org.ejml.data.DMatrix sumRowsRaw()
      Specified by:
      sumRowsRaw in class BaseMatrix
    • toString

      public String toString()
      Returns a string representation of the matrix. Elements are formatted to 4 decimal places in a grid layout.
      Overrides:
      toString in class BaseMatrix
      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 transpose
      output - the transposed matrix
    • transposeMatrix

      protected void transposeMatrix(org.ejml.data.DMatrix output)
      Description copied from class: BaseMatrix
      Computes the transpose of this matrix.
      Specified by:
      transposeMatrix in class BaseMatrix
      Parameters:
      output - the transposed matrix
    • zero

      public void zero()
      Sets all elements in the matrix to zero.
      Specified by:
      zero in class BaseMatrix