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

Function luTester

test/lu_dense.cpp:129–186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

127
128template<typename T>
129void luTester(const int m, const int n, double eps) {
130 SUPPORTED_TYPE_CHECK(T);
131 LAPACK_ENABLED_CHECK();
132
133#if 1
134 array a_orig = cpu_randu<T>(dim4(m, n));
135#else
136 array a_orig = randu(m, n, (dtype)dtype_traits<T>::af_type);
137#endif
138
139 //! [ex_lu_unpacked]
140 array l, u, pivot;
141 lu(l, u, pivot, a_orig);
142 //! [ex_lu_unpacked]
143
144 //! [ex_lu_recon]
145 array a_recon = matmul(l, u);
146 array a_perm = a_orig(pivot, span);
147 //! [ex_lu_recon]
148
149 ASSERT_NEAR(
150 0,
151 max<typename dtype_traits<T>::base_type>(abs(real(a_recon - a_perm))),
152 eps);
153 ASSERT_NEAR(
154 0,
155 max<typename dtype_traits<T>::base_type>(abs(imag(a_recon - a_perm))),
156 eps);
157
158 //! [ex_lu_packed]
159 array out = a_orig.copy();
160 array pivot2;
161 luInPlace(pivot2, out, false);
162 //! [ex_lu_packed]
163
164 //! [ex_lu_extract]
165 array l2 = lower(out, true);
166 array u2 = upper(out, false);
167 //! [ex_lu_extract]
168
169 ASSERT_EQ(count<uint>(pivot == pivot2), pivot.elements());
170
171 int mn = std::min(m, n);
172 l2 = l2(span, seq(mn));
173 u2 = u2(seq(mn), span);
174
175 array a_recon2 = matmul(l2, u2);
176 array a_perm2 = a_orig(pivot2, span);
177
178 ASSERT_NEAR(
179 0,
180 max<typename dtype_traits<T>::base_type>(abs(real(a_recon2 - a_perm2))),
181 eps);
182 ASSERT_NEAR(
183 0,
184 max<typename dtype_traits<T>::base_type>(abs(imag(a_recon2 - a_perm2))),
185 eps);
186}

Callers

nothing calls this directly

Calls 14

randuFunction · 0.85
luInPlaceFunction · 0.85
lowerFunction · 0.85
upperFunction · 0.85
seqClass · 0.85
absFunction · 0.70
realFunction · 0.70
imagFunction · 0.70
minFunction · 0.70
dim4Class · 0.50
luFunction · 0.50
matmulFunction · 0.50

Tested by

no test coverage detected