Exemplo n.º 1
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;

        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public void ToCRS(out int[] rowPtr, out int[] colIndices, 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.ToCRS(out rowPtr, out colIndices, out values, out nnz);
        }
Exemplo n.º 4
0
        public void ToCRS(out int[] rowPtr, out int[] colIndices, 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.ToCRS(out rowPtr, out colIndices, out values, out nnz);

        }