Esempio n. 1
0
        public void FactorizationLU(ref SparseMatrixQuaternion A)
        {
            CholmodInfo cholmodA = CholmodConverter.qConverter(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");
            }
        }
Esempio n. 2
0
        public static CholmodInfo qConverter(ref SparseMatrixQuaternion A, CholmodInfo.CholmodMatrixStorage storage)
        {
            CholmodInfo info = new CholmodInfo();

            info.MatrixType          = CholmodInfo.CholmodMatrixType.Sparse;
            info.MatrixStorageType   = storage;
            info.MatrixStorageMethod = CholmodInfo.CholmodMatrixStoageMethod.Normal;
            info.MatrixItemType      = CholmodInfo.CholmodMatrixItemType.Quaternion;
            info.RowCount            = 4 * A.RowCount;
            info.ColumnCount         = 4 * A.ColumnCount;

            switch (storage)
            {
            case CholmodInfo.CholmodMatrixStorage.CRS:
                A.ToCRS(out info.colIndex, out info.rowIndex, 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);
        }
Esempio n. 3
0
        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;

        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        public static CholmodInfo ConvertDouble(ref DenseMatrixDouble b)
        {
            CholmodInfo info = new CholmodInfo();
            info.MatrixType = CholmodInfo.CholmodMatrixType.Dense;

            b.ToArray(out info.RowCount, out info.ColumnCount, out info.values);

            return info;
        }
Esempio n. 7
0
        public static CholmodInfo ConvertDouble(ref DenseMatrixDouble b)
        {
            CholmodInfo info = new CholmodInfo();

            info.MatrixType = CholmodInfo.CholmodMatrixType.Dense;

            b.ToArray(out info.RowCount, out info.ColumnCount, out info.values);

            return(info);
        }
Esempio n. 8
0
        public static CholmodInfo cConverter(ref DenseMatrixComplex b)
        {
            CholmodInfo info = new CholmodInfo();

            info.MatrixType = CholmodInfo.CholmodMatrixType.Dense;

            b.ToArray(out info.RowCount, out info.ColumnCount, out info.values);    //Normal

            return(info);
        }
Esempio n. 9
0
        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;

        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
        /*
         * For Complex Calculation
         */
        public void FactorizationCholesky(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 = CreateSolverCholesky_CCS_Complex(cholmodA.RowCount, cholmodA.ColumnCount, cholmodA.nnz, Pt, Index, val);
            }

            if (solver == null)
            {
                throw new Exception("Create Solver Fail");
            }
        }
Esempio n. 12
0
        public DenseMatrixDouble SolveByFactorizedLU(ref DenseMatrixDouble b)
        {
            CholmodInfo cholmodb = CholmodConverter.ConvertDouble(ref b);

            DenseMatrixDouble result = new DenseMatrixDouble(n, 1);

            double[] x = new double[n];

            SolveLU(ref cholmodb.values, ref x);

            for (int i = 0; i < n; i++)
            {
                result[i, 0] = x[i];
            }

            x = null;
            GC.Collect();

            return(result);
        }
Esempio n. 13
0
        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);
        }
Esempio n. 14
0
        public static CholmodInfo cConverter(ref DenseMatrixComplex b)
        {
            CholmodInfo info = new CholmodInfo();
            info.MatrixType = CholmodInfo.CholmodMatrixType.Dense;

            b.ToArray(out info.RowCount, out info.ColumnCount, out info.values);    //Normal

            return info;
        }
