public void FactorizationLU(ref SparseMatrixDouble A) { CholmodInfo cholmodA = CholmodConverter.ConverterDouble(ref A, CholmodInfo.CholmodMatrixStorage.CCS); m = A.RowCount; n = A.ColumnCount; fixed(int *Index = cholmodA.rowIndex, Pt = cholmodA.colIndex) fixed(double *val = cholmodA.values) { solver = CreateSolverLUUMFPACK_CCS(cholmodA.RowCount, cholmodA.ColumnCount, cholmodA.nnz, Index, Pt, val ); } if (solver == null) { throw new Exception("Create Solver Fail"); } }
public DenseMatrixDouble SolveLinearSystemByLU(ref SparseMatrixDouble A, ref DenseMatrixDouble b) { if (A.RowCount != b.RowCount) { throw new Exception("The dimension of A and b must be agree"); } CholmodInfo cholmodb = CholmodConverter.ConvertDouble(ref b); CholmodInfo cholmodA = CholmodConverter.ConverterDouble(ref A, CholmodInfo.CholmodMatrixStorage.CCS); double[] x = new double[A.ColumnCount]; fixed(int *Index = cholmodA.rowIndex, Pt = cholmodA.colIndex) fixed(double *val = cholmodA.values, bp = cholmodb.values, xx = x) { SolveRealByLU_CCS(cholmodA.RowCount, cholmodA.ColumnCount, cholmodA.nnz, Index, //Row Index Pt, //Column Pointer val, xx, bp); } DenseMatrixDouble unknown = CholmodConverter.dConvertArrayToDenseMatrix(ref x, x.Length, 1); cholmodA = null; cholmodb = null; GC.Collect(); return(unknown); }