Exemple #1
0
        public TripletArraryData ConvertToTripletArrayData(SparseMatrix A)
        {
            TripletArraryData data = new TripletArraryData();

            switch (SolverType)
            {
            case EnumSolver.UmfpackLU:
                data = ConvertToDataUnSym(A);
                break;

            case EnumSolver.SuperLULU:
                data = ConvertToDataUnSym(A);
                break;

            case EnumSolver.CholmodCholesky:
                data = ConvertToDataSymU(A);
                break;

            case EnumSolver.SPQRLeastNormal:
                data = ConvertToDataUnSym(A);
                break;

            case EnumSolver.SPQRLeastSqure:
                data = ConvertToDataUnSym(A);
                break;
            }

            return(data);
        }
Exemple #2
0
        public TripletArraryData ConvertToDataSymU(SparseMatrix A)
        {
            TripletArraryData data = new TripletArraryData();
            // get number of non-zero elements
            int rowCount    = A.Rows.Count;
            int columnCount = A.Columns.Count;


            int sym_nnz = 0;

            foreach (List <SparseMatrix.Element> col in A.Columns)
            {
                foreach (SparseMatrix.Element e in col)
                {
                    if (e.i >= e.j)
                    {
                        if (e.value != 0)
                        {
                            sym_nnz++;
                        }
                    }
                }
            }

            #region Chomold
            data.values   = new double[sym_nnz];
            data.rowIndex = new int[sym_nnz];
            data.colIndex = new int[sym_nnz];
            data.nnz      = sym_nnz;

            int rowCur = 0;

            foreach (List <SparseMatrix.Element> col in A.Columns)
            {
                foreach (SparseMatrix.Element e in col)
                {
                    if (e.i < e.j || e.value == 0)
                    {
                        continue;
                    }

                    data.rowIndex[rowCur] = e.i;
                    data.colIndex[rowCur] = e.j;
                    data.values[rowCur]   = e.value;
                    rowCur++;
                }
            }
            #endregion

            return(data);
        }
Exemple #3
0
        public TripletArraryData ConvertToDataUnSym(SparseMatrix A)
        {
            TripletArraryData data = new TripletArraryData();
            int unSym_nnz          = 0;


            foreach (List <SparseMatrix.Element> col in A.Columns)
            {
                foreach (SparseMatrix.Element e in col)
                {
                    if (e.value != 0)
                    {
                        unSym_nnz++;
                    }
                }
            }



            data.rowIndex = new int[unSym_nnz];
            data.colIndex = new int[unSym_nnz];
            data.values   = new double[unSym_nnz];
            data.nnz      = unSym_nnz;
            // copy values to arrays
            int rowCur = 0;

            data.colIndex[0] = 0;
            foreach (List <SparseMatrix.Element> col in A.Columns)
            {
                foreach (SparseMatrix.Element e in col)
                {
                    if (e.value != 0)
                    {
                        data.rowIndex[rowCur] = e.i;
                        data.colIndex[rowCur] = e.j;
                        data.values[rowCur]   = e.value;
                        rowCur++;
                    }
                }
            }



            return(data);
        }
Exemple #4
0
        public void Factorization(SparseMatrix A)
        {
            TripletArraryData data = ConvertToTripletArrayData(A);

            int rowCount    = A.Rows.Count;
            int columnCount = A.Columns.Count;
            int nnz         = data.nnz;

            fixed(int *ri = data.rowIndex, ci = data.colIndex)
            fixed(double *val = data.values)
            {
                switch (SolverType)
                {
                case EnumSolver.UmfpackLU:
                    solver = CreateSolverLUUMFPACK(rowCount, nnz, ri, ci, val);
                    break;

                case EnumSolver.SuperLULU:
                    solver = CreateSolverLUSuperLU(rowCount, rowCount, nnz, ri, ci, val);
                    break;

                case EnumSolver.CholmodCholesky:
                    solver = CreateSolverCholeskyCHOLMOD(rowCount, rowCount, nnz, nnz, ri, ci, val);
                    break;

                case EnumSolver.SPQRLeastNormal:
                    solver = CreateSolverQRSuiteSparseQR(rowCount, columnCount, nnz, nnz, ri, ci, val);
                    break;

                case EnumSolver.SPQRLeastSqure:
                    solver = CreateSolverQRSuiteSparseQR(rowCount, columnCount, nnz, nnz, ri, ci, val);
                    break;
                }
            }
            if (solver == null)
            {
                throw new Exception("Create Solver Fail");
            }
        }
Exemple #5
0
        public TripletArraryData ConvertToDataSymU(SparseMatrix A)
        {
            TripletArraryData data = new TripletArraryData();
            // get number of non-zero elements
            int rowCount = A.Rows.Count;
            int columnCount = A.Columns.Count;
            
           
            int sym_nnz = 0;

            foreach (List<SparseMatrix.Element> col in A.Columns)
            {
                foreach (SparseMatrix.Element e in col)
                {
                    if (e.i >= e.j)
                    {
                        
                        if (e.value != 0)
                        {
                            sym_nnz++;
                        }
                    }
                    
                }
            }

            #region Chomold
            data.values = new double[sym_nnz];
            data.rowIndex = new int[sym_nnz];
            data.colIndex = new int[sym_nnz];
            data.nnz = sym_nnz;

            int rowCur = 0;

            foreach (List<SparseMatrix.Element> col in A.Columns)
            {
                foreach (SparseMatrix.Element e in col)
                {
                    if (e.i < e.j || e.value == 0) continue;

                    data.rowIndex[rowCur] = e.i;
                    data.colIndex[rowCur] = e.j;
                    data.values[rowCur] = e.value;
                    rowCur++;
                }

            }
            #endregion

            return data;
        }
Exemple #6
0
        public TripletArraryData ConvertToDataUnSym(SparseMatrix A)
        {

            TripletArraryData data = new TripletArraryData();
            int unSym_nnz = 0;
      

            foreach (List<SparseMatrix.Element> col in A.Columns)
            {
                foreach (SparseMatrix.Element e in col)
                { 
                    if (e.value != 0)
                    {
                        unSym_nnz++;
                    }
                }
            }


           

            data.rowIndex = new int[unSym_nnz];
            data.colIndex = new int[unSym_nnz];
            data.values = new double[unSym_nnz];
            data.nnz = unSym_nnz;
            // copy values to arrays
            int rowCur = 0;
            data.colIndex[0] = 0;
            foreach (List<SparseMatrix.Element> col in A.Columns)
            {
                foreach (SparseMatrix.Element e in col)
                {
                    if (e.value != 0)
                    {
                        data.rowIndex[rowCur] = e.i;
                        data.colIndex[rowCur] = e.j;
                        data.values[rowCur] = e.value;
                        rowCur++;
                    }
                }

            }



            return data;
        }
Exemple #7
0
        public TripletArraryData ConvertToTripletArrayData(SparseMatrix A)
        {
            TripletArraryData data = new TripletArraryData();
            switch (SolverType)
            {

                case EnumSolver.UmfpackLU:
                    data = ConvertToDataUnSym(A);
                    break;
                case EnumSolver.SuperLULU:
                    data = ConvertToDataUnSym(A);
                    break;
                case EnumSolver.CholmodCholesky:
                    data = ConvertToDataSymU(A);
                    break;
                case EnumSolver.SPQRLeastNormal:
                    data = ConvertToDataUnSym(A);
                    break;
                case EnumSolver.SPQRLeastSqure:
                    data = ConvertToDataUnSym(A);
                    break;
            }

            return data;
        }