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

Function solveTriangleTester

test/solve_dense.cpp:121–171  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

119
120template<typename T>
121void solveTriangleTester(const int n, const int k, bool is_upper, double eps,
122 int targetDevice = -1) {
123 if (targetDevice >= 0) setDevice(targetDevice);
124
125 deviceGC();
126
127 SUPPORTED_TYPE_CHECK(T);
128 LAPACK_ENABLED_CHECK();
129
130#if 1
131 array A = cpu_randu<T>(dim4(n, n));
132 array X0 = cpu_randu<T>(dim4(n, k));
133#else
134 array A = randu(n, n, (dtype)dtype_traits<T>::af_type);
135 array X0 = randu(n, k, (dtype)dtype_traits<T>::af_type);
136#endif
137
138 array L, U, pivot;
139 lu(L, U, pivot, A);
140
141 array AT = is_upper ? U : L;
142 array B0 = matmul(AT, X0);
143 array X1;
144
145 if (is_upper) {
146 //! [ex_solve_upper]
147 array X = solve(AT, B0, AF_MAT_UPPER);
148 //! [ex_solve_upper]
149
150 X1 = X;
151 } else {
152 //! [ex_solve_lower]
153 array X = solve(AT, B0, AF_MAT_LOWER);
154 //! [ex_solve_lower]
155
156 X1 = X;
157 }
158
159 array B1 = matmul(AT, X1);
160
161 ASSERT_NEAR(
162 0,
163 sum<typename dtype_traits<T>::base_type>(af::abs(real(B0 - B1))) /
164 (n * k),
165 eps);
166 ASSERT_NEAR(
167 0,
168 sum<typename dtype_traits<T>::base_type>(af::abs(imag(B0 - B1))) /
169 (n * k),
170 eps);
171}
172
173template<typename T>
174class Solve : public ::testing::Test {};

Callers

nothing calls this directly

Calls 10

deviceGCFunction · 0.85
randuFunction · 0.85
absFunction · 0.70
realFunction · 0.70
imagFunction · 0.70
setDeviceFunction · 0.50
dim4Class · 0.50
luFunction · 0.50
matmulFunction · 0.50
solveFunction · 0.50

Tested by

no test coverage detected