Class RealDenseSparseMatrixOps

java.lang.Object
org.flag4j.linalg.ops.dense_sparse.coo.real.RealDenseSparseMatrixOps

public class RealDenseSparseMatrixOps extends Object
This class contains low-level ops between a real dense and real sparse matrix.
  • Method Details

    • add

      public static Matrix add(Matrix src1, CooMatrix src2)
      Adds a real dense matrix to a real sparse matrix.
      Parameters:
      src1 - First matrix in sum.
      src2 - Second matrix in sum.
      Returns:
      The result of the matrix addition.
      Throws:
      IllegalArgumentException - If the matrices do not have the same shape.
    • sub

      public static Matrix sub(Matrix src1, CooMatrix src2)
      Subtracts a real sparse matrix from a real dense matrix.
      Parameters:
      src1 - First matrix in difference.
      src2 - Second matrix in difference.
      Returns:
      The result of the matrix subtraction.
      Throws:
      IllegalArgumentException - If the matrices do not have the same shape.
    • sub

      public static Matrix sub(CooMatrix src2, Matrix src1)
      Subtracts a real dense matrix from a real sparse matrix.
      Parameters:
      src2 - Entries of second matrix in the difference.
      src1 - Entries of first matrix in difference.
      Returns:
      The result of the matrix subtraction.
      Throws:
      IllegalArgumentException - If the matrices do not have the same shape.
    • addEq

      public static void addEq(Matrix src1, CooMatrix src2)
      Adds a real dense matrix to a real sparse matrix and stores the result in the first matrix.
      Parameters:
      src1 - Entries of first matrix in the sum. Also, storage for the result.
      src2 - Entries of second matrix in the sum.
      Throws:
      IllegalArgumentException - If the matrices do not have the same shape.
    • subEq

      public static void subEq(Matrix src1, CooMatrix src2)
      Subtracts a real sparse matrix from a real dense matrix and stores the result in the first matrix.
      Parameters:
      src1 - Entries of first matrix in difference.
      src2 - Entries of second matrix in difference.
      Throws:
      IllegalArgumentException - If the matrices do not have the same shape.
    • elemMult

      public static CooMatrix elemMult(Matrix src1, CooMatrix src2)
      Computes the element-wise multiplication between a real dense matrix and a real sparse matrix.
      Parameters:
      src1 - Entries of first matrix in element-wise product.
      src2 - Entries of second matrix in element-wise product.
      Returns:
      The result of element-wise multiplication.
      Throws:
      IllegalArgumentException - If the matrices do not have the same shape.
    • elemDiv

      public static CooMatrix elemDiv(CooMatrix src1, Matrix src2)
      Computes the element-wise division between a real sparse matrix and a real dense matrix.

      If the dense matrix contains a zero at the same index the sparse matrix contains a non-zero, the result will be either Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY.

      If the dense matrix contains a zero at an index for which the sparse matrix is also zero, the result will be zero. This is done to realize computational benefits from ops with sparse matrices.

      Parameters:
      src1 - Real sparse matrix and numerator in element-wise quotient.
      src2 - Real Dense matrix and denominator in element-wise quotient.
      Returns:
      The element-wise quotient of src1 and src2.
      Throws:
      IllegalArgumentException - If src1 and src2 do not have the same shape.
    • addToEachCol

      public static Matrix addToEachCol(CooMatrix src, Vector col)
      Adds a dense vector to each column as if the vector is a column vector.
      Parameters:
      src - Source sparse matrix.
      col - Vector to add to each column of the source matrix.
      Returns:
      A dense copy of the src matrix with the specified vector added to each column.
      Throws:
      IllegalArgumentException - If the number of data in the col vector does not match the number of rows in the src matrix.
    • addToEachRow

      public static Matrix addToEachRow(CooMatrix src, Vector row)
      Adds a dense vector to add to each row as if the vector is a row vector.
      Parameters:
      src - Source sparse matrix.
      row - Vector to add to each row of the source matrix.
      Returns:
      A dense copy of the src matrix with the specified vector added to each row.
      Throws:
      IllegalArgumentException - If the number of data in the col vector does not match the number of columns in the src matrix.