Class RealComplexCsrOps

java.lang.Object
org.flag4j.linalg.ops.sparse.csr.real_complex.RealComplexCsrOps

public final class RealComplexCsrOps extends Object
This class contains low-level implementations for element-wise ops on real/complex CSR matrices.
  • Method Details

    • applyBinOpp

      public static CsrCMatrix applyBinOpp(CsrMatrix src1, CsrCMatrix src2, BiFunction<Double,Complex128,Complex128> opp, UnaryOperator<Complex128> 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 matrix and using a dense matrix addition algorithm.
      Parameters:
      src1 - The first matrix in the operation.
      src2 - The second matrix in the operation.
      opp - 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 opp and one unary operation uOpp such that it is equivalent to opp.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.
    • applyBinOpp

      public static CsrCMatrix applyBinOpp(CsrCMatrix src1, CsrMatrix src2, BiFunction<Complex128,Double,Complex128> opp, 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.
      opp - 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 opp and one unary operation uOpp such that it is equivalent to opp.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.
    • elemMult

      public static CsrCMatrix elemMult(CsrCMatrix src1, CsrMatrix src2)
      Computes the element-wise multiplication between a complex sparse matrix and a real sparse matrix.

      Parameters:
      src1 - The first matrix in the element-wise multiplication.
      src2 - The second matrix in the element-wise multiplication.
      Returns:
      The result of the element-wise multiplication between src1 and src2.
      Throws:
      IllegalArgumentException - If src1 and src2 do not have the same shape.
    • add

      public static CsrCMatrix add(CsrCMatrix a, CsrMatrix b)
      Computes the element-wise sum of two matrices.
      Parameters:
      a - First matrix in sum.
      b - Second matrix in sum.
      Returns:
      The element-wise sum of a and b.
    • sub

      public static CsrCMatrix sub(CsrCMatrix a, CsrMatrix b)
      Computes the element-wise difference of two matrices.
      Parameters:
      a - First matrix in difference.
      b - Second matrix in difference.
      Returns:
      The element-wise difference of a and b.
    • sub

      public static CsrCMatrix sub(CsrMatrix a, CsrCMatrix b)
      Computes the element-wise difference of two matrices.
      Parameters:
      a - First matrix in difference.
      b - Second matrix in difference.
      Returns:
      The element-wise difference of a and b.
    • addToEachCol

      public static CMatrix addToEachCol(CsrCMatrix src1, Vector src2)
      Adds a vector to each column of a matrix. The vector need not be a column vector. If it is a row vector it will be treated as if it were a column vector.
      Parameters:
      src1 - CSR matrix to add vector to each column of.
      src2 - Vector to add to each column of this matrix.
      Returns:
      The result of adding the vector src2 to each column of this matrix.
    • addToEachCol

      public static CMatrix addToEachCol(CsrCMatrix src1, CooVector src2)
      Adds a vector to each column of a matrix. The vector need not be a column vector. If it is a row vector it will be treated as if it were a column vector.
      Parameters:
      src1 - CSR matrix to add vector to each column of.
      src2 - Vector to add to each column of this matrix.
      Returns:
      The result of adding the vector src2 to each column of this matrix.
    • addToEachRow

      public static CMatrix addToEachRow(CsrCMatrix src1, Vector src2)
      Adds a vector to each row of a matrix. The vector need not be a row vector. If it is a column vector it will be treated as if it were a row vector for this operation.
      Parameters:
      src1 - CSR matrix to add vector to each row of.
      src2 - Vector to add to each row of this matrix.
      Returns:
      The result of adding the vector src2 to each row of this matrix.
    • addToEachRow

      public static CMatrix addToEachRow(CsrCMatrix src1, CooVector src2)
      Adds a vector to each row of a matrix. The vector need not be a row vector. If it is a column vector it will be treated as if it were a row vector for this operation.
      Parameters:
      src1 - CSR matrix to add vector to each row of.
      src2 - Vector to add to each row of this matrix.
      Returns:
      The result of adding the vector src2 to each row of this matrix.