/* * For Complex Calculation */ public void FactorizationLU(ref SparseMatrixComplex A) { CholmodInfo cholmodA = CholmodConverter.cConverter(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_Complex(cholmodA.RowCount, cholmodA.ColumnCount, cholmodA.nnz, Index, Pt, val ); } if (solver == null) { throw new Exception("Create Solver Fail"); } }
public DenseMatrixComplex SolveLinerSystem(ref SparseMatrixComplex A, ref DenseMatrixComplex b) { if (A.RowCount != b.RowCount) { throw new Exception("The dimension of A and b must be agree"); } CholmodInfo cholmodb = CholmodConverter.cConverter(ref b); CholmodInfo cholmodA = CholmodConverter.cConverter(ref A, CholmodInfo.CholmodMatrixStorage.CCS); double[] x = new double[2 * A.ColumnCount]; fixed(int *Index = cholmodA.rowIndex, Pt = cholmodA.colIndex) fixed(double *val = cholmodA.values, bp = cholmodb.values, xx = x) { SolveRealByQR_CCS_Complex(cholmodA.RowCount, cholmodA.ColumnCount, cholmodA.nnz, Pt, //Column Pointer Index, //Row Index val, xx, bp); } DenseMatrixComplex unknown = CholmodConverter.cConvertArrayToDenseMatrix(ref x, x.Length, 1); cholmodA = null; cholmodb = null; GC.Collect(); return(unknown); }
public DenseMatrixComplex SolveByFactorizedLU(ref DenseMatrixComplex b) { CholmodInfo cholmodb = CholmodConverter.cConverter(ref b); DenseMatrixComplex result = new DenseMatrixComplex(n, 1); double[] x = new double[2 * n]; SolveLUComplex(ref cholmodb.values, ref x); for (int i = 0; i < n; i++) { result[i, 0] = new Complex(x[2 * i], x[2 * i + 1]); } x = null; GC.Collect(); return(result); }