Question

I'm new to CPPUNIT. I have generated a matrix A of type cx_mat(complex double) using armadillo library and I have a reference(expected) matrix B of the same type. Please suggest a way to arrest using the matrices A and B and a delta(tolerance) of say 0.0001 in one-shot WITHOUT looping through the entire matrix.

If the above is not possible and if the only alternative is to use the CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE method in a for loop, then please provide me the correct syntax and header files for using the same.

Was it helpful?

Solution 2

It can be done with

bool Arma_test::Is_close(arma::cx_mat& X, arma::cx_mat& Y, double tol)
{
    // abs returns a mat type then max checks columns and returns a row_vec
    // max used again will return the biggest element in the row_vec
    bool close(false);
    if(arma::max(arma::max(arma::abs(X-Y))) < tol)
    {
        close = true;
    }
    return close;
}

See Armadillo Docs.

OTHER TIPS

You can now use the approx_equal function.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top