MCPcopy Create free account
hub / github.com/arrayfire/arrayfire / choleskyTester

Function choleskyTester

test/cholesky_dense.cpp:35–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33
34template<typename T>
35void 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
77template<typename T>
78class Cholesky : public ::testing::Test {};

Callers

nothing calls this directly

Calls 13

randuFunction · 0.85
choleskyInPlaceFunction · 0.85
upperFunction · 0.85
lowerFunction · 0.85
HMethod · 0.80
absFunction · 0.70
realFunction · 0.70
imagFunction · 0.70
dim4Class · 0.50
identityFunction · 0.50
matmulFunction · 0.50
choleskyFunction · 0.50

Tested by

no test coverage detected