// Check for equality. // Return number of mismatches greater than epsilon. virtual idx_t compare(const GenericGridBase<T>* ref, T epsilon, int maxPrint = 0, std::ostream& os = std::cerr) const { auto ref1 = dynamic_cast<const GenericGrid1d*>(ref); if (!ref1) { os << "** type mismatch against GenericGrid1d." << endl; return 1; } // Quick check for errors. idx_t errs = count_diffs(*ref, epsilon); // Run detailed comparison if any errors found. if (errs > 0 && maxPrint) { int p = 0; for (idx_t i1 = 0; i1 < get_d1(); i1++) { T te = (*this)(i1); T re = (*ref1)(i1); if (!within_tolerance(te, re, epsilon)) { p++; if (p < maxPrint) os << "** mismatch at (" << i1 << "): " << te << " != " << re << std::endl; else if (p == maxPrint) os << "** Additional errors not printed." << std::endl; else goto done; } } } done: return errs; }
/* ********************************************************** */ void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { int lenx, leny, maxlag, a, b, c, bb, offset; double *x, *y, *output; /* ************* ACCESS MATLAB VARIABLES ************* */ lenx = mxGetN(prhs[0]); leny = mxGetN(prhs[1]); /* Get a handle to the input array. */ x = (double *) mxGetPr(prhs[0]); y = (double *) mxGetPr(prhs[1]); maxlag = (int) mxGetScalar(prhs[2]); /* Create an array to hold the output. */ plhs[0] = mxCreateNumericMatrix(1, 2*maxlag+1, mxDOUBLE_CLASS, mxREAL); output = (double *) mxGetPr(plhs[0]); /* ********************* COMPUTE ********************* */ count_diffs(x, lenx, y, leny, output, maxlag); /* ********************* CLEAN UP ******************** */ }
// Check for equality. // Return number of mismatches greater than epsilon. virtual idx_t compare(const GenericGridBase<T>* ref, T epsilon, int maxPrint = 0, std::ostream& os = std::cerr) const { auto ref1 = dynamic_cast<const GenericGrid0d*>(ref); if (!ref1) { os << "** type mismatch against GenericGrid0d." << endl; return 1; } // Quick check for errors. idx_t errs = count_diffs(*ref, epsilon); // Run detailed comparison if any errors found. if (errs > 0 && maxPrint) { T te = (*this)(); T re = (*ref1)(); if (!within_tolerance(te, re, epsilon)) { os << "** scalar mismatch: " << te << " != " << re << std::endl; } } return errs; }