示例#1
0
 public static void SetEntry(ref int _ref, ref int i, ref int j, ref double val, out int ierr)
 {
     ierr = 0;
     try {
         IMutableMatrix M = (IMutableMatrix)Infrastructure.GetObject(_ref);
         M[i, j] = val;
     } catch (Exception e) {
         ierr = Infrastructure.ErrorHandler(e);
     }
 }
示例#2
0
        /// <summary>
        /// extracts the diagonal vector from a matrix.
        /// </summary>
        static public double[] GetDiagVector(this IMutableMatrix M)
        {
            int i0 = M.RowPartitioning.i0;
            int L  = M.RowPartitioning.LocalLength;

            double[] diag = new double[L];
            for (int i = 0; i < L; i++)
            {
                diag[i] = M[i + i0, i + i0];
            }
            return(diag);
        }
示例#3
0
        /// <summary>
        /// performs the operation: <paramref name="Acc"/> = <paramref name="Acc"/> + <paramref name="alpha"/>*<paramref name="M"/>
        /// </summary>
        /// <param name="Acc">
        /// Input/Output: the accumulator
        /// </param>
        /// <param name="alpha">
        /// scaling for accumulation
        /// </param>
        /// <param name="M">
        /// Input: the matrix that is accumulated; unchanged on exit.
        /// </param>
        public static void Acc(this IMutableMatrix Acc, double alpha, IMutableMatrixEx M)
        {
            if (Acc.NoOfCols != M.NoOfCols)
            {
                throw new ArgumentException("mismatch in number of columns");
            }
            if (Acc.NoOfRows != M.NoOfRows)
            {
                throw new ArgumentException("mismatch in number of rows");
            }

            if (!Acc.RowPartitioning.EqualsPartition(M.RowPartitioning))
            {
                throw new ArgumentException("unable to perform Acc - operation: matrices must have equal row partition.");
            }

            MsrMatrix _M = M as MsrMatrix;

            int I  = Acc.RowPartitioning.LocalLength;
            int i0 = (int)Acc.RowPartitioning.i0;

            double[] val = null;
            int[]    col = null;
            int      L;

            for (int i = 0; i < I; i++)
            {
                int iRow = i + i0;

                L = M.GetRow(iRow, ref col, ref val);

                for (int l = 0; l < L; l++)
                {
                    Acc[iRow, col[l]] += alpha * val[l];
                }
            }
        }