示例#1
0
        // *** wrapper for external DoLSqr ***
        public static double[] DoLSqr(int num_cols, LSqrSparseMatrix mat, LSqrSparseMatrix mat_transp, double[] rhs, int max_iter)
        {
            IntPtr sol_ptr = DoLSqr(mat.Id, mat_transp.Id, rhs, max_iter);

            double[] sol = new double[num_cols];
            Marshal.Copy(sol_ptr, sol, 0, sol.Length);
            Marshal.FreeHGlobal(sol_ptr);
            return(sol);
        }
示例#2
0
 public static double[] DoLSqr(int num_cols, LSqrSparseMatrix mat, LSqrSparseMatrix mat_transp, double[] init_sol, double[] rhs, int max_iter)
 {
     IntPtr sol_ptr = DoLSqr(mat.Id, mat_transp.Id, init_sol, rhs, max_iter);
     GC.KeepAlive(mat); // avoid premature garbage collection
     GC.KeepAlive(mat_transp);
     double[] sol = new double[num_cols];
     Marshal.Copy(sol_ptr, sol, 0, sol.Length);
     Marshal.FreeHGlobal(sol_ptr);
     return sol;
 }
示例#3
0
 public static LSqrSparseMatrix FromDenseMatrix(double[,] mat)
 {
     LSqrSparseMatrix lsqr_mat = new LSqrSparseMatrix(mat.GetLength(0));
     for (int row = 0; row < mat.GetLength(0); row++)
     {
         for (int col = 0; col < mat.GetLength(1); col++)
         {
             if (mat[row, col] != 0)
             {
                 lsqr_mat.InsertValue(row, col, mat[row, col]);
             }
         }
     }
     return lsqr_mat;
 }
示例#4
0
        public static LSqrSparseMatrix TransposeFromDenseMatrix(double[,] mat)
        {
            LSqrSparseMatrix lsqr_mat = new LSqrSparseMatrix();

            for (int col = 0; col < mat.GetLength(1); col++)
            {
                lsqr_mat.NewRow();
                for (int row = 0; row < mat.GetLength(0); row++)
                {
                    if (mat[row, col] != 0)
                    {
                        lsqr_mat.InsertValue(row, mat[row, col]);
                    }
                }
            }
            return(lsqr_mat);
        }
示例#5
0
 // *** wrappers for external DoLSqr ***
 public static double[] DoLSqr(int num_cols, LSqrSparseMatrix mat, LSqrSparseMatrix mat_transp, double[] rhs, int max_iter)
 {
     return DoLSqr(num_cols, mat, mat_transp, /*init_sol=*/null, rhs, max_iter);
 }