| 33 | |
| 34 | template<typename T> |
| 35 | void choleskyTester(const int n, double eps, bool is_upper) { |
| 36 | SUPPORTED_TYPE_CHECK(T); |
| 37 | LAPACK_ENABLED_CHECK(); |
| 38 | |
| 39 | dtype ty = (dtype)dtype_traits<T>::af_type; |
| 40 | |
| 41 | // Prepare positive definite matrix |
| 42 | #if 1 |
| 43 | array a = cpu_randu<T>(dim4(n, n)); |
| 44 | #else |
| 45 | array a = randu(n, n, ty); |
| 46 | #endif |
| 47 | array b = 10 * n * identity(n, n, ty); |
| 48 | array in = matmul(a.H(), a) + b; |
| 49 | |
| 50 | //! [ex_chol_reg] |
| 51 | array out; |
| 52 | cholesky(out, in, is_upper); |
| 53 | //! [ex_chol_reg] |
| 54 | |
| 55 | array re = is_upper ? matmul(out.H(), out) : matmul(out, out.H()); |
| 56 | |
| 57 | ASSERT_NEAR(0, max<typename dtype_traits<T>::base_type>(abs(real(in - re))), |
| 58 | eps); |
| 59 | ASSERT_NEAR(0, max<typename dtype_traits<T>::base_type>(abs(imag(in - re))), |
| 60 | eps); |
| 61 | |
| 62 | //! [ex_chol_inplace] |
| 63 | array in2 = in.copy(); |
| 64 | choleskyInPlace(in2, is_upper); |
| 65 | //! [ex_chol_inplace] |
| 66 | |
| 67 | array out2 = is_upper ? upper(in2) : lower(in2); |
| 68 | |
| 69 | ASSERT_NEAR(0, |
| 70 | max<typename dtype_traits<T>::base_type>(abs(real(out2 - out))), |
| 71 | eps); |
| 72 | ASSERT_NEAR(0, |
| 73 | max<typename dtype_traits<T>::base_type>(abs(imag(out2 - out))), |
| 74 | eps); |
| 75 | } |
| 76 | |
| 77 | template<typename T> |
| 78 | class Cholesky : public ::testing::Test {}; |
nothing calls this directly
no test coverage detected