void writeAsciiMatrix(const std::string& fname, const Math::Matrix<T,P,S>& M, const std::string& meta, const bool trans = false) { Math::Range start(0,0); Math::Range end(M.rows(), M.cols()); std::ofstream ofs(fname.c_str()); if (!ofs.is_open()) throw(std::runtime_error("Cannot open " + fname + " for writing.")); MatrixWriteImpl<T,P,S,internal::BasicMatrixFormatter<T> >::write(ofs, M, meta, start, end, trans); }
void TestMatrix::runSubTest8(double& res, double& expected, std::string& subTestName) { expected = 1; subTestName = "simple_invert"; #ifdef COSMO_LAPACK Math::Matrix<double> mat(2, 2); mat(0, 0) = 1; mat(0, 1) = 2; mat(1, 0) = 3; mat(1, 1) = 4; mat.writeIntoTextFile("test_files/matrix_test_8_original.txt"); Math::Matrix<double> invMat; mat.getInverse(&invMat); invMat.writeIntoTextFile("test_files/matrix_test_8_inverse.txt"); Math::Matrix<double> prod = invMat * mat; prod.writeIntoTextFile("test_files/matrix_test_8_product.txt"); res = 1; for(int i = 0; i < prod.rows(); ++i) { for(int j = 0; j < prod.cols(); ++j) { if(i == j) { if(!Math::areEqual(prod(i, j), 1.0, 1e-5)) { output_screen("FAIL! Diagonal element " << i << " must be 1 but it is " << prod(i, j) << std::endl); res = 0; } } else { if(!Math::areEqual(prod(i, j), 0.0, 1e-5)) { output_screen("FAIL! Non-diagonal element " << i << " " << j << " must be 0 but it is " << prod(i, j) << std::endl); res = 0; } } } } #else output_screen_clean("This test (below) is skipped because Cosmo++ has not been linked to lapack" << std::endl); res = 1; #endif }