Exemplo n.º 1
0
        public MatrixBySparseMatrix CloneT()
        {
            MatrixBySparseMatrix clone = new MatrixBySparseMatrix(_ColSize, _RowSize, BlkSize);

            foreach (var bc_br_bval in blkmatrix.EnumElements())
            {
                int         bc   = bc_br_bval.Item1;
                int         br   = bc_br_bval.Item2;
                MatrixByArr bval = bc_br_bval.Item3;

                clone.blkmatrix[bc, br] = bval.CloneT();
            }
            return(clone);
        }
Exemplo n.º 2
0
        public static void SelfTest()
        {
            if (_SelfTest == false)
            {
                return;
            }
            _SelfTest = false;
            MatrixBySparseMatrix mat = new MatrixBySparseMatrix(4, 4, 2);

            HDebug.AssertToleranceMatrix(0, mat - MatrixByArr.Zeros(4, 4));

            mat[0, 0] = mat[1, 1] = mat[2, 2] = mat[3, 3] = 1;
            HDebug.AssertToleranceMatrix(0, mat - LinAlg.Eye(4, 1));

            mat[0, 0] = mat[1, 1] = mat[2, 2] = mat[3, 3] = 0;
            HDebug.AssertToleranceMatrix(0, mat - MatrixByArr.Zeros(4, 4));
        }
Exemplo n.º 3
0
        public static MatrixBySparseMatrix ToSparseMatrix(this Matrix mat, int blksize)
        {
            if (mat is MatrixBySparseMatrix)
            {
                return((mat as MatrixBySparseMatrix).CloneT());
            }
            MatrixBySparseMatrix smat = new MatrixBySparseMatrix(mat.ColSize, mat.RowSize, blksize);

            for (int c = 0; c < mat.ColSize; c++)
            {
                for (int r = 0; r < mat.RowSize; r++)
                {
                    double val = mat[c, r];
                    if (val != 0)
                    {
                        smat[c, r] = val;
                    }
                }
            }
            return(smat);
        }