Class CheckUtil


  • public class CheckUtil
    extends Object
    • Constructor Detail

      • CheckUtil

        public CheckUtil()
    • Method Detail

      • checkMmul

        public static boolean checkMmul​(INDArray first,
                                        INDArray second,
                                        double maxRelativeDifference,
                                        double minAbsDifference)
        Check first.mmul(second) using Apache commons math mmul. Float/double matrices only.
        Returns true if OK, false otherwise.
        Checks each element according to relative error (|a-b|/(|a|+|b|); however absolute error |a-b| must also exceed minAbsDifference for it to be considered a failure. This is necessary to avoid instability near 0: i.e., Nd4j mmul might return element of 0.0 (due to underflow on float) while Apache commons math mmul might be say 1e-30 or something (using doubles). Throws exception if matrices can't be multiplied Checks each element of the result. If
        Parameters:
        first - First matrix
        second - Second matrix
        maxRelativeDifference - Maximum relative error
        minAbsDifference - Minimum absolute difference for failure
        Returns:
        true if OK, false if result incorrect
      • checkGemm

        public static boolean checkGemm​(INDArray a,
                                        INDArray b,
                                        INDArray c,
                                        boolean transposeA,
                                        boolean transposeB,
                                        double alpha,
                                        double beta,
                                        double maxRelativeDifference,
                                        double minAbsDifference)
      • checkAdd

        public static boolean checkAdd​(INDArray first,
                                       INDArray second,
                                       double maxRelativeDifference,
                                       double minAbsDifference)
        Same as checkMmul, but for matrix addition
      • checkSubtract

        public static boolean checkSubtract​(INDArray first,
                                            INDArray second,
                                            double maxRelativeDifference,
                                            double minAbsDifference)
        Same as checkMmul, but for matrix subtraction
      • checkMulManually

        public static boolean checkMulManually​(INDArray first,
                                               INDArray second,
                                               double maxRelativeDifference,
                                               double minAbsDifference)
      • checkDivManually

        public static boolean checkDivManually​(INDArray first,
                                               INDArray second,
                                               double maxRelativeDifference,
                                               double minAbsDifference)
      • checkEntries

        public static boolean checkEntries​(org.apache.commons.math3.linear.RealMatrix rmResult,
                                           INDArray result,
                                           double maxRelativeDifference,
                                           double minAbsDifference)
      • checkEntries

        public static boolean checkEntries​(INDArray expected,
                                           INDArray actual,
                                           double maxRelativeDifference,
                                           double minAbsDifference)
      • convertToApacheMatrix

        public static org.apache.commons.math3.linear.RealMatrix convertToApacheMatrix​(INDArray matrix)
      • convertFromApacheMatrix

        public static INDArray convertFromApacheMatrix​(org.apache.commons.math3.linear.RealMatrix matrix,
                                                       DataType dataType)
      • printFailureDetails

        public static void printFailureDetails​(INDArray first,
                                               INDArray second,
                                               org.apache.commons.math3.linear.RealMatrix expected,
                                               INDArray actual,
                                               INDArray onCopies,
                                               String op)
      • printGemmFailureDetails

        public static void printGemmFailureDetails​(INDArray a,
                                                   INDArray b,
                                                   INDArray c,
                                                   boolean transposeA,
                                                   boolean transposeB,
                                                   double alpha,
                                                   double beta,
                                                   org.apache.commons.math3.linear.RealMatrix expected,
                                                   INDArray actual,
                                                   INDArray onCopies)
      • printMatrixFullPrecision

        public static void printMatrixFullPrecision​(INDArray matrix)
      • printNDArrayHeader

        public static void printNDArrayHeader​(INDArray array)
      • printApacheMatrix

        public static void printApacheMatrix​(org.apache.commons.math3.linear.RealMatrix matrix)