Ejemplo n.º 1
0
        /**
         * Performs an element-wise multiplication.<br>
         * C[i,j] = A[i,j]*B[i,j]<br>
         * All matrices must have the same shape.
         *
         * @param A (Input) Matrix.
         * @param B (Input) Matrix
         * @param C (Ouptut) Matrix.
         * @param gw (Optional) Storage for internal workspace.  Can be null.
         * @param gx (Optional) Storage for internal workspace.  Can be null.
         */
        public static void elementMult(DMatrixSparseCSC A, DMatrixSparseCSC B, DMatrixSparseCSC C,
                                       IGrowArray gw, DGrowArray gx)
        {
            if (A.numCols != B.numCols || A.numRows != B.numRows || A.numCols != C.numCols || A.numRows != C.numRows)
            {
                throw new ArgumentException("All inputs must have the same number of rows and columns");
            }

            ImplCommonOps_DSCC.elementMult(A, B, C, gw, gx);
        }
Ejemplo n.º 2
0
        /**
         * Performs matrix addition:<br>
         * C = &alpha;A + &beta;B
         *
         * @param alpha scalar value multiplied against A
         * @param A Matrix
         * @param beta scalar value multiplied against B
         * @param B Matrix
         * @param C Output matrix.
         * @param gw (Optional) Storage for internal workspace.  Can be null.
         * @param gx (Optional) Storage for internal workspace.  Can be null.
         */
        public static void add(double alpha, DMatrixSparseCSC A, double beta, DMatrixSparseCSC B, DMatrixSparseCSC C,
                               IGrowArray gw, DGrowArray gx)
        {
            if (A.numRows != B.numRows || A.numCols != B.numCols || A.numRows != C.numRows || A.numCols != C.numCols)
            {
                throw new ArgumentException("Inconsistent matrix shapes");
            }

            ImplCommonOps_DSCC.add(alpha, A, beta, B, C, gw, gx);
        }
Ejemplo n.º 3
0
        /**
         * Perform matrix transpose
         *
         * @param a Input matrix.  Not modified
         * @param a_t Storage for transpose of 'a'.  Must be correct shape.  data length might be adjusted.
         * @param gw (Optional) Storage for internal workspace.  Can be null.
         */
        public static void transpose(DMatrixSparseCSC a, DMatrixSparseCSC a_t, IGrowArray gw)
        {
            if (a_t.numRows != a.numCols || a_t.numCols != a.numRows)
            {
                throw new ArgumentException("Unexpected shape for transpose matrix");
            }

            a_t.growMaxLength(a.nz_length, false);
            a_t.nz_length = a.nz_length;

            ImplCommonOps_DSCC.transpose(a, a_t, gw);
        }
Ejemplo n.º 4
0
        /**
         * <p>
         * Performs a rank-1 update operation on the submatrix specified by V with the multiply on the right.<br>
         * <br>
         * C = (I - &gamma;*v*v<sup>T</sup>)*A<br>
         * </p>
         * <p>
         * The order that matrix multiplies are performed has been carefully selected
         * to minimize the number of operations.
         * </p>
         *
         * <p>
         * Before this can become a truly generic operation the submatrix specification needs
         * to be made more generic.
         * </p>
         */
        public static void rank1UpdateMultR(DMatrixSparseCSC V, int colV, double gamma,
                                            DMatrixSparseCSC A, DMatrixSparseCSC C,
                                            IGrowArray gw, DGrowArray gx)
        {
            if (V.numRows != A.numRows)
            {
                throw new ArgumentException("Number of rows in V and A must match");
            }

            C.nz_length = 0;
            C.numRows   = V.numRows;
            C.numCols   = 0;

            for (int i = 0; i < A.numCols; i++)
            {
                double tau = CommonOps_DSCC.dotInnerColumns(V, colV, A, i, gw, gx);
                ImplCommonOps_DSCC.addColAppend(1.0, A, i, -gamma * tau, V, colV, C, gw);
            }
        }
Ejemplo n.º 5
0
 /**
  * Removes all elements from the matrix that are &gt; tol. The modification is done in place and no temporary
  * storage is declared.
  *
  * @param A (Input/Output) input matrix. Modified.
  * @param tol Tolerance for defining zero
  */
 public static void removeZeros(DMatrixSparseCSC A, double tol)
 {
     ImplCommonOps_DSCC.removeZeros(A, tol);
 }
Ejemplo n.º 6
0
 /**
  * Copies all elements from input into output which are &gt; tol.
  * @param input (Input) input matrix. Not modified.
  * @param output (Output) Output matrix. Modified and shaped to match input.
  * @param tol Tolerance for defining zero
  */
 public static void removeZeros(DMatrixSparseCSC input, DMatrixSparseCSC output, double tol)
 {
     ImplCommonOps_DSCC.removeZeros(input, output, tol);
 }