Accord.Math.ComplexMatrix.IsEqual C# (CSharp) Method

IsEqual() public static method

Compares two matrices for equality, considering an acceptance threshold.
public static IsEqual ( this objA, Complex objB, double threshold ) : bool
objA this
objB Complex
threshold double
return bool
        public static bool IsEqual(this Complex[][] objA, Complex[][] objB, double threshold)
        {
            if (objA == null && objB == null) return true;
            if (objA == null) throw new ArgumentNullException("objA");
            if (objB == null) throw new ArgumentNullException("objB");

            for (int i = 0; i < objA.Length; i++)
            {
                for (int j = 0; j < objA[i].Length; j++)
                {
                    double xr = objA[i][j].Real;
                    double yr = objB[i][j].Real;
                    double xi = objA[i][j].Imaginary;
                    double yi = objB[i][j].Imaginary;

                    if (Math.Abs(xr - yr) > threshold || (Double.IsNaN(xr) ^ Double.IsNaN(yr)))
                        return false;

                    if (Math.Abs(xi - yi) > threshold || (Double.IsNaN(xr) ^ Double.IsNaN(yr)))
                        return false;
                }
            }
            return true;
        }