Exemplo n.º 1
0
        public MatrixBySparseMatrix(int colsize, int rowsize, int blksize)
        {
            if (_SelfTest)
            {
                SelfTest();
            }

            this._ColSize = colsize;
            this._RowSize = rowsize;
            this.BlkSize  = blksize;
            //Func<MatrixByArr> GetZeroBlock = delegate() { return new double[blksize, blksize]; };
            int colblksize = (colsize % blksize == 0) ? (colsize / blksize) : (colsize / blksize + 1);
            int rowblksize = (rowsize % blksize == 0) ? (rowsize / blksize) : (rowsize / blksize + 1);

            //this.blkmatrix = new MatrixSparse<MatrixByArr>((colsize/blksize+1), (rowsize/blksize+1), GetZeroBlock);
            this.blkmatrix = new MatrixSparse <MatrixByArr>(colblksize, rowblksize, GetZeroBlock);
        }
Exemplo n.º 2
0
        ////////////////////////////////////////////////////////////////////////////////////
        // Serializable
        public MatrixBySparseMatrix(SerializationInfo info, StreamingContext ctxt)
        {
            this.BlkSize  = info.GetInt32("BlkSize");
            this._ColSize = info.GetInt32("_ColSize");
            this._RowSize = info.GetInt32("_RowSize");

            int colblksize = (ColSize % BlkSize == 0) ? (ColSize / BlkSize) : (ColSize / BlkSize + 1);
            int rowblksize = (RowSize % BlkSize == 0) ? (RowSize / BlkSize) : (RowSize / BlkSize + 1);

            this.blkmatrix = new MatrixSparse <MatrixByArr>(colblksize, rowblksize, GetZeroBlock);

            int block_num = info.GetInt32("block_num");

            int[]        block_Item1 = (int[]      )info.GetValue("block_Item1", typeof(int[]));
            int[]        block_Item2 = (int[]      )info.GetValue("block_Item2", typeof(int[]));
            double[, ][] block_Item3 = (double[, ][])info.GetValue("block_Item3", typeof(double[, ][]));
            block_num = block_Item1.Length;
            HDebug.Assert(block_num == block_Item1.Length);
            HDebug.Assert(block_num == block_Item2.Length);
            HDebug.Assert(block_Item3.GetLength(0) == BlkSize);
            HDebug.Assert(block_Item3.GetLength(1) == BlkSize);
            for (int c = 0; c < BlkSize; c++)
            {
                for (int r = 0; r < BlkSize; r++)
                {
                    HDebug.Assert(block_Item3[c, r].Length == block_num);
                }
            }
            for (int i = 0; i < block_num; i++)
            {
                int         bc   = block_Item1[i];
                int         br   = block_Item2[i];
                MatrixByArr bval = new double[BlkSize, BlkSize];
                for (int c = 0; c < BlkSize; c++)
                {
                    for (int r = 0; r < BlkSize; r++)
                    {
                        bval[c, r] = block_Item3[c, r][i];
                    }
                }
                SetBlock(bc, br, bval);
            }

            //throw new NotImplementedException();
        }
Exemplo n.º 3
0
        public MatrixSparse <T> GetSubMatrixExcept(int colremove, int rowremove)
        {
            MatrixSparse <T> submat = new MatrixSparse <T>(ColSize - 1, RowSize - 1, this.GetDefault);

            foreach (var c_r_val in EnumElements())
            {
                int c = c_r_val.Item1; if (c == colremove)
                {
                    continue;
                }
                int r = c_r_val.Item2; if (r == rowremove)
                {
                    continue;
                }
                T   val = c_r_val.Item3;
                int sc  = (c < colremove) ? c : (c - 1);
                int sr  = (r < rowremove) ? r : (r - 1);
                submat[sc, sr] = val;
            }
            return(submat);
        }
Exemplo n.º 4
0
        public MatrixSparse <T> GetSubMatrix(IList <int> colidxs, IList <int> rowidxs)
        {
            MatrixSparse <T> submat = new MatrixSparse <T>(colidxs.Count, rowidxs.Count, this.GetDefault);

            Dictionary <int, int> col_subcol = colidxs.HToDictionaryAsValueIndex();
            Dictionary <int, int> row_subrow = rowidxs.HToDictionaryAsValueIndex();

            foreach (var c_r_val in EnumElements())
            {
                int c = c_r_val.Item1; if (col_subcol.ContainsKey(c) == false)
                {
                    continue;
                }
                int r = c_r_val.Item2; if (row_subrow.ContainsKey(r) == false)
                {
                    continue;
                }
                T   val = c_r_val.Item3;
                int sc  = col_subcol[c];
                int sr  = row_subrow[r];
                submat[sc, sr] = val;
            }
            return(submat);
        }