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

Function solve

src/backend/cpu/solve.cpp:262–323  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

260
261template<typename T>
262Array<T> solve(const Array<T> &a, const Array<T> &b,
263 const af_mat_prop options) {
264 if (options & AF_MAT_UPPER || options & AF_MAT_LOWER) {
265 return triangleSolve<T>(a, b, options);
266 }
267
268#ifdef AF_USE_MKL_BATCH
269 if (a.dims()[2] > 1 || a.dims()[3] > 1) {
270 return generalSolveBatched(a, b, options);
271 }
272#endif
273
274 const dim4 NullShape(0, 0, 0, 0);
275
276 dim4 aDims = a.dims();
277 int batchz = aDims[2];
278 int batchw = aDims[3];
279
280 int M = aDims[0];
281 int N = aDims[1];
282 int K = b.dims()[1];
283
284 Array<T> A = copyArray<T>(a);
285
286 dim4 endPadding(max(M, N) - b.dims()[0], K - b.dims()[1], 0, 0);
287 Array<T> B = (endPadding == NullShape
288 ? copyArray(b)
289 : padArrayBorders(b, NullShape, endPadding, AF_PAD_ZERO));
290
291 for (int i = 0; i < batchw; i++) {
292 for (int j = 0; j < batchz; j++) {
293 Param<T> pA(A.get() + A.strides()[2] * j + A.strides()[3] * i,
294 A.dims(), A.strides());
295 Param<T> pB(B.get() + B.strides()[2] * j + B.strides()[3] * i,
296 B.dims(), B.strides());
297 if (M == N) {
298 Array<int> pivot = createEmptyArray<int>(dim4(N, 1, 1));
299
300 auto func = [](Param<T> A, Param<T> B, Param<int> pivot, int N,
301 int K) {
302 gesv_func<T>()(AF_LAPACK_COL_MAJOR, N, K, A.get(),
303 A.strides(1), pivot.get(), B.get(),
304 B.strides(1));
305 };
306 getQueue().enqueue(func, pA, pB, pivot, N, K);
307 } else {
308 auto func = [=](Param<T> A, Param<T> B, int M, int N, int K) {
309 int sM = A.dims(0);
310 int sN = A.dims(1);
311
312 gels_func<T>()(AF_LAPACK_COL_MAJOR, 'N', M, N, K, A.get(),
313 A.strides(1), B.get(), max(sM, sN));
314 };
315 getQueue().enqueue(func, pA, pB, M, N, K);
316 }
317 }
318 }
319

Callers 1

inverseFunction · 0.70

Calls 11

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

Tested by

no test coverage detected