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

Function det

src/api/c/det.cpp:32–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30
31template<typename T>
32T det(const af_array a) {
33 using namespace detail;
34 const Array<T> A = getArray<T>(a);
35
36 const int num = A.dims()[0];
37
38 if (num == 0) {
39 T res = scalar<T>(1.0);
40 return res;
41 }
42
43 std::vector<T> hD(num);
44 std::vector<int> hP(num);
45
46 Array<T> D = createEmptyArray<T>(dim4());
47 Array<int> pivot = createEmptyArray<int>(dim4());
48
49 // Free memory as soon as possible
50 {
51 Array<T> A_copy = copyArray<T>(A);
52
53 Array<int> pivot = lu_inplace(A_copy, false);
54 copyData(&hP[0], pivot);
55
56 Array<T> D = diagExtract(A_copy, 0);
57 copyData(&hD[0], D);
58 }
59
60 bool is_neg = false;
61 T res = scalar<T>(is_neg ? -1 : 1);
62 for (int i = 0; i < num; i++) {
63 res = res * hD[i];
64 is_neg ^= (hP[i] != (i + 1));
65 }
66
67 if (is_neg) { res = res * scalar<T>(-1); }
68
69 return res;
70}
71
72af_err af_det(double *real_val, double *imag_val, const af_array in) {
73 try {

Callers

nothing calls this directly

Calls 5

lu_inplaceFunction · 0.70
copyDataFunction · 0.70
diagExtractFunction · 0.70
dim4Class · 0.50
dimsMethod · 0.45

Tested by

no test coverage detected