-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathconjugate_transposed.cpp
More file actions
69 lines (56 loc) · 2.12 KB
/
conjugate_transposed.cpp
File metadata and controls
69 lines (56 loc) · 2.12 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
67
68
69
#define MDSPAN_USE_PAREN_OPERATOR 1
#include "gtest/gtest.h"
#include <experimental/linalg>
#include <experimental/mdspan>
#include <complex>
#include <vector>
namespace {
using MDSPAN_IMPL_STANDARD_NAMESPACE::dynamic_extent;
using MDSPAN_IMPL_STANDARD_NAMESPACE::extents;
using MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan;
using std::experimental::linalg::conjugate_transposed;
TEST(conjugate_transposed, mdspan_complex_double)
{
using std::conj;
using real_t = double;
using scalar_t = std::complex<real_t>;
using matrix_dynamic_t =
mdspan<scalar_t, extents<std::size_t, dynamic_extent, dynamic_extent>>;
constexpr std::size_t dim = 5;
using matrix_static_t =
mdspan<scalar_t, extents<std::size_t, dim, dim>>;
constexpr std::size_t storageSize = std::size_t(dim*dim);
std::vector<scalar_t> A_storage (storageSize);
std::vector<scalar_t> B_storage (storageSize);
matrix_dynamic_t A (A_storage.data (), dim, dim);
matrix_static_t B (B_storage.data ());
for (std::size_t i = 0; i < dim; ++i) {
for (std::size_t j = 0; j < dim; ++j) {
const real_t i_val_re (real_t(i) + 1.0);
const scalar_t i_val (i_val_re, i_val_re);
const real_t j_val_re = real_t(j) + 1.0;
const scalar_t j_val (j_val_re, j_val_re);
const scalar_t val = i_val + real_t(dim) * j_val;
A(i,j) = val;
B(i,j) = -val;
}
}
auto A_h = conjugate_transposed (A);
auto B_h = conjugate_transposed (B);
for (std::size_t i = 0; i < dim; ++i) {
for (std::size_t j = 0; j < dim; ++j) {
const real_t i_val_re (real_t(i) + 1.0);
const scalar_t i_val (i_val_re, i_val_re);
const real_t j_val_re = real_t(j) + 1.0;
const scalar_t j_val (j_val_re, j_val_re);
const scalar_t val = i_val + real_t(dim) * j_val;
EXPECT_EQ( A(i,j), val );
EXPECT_EQ( B(i,j), -val );
EXPECT_EQ( scalar_t(A_h(j,i)), conj(val) );
EXPECT_EQ( scalar_t(B_h(j,i)), -conj(val) );
EXPECT_EQ( scalar_t(A_h(j,i)), conj(A(i,j)) );
EXPECT_EQ( scalar_t(B_h(j,i)), conj(B(i,j)) );
}
}
}
}