public static void print(Stream output, ZMatrix mat, string format) { string type = "dense64"; Console.WriteLine("Type = " + type + " complex , numRows = " + mat.getNumRows() + " , numCols = " + mat.getNumCols()); format += " "; Complex_F64 c = new Complex_F64(); for (int y = 0; y < mat.getNumRows(); y++) { for (int x = 0; x < mat.getNumCols(); x++) { mat.get(y, x, c); Console.Write(format, c.real, c.imaginary); if (x < mat.getNumCols() - 1) { Console.Write(" , "); } } Console.WriteLine(); } }
public static void assertEquals(ZMatrix A, ZMatrix B, double tol) { assertShape(A, B); Complex_F64 a = new Complex_F64(); Complex_F64 b = new Complex_F64(); for (int i = 0; i < A.getNumRows(); i++) { for (int j = 0; j < A.getNumCols(); j++) { A.get(i, j, a); B.get(i, j, b); assertTrue(!double.IsNaN(a.real) && !double.IsNaN(b.real), "Real At (" + i + "," + j + ") A = " + a.real + " B = " + b.real); assertTrue(!double.IsInfinity(a.real) && !double.IsInfinity(b.real), "Real At (" + i + "," + j + ") A = " + a.real + " B = " + b.real); assertTrue(Math.Abs(a.real - b.real) <= tol, "Real At (" + i + "," + j + ") A = " + a.real + " B = " + b.real); assertTrue(!double.IsNaN(a.imaginary) && !double.IsNaN(b.imaginary), "Img At (" + i + "," + j + ") A = " + a.imaginary + " B = " + b.imaginary); assertTrue(!double.IsInfinity(a.imaginary) && !double.IsInfinity(b.imaginary), "Img At (" + i + "," + j + ") A = " + a.imaginary + " B = " + b.imaginary); assertTrue(Math.Abs(a.imaginary - b.imaginary) <= tol, "Img At (" + i + "," + j + ") A = " + a.imaginary + " B = " + b.imaginary); } } }
/** * Checks to see if the provided matrix is within tolerance to an identity matrix. * * @param mat Matrix being examined. Not modified. * @param tol Tolerance. * @return True if it is within tolerance to an identify matrix. */ public static bool isIdentity(ZMatrix mat, double tol) { // see if the result is an identity matrix Complex_F64 c = new Complex_F64(); for (int i = 0; i < mat.getNumRows(); i++) { for (int j = 0; j < mat.getNumCols(); j++) { mat.get(i, j, c); if (i == j) { if (!(Math.Abs(c.real - 1) <= tol)) { return(false); } if (!(Math.Abs(c.imaginary) <= tol)) { return(false); } } else { if (!(Math.Abs(c.real) <= tol)) { return(false); } if (!(Math.Abs(c.imaginary) <= tol)) { return(false); } } } } return(true); }