Line data Source code
1 : /** 2 : * @file test_JacobiPreconditioner.cpp 3 : * 4 : * @brief Tests for the JacobiPreconditioner class 5 : * 6 : * @author Michael Loipführer - initial code 7 : */ 8 : 9 : #include <doctest/doctest.h> 10 : 11 : #include <VolumeDescriptor.h> 12 : #include "Logger.h" 13 : #include "JacobiPreconditioner.h" 14 : #include "testHelpers.h" 15 : 16 : using namespace elsa; 17 : using namespace doctest; 18 : 19 : TEST_SUITE_BEGIN("problems"); 20 : 21 : template <template <typename> typename T, typename data_t> 22 : constexpr data_t return_data_t(const T<data_t>&); 23 : 24 : TYPE_TO_STRING(JacobiPreconditioner<float>); 25 : TYPE_TO_STRING(JacobiPreconditioner<double>); 26 : 27 : TEST_CASE_TEMPLATE("JacobiPreconditioner: Testing standard use cases", data_t, float, double) 28 4 : { 29 : // Set seed for Eigen Matrices! 30 4 : srand((unsigned int) 666); 31 : 32 : // no log spamming in tests 33 4 : Logger::setLevel(Logger::LogLevel::OFF); 34 : 35 4 : GIVEN("a simple linear operator") 36 4 : { 37 4 : IndexVector_t numCoeff(2); 38 4 : numCoeff << 13, 24; 39 4 : VolumeDescriptor dd(numCoeff); 40 : 41 4 : Eigen::Matrix<data_t, -1, 1> bVec(dd.getNumberOfCoefficients()); 42 4 : bVec.setRandom(); 43 4 : bVec = bVec.cwiseAbs(); 44 4 : Scaling<data_t> scalingOp{dd, DataContainer<data_t>{dd, bVec}}; 45 : 46 4 : WHEN("setting up a Jacobi Preconditioner") 47 4 : { 48 4 : JacobiPreconditioner<data_t> preconditioner{scalingOp, false}; 49 : 50 4 : THEN("the clone works correctly") 51 4 : { 52 2 : auto preconditionerClone = preconditioner.clone(); 53 : 54 2 : REQUIRE_NE(preconditionerClone.get(), &preconditioner); 55 2 : REQUIRE_EQ(*preconditionerClone, preconditioner); 56 2 : } 57 : 58 4 : THEN("the preconditioner actually represents the diagonal of the operator") 59 4 : { 60 : 61 2 : DataContainer<data_t> e(scalingOp.getDomainDescriptor()); 62 2 : e = 0; 63 2 : DataContainer<data_t> diag(scalingOp.getDomainDescriptor()); 64 626 : for (index_t i = 0; i < e.getSize(); i++) { 65 624 : e[i] = 1; 66 624 : REQUIRE_UNARY(checkApproxEq(preconditioner.apply(e), scalingOp.apply(e))); 67 624 : e[i] = 0; 68 624 : } 69 2 : } 70 4 : } 71 4 : } 72 4 : } 73 : 74 : TEST_SUITE_END();