简体   繁体   中英

Asserting equality of two armadillo cx_mat matrices using CPPUNIT

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.

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 .

您现在可以使用roximate_equal函数。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM