public static void mult(DMatrixSparseCSC A, DMatrixRMaj B, DMatrixRMaj C)
        {
            C.zero();

            // C(i,j) = sum_k A(i,k) * B(k,j)
            for (int k = 0; k < A.numCols; k++)
            {
                int idx0 = A.col_idx[k];
                int idx1 = A.col_idx[k + 1];

                for (int indexA = idx0; indexA < idx1; indexA++)
                {
                    int    i      = A.nz_rows[indexA];
                    double valueA = A.nz_values[indexA];

                    int indexB = k * B.numCols;
                    int indexC = i * C.numCols;
                    int end    = indexB + B.numCols;

//                for (int j = 0; j < B.numCols; j++) {
                    while (indexB < end)
                    {
                        C.data[indexC++] += valueA * B.data[indexB++];
                    }
                }
            }
        }
Exemplo n.º 2
0
 /**
  * Creates a zeros matrix only if A does not already exist.  If it does exist it will fill
  * the lower triangular portion with zeros.
  */
 public static DMatrixRMaj checkZerosLT(DMatrixRMaj A, int numRows, int numCols)
 {
     if (A == null)
     {
         return(new DMatrixRMaj(numRows, numCols));
     }
     else if (numRows != A.numRows || numCols != A.numCols)
     {
         A.reshape(numRows, numCols);
         A.zero();
     }
     else
     {
         for (int i = 0; i < A.numRows; i++)
         {
             int index = i * A.numCols;
             int end   = index + Math.Min(i, A.numCols);
             while (index < end)
             {
                 A.data[index++] = 0;
             }
         }
     }
     return(A);
 }
Exemplo n.º 3
0
 public static DMatrixRMaj ensureZeros(DMatrixRMaj A, int numRows, int numCols)
 {
     if (A == null)
     {
         return(new DMatrixRMaj(numRows, numCols));
     }
     A.reshape(numRows, numCols);
     A.zero();
     return(A);
 }
Exemplo n.º 4
0
 public static DMatrixRMaj checkZeros(DMatrixRMaj A, int numRows, int numCols)
 {
     if (A == null)
     {
         return(new DMatrixRMaj(numRows, numCols));
     }
     else if (numRows != A.numRows || numCols != A.numCols)
     {
         throw new ArgumentException("Input is not " + numRows + " x " + numCols + " matrix");
     }
     else
     {
         A.zero();
     }
     return(A);
 }
        private void solveEigenvectorDuplicateEigenvalue(double real, int first, bool isTriangle)
        {
            double scale = Math.Abs(real);

            if (scale == 0)
            {
                scale = 1;
            }

            eigenvectorTemp.reshape(N, 1, false);
            eigenvectorTemp.zero();

            if (first > 0)
            {
                if (isTriangle)
                {
                    solveUsingTriangle(real, first, eigenvectorTemp);
                }
                else
                {
                    solveWithLU(real, first, eigenvectorTemp);
                }
            }

            eigenvectorTemp.reshape(N, 1, false);

            for (int i = first; i < N; i++)
            {
                Complex_F64 c = _implicit.eigenvalues[N - i - 1];

                if (c.isReal() && Math.Abs(c.real - real) / scale < 100.0 * UtilEjml.EPS)
                {
                    eigenvectorTemp.data[i] = 1;

                    DMatrixRMaj v = new DMatrixRMaj(N, 1);
                    CommonOps_DDRM.multTransA(Q, eigenvectorTemp, v);
                    eigenvectors[N - i - 1] = v;
                    NormOps_DDRM.normalizeF(v);

                    eigenvectorTemp.data[i] = 0;
                }
            }
        }