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

Function qrTester

test/qr_dense.cpp:90–137  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

88
89template<typename T>
90void qrTester(const int m, const int n, double eps) {
91 try {
92 SUPPORTED_TYPE_CHECK(T);
93 LAPACK_ENABLED_CHECK();
94
95#if 1
96 array in = cpu_randu<T>(dim4(m, n));
97#else
98 array in = randu(m, n, (dtype)dtype_traits<T>::af_type);
99#endif
100
101 //! [ex_qr_unpacked]
102 array q, r, tau;
103 qr(q, r, tau, in);
104 //! [ex_qr_unpacked]
105
106 array qq = matmul(q, q.H());
107 array ii = identity(qq.dims(), qq.type());
108
109 ASSERT_NEAR(0, max<double>(abs(real(qq - ii))), eps);
110 ASSERT_NEAR(0, max<double>(abs(imag(qq - ii))), eps);
111
112 //! [ex_qr_recon]
113 array re = matmul(q, r);
114 //! [ex_qr_recon]
115
116 ASSERT_NEAR(0, max<double>(abs(real(re - in))), eps);
117 ASSERT_NEAR(0, max<double>(abs(imag(re - in))), eps);
118
119 //! [ex_qr_packed]
120 array out = in.copy();
121 array tau2;
122 qrInPlace(tau2, out);
123 //! [ex_qr_packed]
124
125 array r2 = upper(out);
126
127 ASSERT_NEAR(0, max<double>(abs(real(tau - tau2))), eps);
128 ASSERT_NEAR(0, max<double>(abs(imag(tau - tau2))), eps);
129
130 ASSERT_NEAR(0, max<double>(abs(real(r2 - r))), eps);
131 ASSERT_NEAR(0, max<double>(abs(imag(r2 - r))), eps);
132
133 } catch (exception& ex) {
134 cout << ex.what() << endl;
135 throw;
136 }
137}
138
139template<typename T>
140double eps();

Callers

nothing calls this directly

Calls 14

randuFunction · 0.85
qrInPlaceFunction · 0.85
upperFunction · 0.85
HMethod · 0.80
typeMethod · 0.80
absFunction · 0.70
realFunction · 0.70
imagFunction · 0.70
dim4Class · 0.50
qrFunction · 0.50
matmulFunction · 0.50
identityFunction · 0.50

Tested by

no test coverage detected