public static CholmodInfo ConverterDouble(ref SparseMatrixDouble A, CholmodInfo.CholmodMatrixStorage storage) { CholmodInfo info = new CholmodInfo(); info.MatrixType = CholmodInfo.CholmodMatrixType.Sparse; info.MatrixStorageType = storage; info.RowCount = A.RowCount; info.ColumnCount = A.ColumnCount; switch (storage) { case CholmodInfo.CholmodMatrixStorage.CRS: A.ToCRS(out info.rowIndex, out info.colIndex, out info.values, out info.nnz); break; case CholmodInfo.CholmodMatrixStorage.CCS: A.ToCCS(out info.colIndex, out info.rowIndex, out info.values, out info.nnz); break; case CholmodInfo.CholmodMatrixStorage.Triplet: A.ToTriplet(out info.colIndex, out info.rowIndex, out info.values, out info.nnz); break; default: A.ToTriplet(out info.colIndex, out info.rowIndex, out info.values, out info.nnz); break; } return info; }
public static CholmodInfo ConverterDouble(ref SparseMatrixDouble A, CholmodInfo.CholmodMatrixStorage storage) { CholmodInfo info = new CholmodInfo(); info.MatrixType = CholmodInfo.CholmodMatrixType.Sparse; info.MatrixStorageType = storage; info.RowCount = A.RowCount; info.ColumnCount = A.ColumnCount; switch (storage) { case CholmodInfo.CholmodMatrixStorage.CRS: A.ToCRS(out info.rowIndex, out info.colIndex, out info.values, out info.nnz); break; case CholmodInfo.CholmodMatrixStorage.CCS: A.ToCCS(out info.colIndex, out info.rowIndex, out info.values, out info.nnz); break; case CholmodInfo.CholmodMatrixStorage.Triplet: A.ToTriplet(out info.colIndex, out info.rowIndex, out info.values, out info.nnz); break; default: A.ToTriplet(out info.colIndex, out info.rowIndex, out info.values, out info.nnz); break; } return(info); }
public static CholmodInfo ConverterDouble(ref SparseMatrixDouble A) { CholmodInfo info = new CholmodInfo(); info.MatrixType = CholmodInfo.CholmodMatrixType.Sparse; info.RowCount = A.RowCount; info.ColumnCount = A.ColumnCount; A.ToTriplet(out info.colIndex, out info.rowIndex, out info.values, out info.nnz); return info; }
public static CholmodInfo ConverterDouble(ref SparseMatrixDouble A) { CholmodInfo info = new CholmodInfo(); info.MatrixType = CholmodInfo.CholmodMatrixType.Sparse; info.RowCount = A.RowCount; info.ColumnCount = A.ColumnCount; A.ToTriplet(out info.colIndex, out info.rowIndex, out info.values, out info.nnz); return(info); }
public void ToTriplet(out int[] colIndices, out int[] rowIndices, out double[] values, out int nnz) { SparseMatrixDouble sparse = new SparseMatrixDouble(4 * this.rowCount, 4 * this.columnCount); foreach (KeyValuePair <Pair, Quaternion> e in mapData) { Pair pair = e.Key; double q0 = e.Value.x; double q1 = e.Value.y; double q2 = e.Value.z; double q3 = e.Value.w; if (q0 != 0) { sparse.Datas.Add(new Pair(4 * pair.Key, 4 * pair.Value), q0); sparse.Datas.Add(new Pair(4 * pair.Key + 1, 4 * pair.Value + 1), q0); sparse.Datas.Add(new Pair(4 * pair.Key + 2, 4 * pair.Value + 2), q0); sparse.Datas.Add(new Pair(4 * pair.Key + 3, 4 * pair.Value + 3), q0); } if (q1 != 0) { sparse.Datas.Add(new Pair(4 * pair.Key + 1, 4 * pair.Value), q1); sparse.Datas.Add(new Pair(4 * pair.Key, 4 * pair.Value + 1), q1); sparse.Datas.Add(new Pair(4 * pair.Key + 3, 4 * pair.Value + 2), q1); sparse.Datas.Add(new Pair(4 * pair.Key + 2, 4 * pair.Value + 3), q1); } if (q2 != 0) { sparse.Datas.Add(new Pair(4 * pair.Key + 2, 4 * pair.Value), q1); sparse.Datas.Add(new Pair(4 * pair.Key, 4 * pair.Value + 2), q1); sparse.Datas.Add(new Pair(4 * pair.Key + 3, 4 * pair.Value + 1), q1); sparse.Datas.Add(new Pair(4 * pair.Key + 1, 4 * pair.Value + 3), q1); } if (q3 != 0) { sparse.Datas.Add(new Pair(4 * pair.Key + 3, 4 * pair.Value), q1); sparse.Datas.Add(new Pair(4 * pair.Key, 4 * pair.Value + 3), q1); sparse.Datas.Add(new Pair(4 * pair.Key + 2, 4 * pair.Value + 1), q1); sparse.Datas.Add(new Pair(4 * pair.Key + 1, 4 * pair.Value + 2), q1); } } sparse.ToTriplet(out colIndices, out rowIndices, out values, out nnz); }
public void FactorizationCholesky(ref SparseMatrixDouble A) { // CholmodInfo cholmodA = CholmodConverter.Converter(ref A); int rowCount = A.RowCount; int columnCount = A.ColumnCount; int nnz = 0; int[] Ri = null; int[] Ci = null; double[] values = null; A.ToTriplet(out Ci, out Ri, out values, out nnz); fixed(int *ri = Ri, ci = Ci) fixed(double *val = values) { solver = CreateSolverCholeskyCHOLMOD(rowCount, rowCount, nnz, nnz, ri, ci, val); } if (solver == null) { throw new Exception("Create Solver Fail"); } }
public void ToTriplet(out int[] colIndices, out int[] rowIndices, out double[] values, out int nnz) { SparseMatrixDouble sparse = new SparseMatrixDouble(4 * this.rowCount, 4 * this.columnCount); foreach (KeyValuePair<Pair, Quaternion> e in mapData) { Pair pair = e.Key; double q0 = e.Value.w; double q1 = e.Value.x; double q2 = e.Value.y; double q3 = e.Value.z; if (q0 != 0) { sparse.Datas.Add(new Pair(4 * pair.Key, 4 * pair.Value), q0); sparse.Datas.Add(new Pair(4 * pair.Key + 1, 4 * pair.Value + 1), q0); sparse.Datas.Add(new Pair(4 * pair.Key + 2, 4 * pair.Value + 2), q0); sparse.Datas.Add(new Pair(4 * pair.Key + 3, 4 * pair.Value + 3), q0); } if (q1 != 0) { sparse.Datas.Add(new Pair(4 * pair.Key + 1, 4 * pair.Value), q1); sparse.Datas.Add(new Pair(4 * pair.Key, 4 * pair.Value + 1), -q1); sparse.Datas.Add(new Pair(4 * pair.Key + 3, 4 * pair.Value + 2), q1); sparse.Datas.Add(new Pair(4 * pair.Key + 2, 4 * pair.Value + 3), -q1); } if (q2 != 0) { sparse.Datas.Add(new Pair(4 * pair.Key + 2, 4 * pair.Value), q2); sparse.Datas.Add(new Pair(4 * pair.Key + 3, 4 * pair.Value + 1), -q2); sparse.Datas.Add(new Pair(4 * pair.Key, 4 * pair.Value + 2), -q2); sparse.Datas.Add(new Pair(4 * pair.Key + 1, 4 * pair.Value + 3), q2); } if (q3 != 0) { sparse.Datas.Add(new Pair(4 * pair.Key + 3, 4 * pair.Value), q3); sparse.Datas.Add(new Pair(4 * pair.Key + 2, 4 * pair.Value + 1), q3); sparse.Datas.Add(new Pair(4 * pair.Key, 4 * pair.Value + 3), -q3); sparse.Datas.Add(new Pair(4 * pair.Key + 1, 4 * pair.Value + 2), -q3); } } sparse.ToTriplet(out colIndices, out rowIndices, out values, out nnz); }
public void FactorizationCholesky(ref SparseMatrixDouble A) { // CholmodInfo cholmodA = CholmodConverter.Converter(ref A); int rowCount = A.RowCount; int columnCount = A.ColumnCount; int nnz = 0; int[] Ri = null; int[] Ci = null; double[] values = null; A.ToTriplet(out Ci, out Ri, out values, out nnz); fixed (int* ri = Ri, ci = Ci) fixed (double* val = values) { solver = CreateSolverCholeskyCHOLMOD(rowCount, rowCount, nnz, nnz, ri, ci, val); } if (solver == null) throw new Exception("Create Solver Fail"); }