Class RealCooMatrixGetSet

java.lang.Object
org.flag4j.linalg.ops.sparse.coo.real.RealCooMatrixGetSet

public final class RealCooMatrixGetSet extends Object
This class provides methods for getting and setting elements and slices from/to a real sparse matrix.
  • Method Details

    • matrixGet

      public static double matrixGet(CooMatrix src, int row, int col)
      Gets the specified element from a sparse matrix.
      Parameters:
      src - Source matrix to get value from.
      row - Row index of the value to get from the sparse matrix.
      col - Column index of the value to get from the sparse matrix.
      Returns:
      The value in the sparse matrix at the specified indices.
    • matrixSet

      public static CooMatrix matrixSet(CooMatrix src, int row, int col, double value)
      Sets the specified element from a sparse matrix.
      Parameters:
      src - Sparse matrix to set value in.
      row - Row index of the value to set in the sparse matrix.
      col - Column index of the value to set in the sparse matrix.
      value - Value to set.
      Returns:
      The
    • setRow

      public static CooMatrix setRow(CooMatrix src, int rowIdx, CooVector row)
      Sets a specified row of a real sparse COO matrix to the values in a sparse COO vector.
      Parameters:
      src - Sparse COO matrix to set row in.
      rowIdx - Index of the row to set.
      row - Sparse COO vector containing new data for the row.
      Returns:
      A new COO matrix resulting from setting row rowIdx in src to row.
      Throws:
      IllegalArgumentException - If row.length != src.numCols.
    • setRow

      public static CooMatrix setRow(CooMatrix src, int rowIdx, double[] row)
      Sets a specified row of a real sparse matrix to the values of a dense array.
      Parameters:
      src - Source matrix to set the row of.
      rowIdx - Index of the row to set.
      row - Dense array containing the data of the row to set.
      Returns:
      A copy of the src matrix with the specified row set to the dense row array.
    • setCol

      public static CooMatrix setCol(CooMatrix src, int colIdx, double[] col)
      Sets a column of a sparse matrix to the data of a dense array.
      Parameters:
      src - Source matrix to set column of.
      colIdx - The index of the column to set within the src matrix.
      col - The dense array containing the new column data for the src array.
      Returns:
      A copy of the src matrix with the specified column set to the dense array.
      Throws:
      IllegalArgumentException - If the colIdx is not within the range of the matrix.
      IllegalArgumentException - If the col array does not have the same length as the number of rows in src matrix.
    • setCol

      public static CooMatrix setCol(CooMatrix src, int colIdx, CooVector col)
      Sets a column of a sparse matrix to the values in a sparse tensor.
      Parameters:
      src - Source matrix to set column of.
      colIdx - Index of the column to set.
      col - New data for the specified column.
      Returns:
      A copy of the src matrix with the specified column set to the col sparse vector.
      Throws:
      IllegalArgumentException - If the src matrix does not have the same number of rows as total data in the col vector.
    • setSlice

      public static CooMatrix setSlice(CooMatrix src, CooMatrix values, int row, int col)
      Copies a sparse matrix and sets a slice of the sparse matrix to the data of another sparse matrix.
      Parameters:
      src - Source sparse matrix to copy and set values of.
      values - Values of the slice to be set.
      row - Starting row index of slice.
      col - Starting column index of slice.
      Returns:
      A copy of the src matrix with the specified slice set to the values matrix.
      Throws:
      IllegalArgumentException - If the values matrix does not fit in the src matrix given the row and column index.
    • setSlice

      public static CooMatrix setSlice(CooMatrix src, double[][] values, int row, int col)
      Copies a sparse matrix and sets a slice of the sparse matrix to the data of a dense array.
      Parameters:
      src - Source sparse matrix to copy and set values of.
      values - Dense values of the slice to be set.
      row - Starting row index of slice.
      col - Starting column index of slice.
      Returns:
      A copy of the src matrix with the specified slice set to the values array.
      Throws:
      IllegalArgumentException - If the values array does not fit in the src matrix given the row and column index.
    • setSlice

      public static CooMatrix setSlice(CooMatrix src, Matrix values, int row, int col)
      Copies a sparse matrix and sets a slice of the sparse matrix to the data of a dense matrix.
      Parameters:
      src - Source sparse matrix to copy and set values of.
      values - Dense matrix containing values of the slice to be set.
      row - Starting row index of slice.
      col - Starting column index of slice.
      Returns:
      A copy of the src matrix with the specified slice set to the values array.
      Throws:
      IllegalArgumentException - If the values array does not fit in the src matrix given the row and column index.
    • setSlice

      public static CooMatrix setSlice(CooMatrix src, int[][] values, int row, int col)
      Copies a sparse matrix and sets a slice of the sparse matrix to the data of a dense array.
      Parameters:
      src - Source sparse matrix to copy and set values of.
      values - Dense values of the slice to be set.
      row - Starting row index of slice.
      col - Starting column index of slice.
      Returns:
      A copy of the src matrix with the specified slice set to the values array.
      Throws:
      IllegalArgumentException - If the values array does not fit in the src matrix given the row and column index.
    • getRow

      public static CooVector getRow(CooMatrix src, int rowIdx)
      Gets a specified row from this sparse matrix.
      Parameters:
      src - Source sparse matrix to extract row from.
      rowIdx - Index of the row to extract from the src matrix.
      Returns:
      Returns the specified row from this sparse matrix.
    • getRow

      public static CooVector getRow(CooMatrix src, int rowIdx, int start, int end)
      Gets a specified row range from this sparse matrix.
      Parameters:
      src - Source sparse matrix to extract row from.
      rowIdx - Index of the row to extract from the src matrix.
      start - Staring column index of the column to be extracted (inclusive).
      end - Ending column index of the column to be extracted (exclusive)
      Returns:
      Returns the specified column range from this sparse matrix.
    • getCol

      public static CooVector getCol(CooMatrix src, int colIdx)
      Gets a specified column from this sparse matrix.
      Parameters:
      src - Source sparse matrix to extract column from.
      colIdx - Index of the column to extract from the src matrix.
      Returns:
      Returns the specified column from this sparse matrix.
    • getCol

      public static CooVector getCol(CooMatrix src, int colIdx, int start, int end)
      Gets a specified column range from this sparse matrix.
      Parameters:
      src - Source sparse matrix to extract column from.
      colIdx - Index of the column to extract from the src matrix.
      start - Staring row index of the column to be extracted (inclusive).
      end - Ending row index of the column to be extracted (exclusive)
      Returns:
      Returns the specified column range from this sparse matrix.
    • getSlice

      public static CooMatrix getSlice(CooMatrix src, int rowStart, int rowEnd, int colStart, int colEnd)
      Gets a specified rectangular slice of a sparse matrix.
      Parameters:
      src - Sparse matrix to extract slice from.
      rowStart - Starting row index of the slice (inclusive).
      rowEnd - Ending row index of the slice (exclusive).
      colStart - Staring column index of a slice (inclusive).
      colEnd - Ending column index of the slice (exclusive).
      Returns:
      The specified slice of the sparse matrix.