forked from hunter-packages/arrayfire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinverse_dense.cpp
More file actions
66 lines (57 loc) · 1.9 KB
/
inverse_dense.cpp
File metadata and controls
66 lines (57 loc) · 1.9 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
63
64
65
66
/*******************************************************
* 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 <gtest/gtest.h>
#include <arrayfire.h>
#include <af/dim4.hpp>
#include <af/defines.h>
#include <af/traits.hpp>
#include <vector>
#include <iostream>
#include <complex>
#include <string>
#include <testHelpers.hpp>
using std::vector;
using std::string;
using std::cout;
using std::endl;
using af::cfloat;
using af::cdouble;
///////////////////////////////// CPP ////////////////////////////////////
//
template<typename T>
void inverseTester(const int m, const int n, const int k, double eps)
{
if (noDoubleTests<T>()) return;
if (noLAPACKTests()) return;
#if 1
af::array A = cpu_randu<T>(af::dim4(m, n));
#else
af::array A = af::randu(m, n, (af::dtype)af::dtype_traits<T>::af_type);
#endif
//! [ex_inverse]
af::array IA = inverse(A);
af::array I = af::matmul(A, IA);
//! [ex_inverse]
af::array I2 = af::identity(m, n, (af::dtype)af::dtype_traits<T>::af_type);
ASSERT_NEAR(0, af::max<double>(af::abs(real(I - I2))), eps);
ASSERT_NEAR(0, af::max<double>(af::abs(imag(I - I2))), eps);
}
#define INVERSE_TESTS(T, eps) \
TEST(INVERSE, T##Square) \
{ \
inverseTester<T>(1000, 1000, 100, eps); \
} \
TEST(INVERSE, T##SquareMultiple) \
{ \
inverseTester<T>(2048, 2048, 512, eps); \
} \
INVERSE_TESTS(float, 0.01)
INVERSE_TESTS(double, 1E-5)
INVERSE_TESTS(cfloat, 0.01)
INVERSE_TESTS(cdouble, 1E-5)