-
Notifications
You must be signed in to change notification settings - Fork 550
Expand file tree
/
Copy pathinverse.cpp
More file actions
62 lines (50 loc) · 1.8 KB
/
inverse.cpp
File metadata and controls
62 lines (50 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*******************************************************
* Copyright (c) 2014, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
* http://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
#include <backend.hpp>
#include <common/ArrayInfo.hpp>
#include <common/err_common.hpp>
#include <handle.hpp>
#include <inverse.hpp>
#include <af/array.h>
#include <af/defines.h>
#include <af/lapack.h>
using detail::cdouble;
using detail::cfloat;
template<typename T>
static inline af_array inverse(const af_array in) {
return getHandle(inverse<T>(getArray<T>(in)));
}
af_err af_inverse(af_array* out, const af_array in, const af_mat_prop options) {
try {
const ArrayInfo& i_info = getInfo(in);
if (i_info.ndims() > 2) {
AF_ERROR("solve can not be used in batch mode", AF_ERR_BATCH);
}
af_dtype type = i_info.getType();
if (options != AF_MAT_NONE) {
AF_ERROR("Using this property is not yet supported in inverse",
AF_ERR_NOT_SUPPORTED);
}
DIM_ASSERT(
1, i_info.dims()[0] == i_info.dims()[1]); // Only square matrices
ARG_ASSERT(1, i_info.isFloating()); // Only floating and complex types
af_array output;
if (i_info.ndims() == 0) { return af_retain_array(out, in); }
switch (type) {
case f32: output = inverse<float>(in); break;
case f64: output = inverse<double>(in); break;
case c32: output = inverse<cfloat>(in); break;
case c64: output = inverse<cdouble>(in); break;
default: TYPE_ERROR(1, type);
}
std::swap(*out, output);
}
CATCHALL;
return AF_SUCCESS;
}