public static Matrix Zeros(int colsize, int rowsize) { if (Zeros_Selftest) { Zeros_Selftest = false; HDebug.Assert(Matrix.Zeros(3, 2).IsZero()); HDebug.Assert(Matrix.Zeros(100, 100).IsZero()); } if ((colsize < 10) && (rowsize < 10)) { return(MatrixByArr.Zeros(colsize, rowsize)); } return(MatrixByColRow.Zeros(colsize, rowsize)); }
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)); }
public static Matrix Ones(int colsize, int rowsize, double mul) { if (Zeros_Selftest) { Zeros_Selftest = false; Matrix tm0 = new double[2, 2] { { 1, 1 }, { 1, 1 } }; Matrix tm1 = tm0 * 1.1; HDebug.Assert((tm0 - Ones(2, 2)).IsZero()); HDebug.Assert((tm1 - Ones(2, 2, 1.1)).IsZero()); HDebug.Assert((Zeros(10, 10) - Ones(10, 10, 0)).IsZero()); } Matrix mat = null; if ((colsize < 10) && (rowsize < 10)) { mat = MatrixByArr.Zeros(colsize, rowsize); } else { mat = MatrixByColRow.Zeros(colsize, rowsize); } if (mul == 0) { return(mat); } for (int c = 0; c < colsize; c++) { for (int r = 0; r < rowsize; r++) { mat[c, r] = mul; } } return(mat); }