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

Function solve

src/backend/opencl/cpu/cpu_solve.cpp:249–301  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

247
248template<typename T>
249Array<T> solve(const Array<T> &a, const Array<T> &b,
250 const af_mat_prop options) {
251 if (options & AF_MAT_UPPER || options & AF_MAT_LOWER) {
252 return triangleSolve<T>(a, b, options);
253 }
254
255#ifdef AF_USE_MKL_BATCH
256 if (a.dims()[2] > 1 || a.dims()[3] > 1) {
257 return generalSolveBatched(a, b, options);
258 }
259#endif
260
261 const dim4 NullShape(0, 0, 0, 0);
262
263 dim4 aDims = a.dims();
264 int batchz = aDims[2];
265 int batchw = aDims[3];
266
267 int M = a.dims()[0];
268 int N = a.dims()[1];
269 int K = b.dims()[1];
270
271 Array<T> A = copyArray<T>(a);
272 dim4 endPadding(max(M, N) - b.dims()[0], K - b.dims()[1], 0, 0);
273 Array<T> B = (endPadding == NullShape
274 ? copyArray(b)
275 : padArrayBorders(b, NullShape, endPadding, AF_PAD_ZERO));
276
277 mapped_ptr<T> aPtr = A.getMappedPtr();
278 mapped_ptr<T> bPtr = B.getMappedPtr();
279
280 for (int i = 0; i < batchw; i++) {
281 for (int j = 0; j < batchz; j++) {
282 auto pA = aPtr.get() + A.strides()[2] * j + A.strides()[3] * i;
283 auto pB = bPtr.get() + B.strides()[2] * j + B.strides()[3] * i;
284
285 if (M == N) {
286 std::vector<int> pivot(N);
287 gesv_func<T>()(AF_LAPACK_COL_MAJOR, N, K, pA, A.strides()[1],
288 &pivot.front(), pB, B.strides()[1]);
289 } else {
290 int sM = a.strides()[1];
291 int sN = a.strides()[2] / sM;
292
293 gels_func<T>()(AF_LAPACK_COL_MAJOR, 'N', M, N, K, pA,
294 A.strides()[1], pB, max(sM, sN));
295 }
296 }
297 }
298 if (M != N) { B.resetDims(dim4(N, K, B.dims()[2], B.dims()[3])); }
299
300 return B;
301}
302
303#define INSTANTIATE_SOLVE(T) \
304 template Array<T> solve<T>(const Array<T> &a, const Array<T> &b, \

Callers

nothing calls this directly

Calls 10

generalSolveBatchedFunction · 0.70
maxFunction · 0.50
copyArrayFunction · 0.50
padArrayBordersFunction · 0.50
dim4Class · 0.50
dimsMethod · 0.45
getMappedPtrMethod · 0.45
getMethod · 0.45
stridesMethod · 0.45
resetDimsMethod · 0.45

Tested by

no test coverage detected