Class RealCsrOps

java.lang.Object
org.flag4j.linalg.ops.sparse.csr.real.RealCsrOps

public final class RealCsrOps extends Object
This utility class contains low-level implementations for operations on real CSR matrices.
  • Method Details

    • elemMult

      public static CsrMatrix elemMult(CsrMatrix src1, CsrMatrix src2)
      Computes the element-wise multiplication between two real CSR matrices.
      Parameters:
      src1 - First CSR matrix in the element-wise product.
      src2 - Second CSR matrix in the element-wise product.
      Returns:
      The element-wise product of src1 and src2.
      Throws:
      TensorShapeException - If !src1.shape.equals(src2.shape)
    • applyBinOpp

      public static CsrMatrix applyBinOpp(CsrMatrix src1, CsrMatrix src2, BinaryOperator<Double> bOpp, UnaryOperator<Double> uOpp)

      Applies an element-wise binary operation to two CSR Matrices.

      Note, this methods efficiency relies heavily on the assumption that both operand matrices are very large and very sparse. If the two matrices are not large and very sparse, this method will likely be significantly slower than simply converting the matrices to dense matrices and using a dense matrix addition algorithm.

      Parameters:
      src1 - The first matrix in the operation.
      src2 - The second matrix in the operation.
      bOpp - Binary operator to apply element-wise to src1 and src2.
      uOpp - Unary operator for use with binary ops which are not commutative such as subtraction. If the operation is commutative this should be null. If the binary operation is not commutative, it needs to be decomposable to one commutative binary operation bOpp and one unary operation uOpp such that it is equivalent to bOpp.apply(x, uOpp.apply(y)).
      Returns:
      The result of applying the specified binary operation to src1 and src2 element-wise.
      Throws:
      IllegalArgumentException - If src1 and src2 do not have the same shape.
    • transpose

      public static CsrMatrix transpose(CsrMatrix src)
      Transposes a sparse CSR matrix.
      Parameters:
      src - The matrix to transpose.
      Returns:
      The transpose of the src matrix.
    • getSlice

      public static CsrMatrix getSlice(CsrMatrix src, int rowStart, int rowEnd, int colStart, int colEnd)
      Gets a specified slice of a CSR matrix.
      Parameters:
      src - Sparse CSR matrix to extract slice from.
      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 - If rowEnd is not greater than rowStart or if colEnd is not greater than colStart.