public static void SelfTest() { if (HDebug.Selftest()) { Random rand = new Random(0); int colblksize = 3; int rowblksize = 10; int layersize = 3; var mat = Matrix.Zeros(colblksize * 3, rowblksize * 3); var hess = new HessMatrixLayeredArray(colblksize * 3, rowblksize * 3, layersize); HDebug.Assert(mat.ColSize == hess.ColSize); HDebug.Assert(mat.RowSize == hess.RowSize); int count = mat.ColSize * mat.RowSize * 10; for (int i = 0; i < count; i++) { int c = rand.NextInt(0, colblksize * 3 - 1); int r = rand.NextInt(0, rowblksize * 3 - 1); double v = rand.NextDouble(); mat[c, r] = v; hess[c, r] = v; HDebug.AssertTolerance(double.Epsilon, (mat - hess).ToArray()); } for (int i = 0; i < 700; i++) { int c = rand.NextInt(0, colblksize * 3 - 1); int r = rand.NextInt(0, rowblksize * 3 - 1); double v = 0; mat[c, r] = v; hess[c, r] = v; HDebug.AssertTolerance(double.Epsilon, (mat - hess).ToArray()); } } }
public HessMatrixLayeredArray CloneT() { HessMatrixLayeredArray clone = new HessMatrixLayeredArray(ColSize, RowSize, layersize); foreach (var bc_br_bval in EnumBlocks()) { int bc = bc_br_bval.Item1; int br = bc_br_bval.Item2; var bval = bc_br_bval.Item3; clone.SetBlock(bc, br, bval.CloneT()); } return(clone); }
public static HessMatrixLayeredArray ZerosHessMatrixLayeredArray(int colsize, int rowsize, int layersize) { if (ZerosSparse_selftest) { ZerosSparse_selftest = false; HessMatrixLayeredArray tmat = ZerosHessMatrixLayeredArray(300, 300, layersize); bool bzero = true; for (int c = 0; c < tmat.ColSize; c++) { for (int r = 0; r < tmat.ColSize; r++) { if (tmat[c, r] != 0) { bzero = false; } } } HDebug.Assert(bzero); } HessMatrixLayeredArray mat = new HessMatrixLayeredArray(colsize, rowsize, layersize); return(mat); }