Esempio n. 15
0
        public static CholmodInfo cConverter(ref SparseMatrixComplex A, CholmodInfo.CholmodMatrixStorage storage, CholmodInfo.CholmodMatrixStoageMethod method)
        {
            CholmodInfo info = new CholmodInfo();
            info.MatrixType = CholmodInfo.CholmodMatrixType.Sparse;
            info.MatrixStorageType = storage;
            info.MatrixStorageMethod = method;
            info.MatrixItemType = CholmodInfo.CholmodMatrixItemType.Complex;
            info.RowCount = A.RowCount;
            info.ColumnCount = A.ColumnCount;

            double[] values = null;

            switch (storage)
            {
                case CholmodInfo.CholmodMatrixStorage.CRS:
                    A.ToCRS(out info.colIndex, out info.rowIndex, out values, out info.nnz);
                    break;
                case CholmodInfo.CholmodMatrixStorage.CCS:
                    A.ToCCS(out info.colIndex, out info.rowIndex, out values, out info.nnz);
                    break;
                case CholmodInfo.CholmodMatrixStorage.Triplet:
                    A.ToTriplet(out info.colIndex, out info.rowIndex, out values, out info.z, out info.nnz);
                    break;
                default:
                    A.ToTriplet(out info.colIndex, out info.rowIndex, out values, out info.z, out info.nnz);

                    break;
            }

            switch (method)
            {
                case CholmodInfo.CholmodMatrixStoageMethod.Normal:
                    info.values = values;
                    break;
                case CholmodInfo.CholmodMatrixStoageMethod.Divided:
                    double[] realParts = new double[info.nnz];
                    double[] imgParts = new double[info.nnz];

                    for (int i = 0; i < info.nnz; i++)
                    {
                        realParts[i] = values[2 * i];
                        imgParts[i] = values[2 * i + 1];
                    }

                    info.values = realParts;
                    info.z = imgParts;

                    values = null;

                    break;
                default:
                    break;
            }

            GC.Collect();
            return info;

        }
Esempio n. 16
0
        public static CholmodInfo qConverter(ref SparseMatrixQuaternion A, CholmodInfo.CholmodMatrixStorage storage)
        {
            CholmodInfo info = new CholmodInfo();
            info.MatrixType = CholmodInfo.CholmodMatrixType.Sparse;
            info.MatrixStorageType = storage;
            info.MatrixStorageMethod = CholmodInfo.CholmodMatrixStoageMethod.Normal;
            info.MatrixItemType = CholmodInfo.CholmodMatrixItemType.Quaternion;
            info.RowCount = 4 * A.RowCount;
            info.ColumnCount = 4 * A.ColumnCount;

            switch (storage)
            {
                case CholmodInfo.CholmodMatrixStorage.CRS:
                    A.ToCRS(out info.colIndex, out info.rowIndex, 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;
        }
Esempio n. 17
0
        public static CholmodInfo cConverter(ref SparseMatrixComplex A, CholmodInfo.CholmodMatrixStorage storage, CholmodInfo.CholmodMatrixStoageMethod method)
        {
            CholmodInfo info = new CholmodInfo();

            info.MatrixType          = CholmodInfo.CholmodMatrixType.Sparse;
            info.MatrixStorageType   = storage;
            info.MatrixStorageMethod = method;
            info.MatrixItemType      = CholmodInfo.CholmodMatrixItemType.Complex;
            info.RowCount            = A.RowCount;
            info.ColumnCount         = A.ColumnCount;

            double[] values = null;

            switch (storage)
            {
            case CholmodInfo.CholmodMatrixStorage.CRS:
                A.ToCRS(out info.colIndex, out info.rowIndex, out values, out info.nnz);
                break;

            case CholmodInfo.CholmodMatrixStorage.CCS:
                A.ToCCS(out info.colIndex, out info.rowIndex, out values, out info.nnz);
                break;

            case CholmodInfo.CholmodMatrixStorage.Triplet:
                A.ToTriplet(out info.colIndex, out info.rowIndex, out values, out info.z, out info.nnz);
                break;

            default:
                A.ToTriplet(out info.colIndex, out info.rowIndex, out values, out info.z, out info.nnz);

                break;
            }

            switch (method)
            {
            case CholmodInfo.CholmodMatrixStoageMethod.Normal:
                info.values = values;
                break;

            case CholmodInfo.CholmodMatrixStoageMethod.Divided:
                double[] realParts = new double[info.nnz];
                double[] imgParts  = new double[info.nnz];

                for (int i = 0; i < info.nnz; i++)
                {
                    realParts[i] = values[2 * i];
                    imgParts[i]  = values[2 * i + 1];
                }

                info.values = realParts;
                info.z      = imgParts;

                values = null;

                break;

            default:
                break;
            }

            GC.Collect();
            return(info);
        }