-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathhelper.cpp
More file actions
60 lines (50 loc) · 2.18 KB
/
Copy pathhelper.cpp
File metadata and controls
60 lines (50 loc) · 2.18 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
/*
* xtensor-fftw
* Copyright (c) 2017, Patrick Bos
* Distributed under the terms of the BSD 3-Clause License.
*
* The full license is in the file LICENSE, distributed with this software.
*/
#define _USE_MATH_DEFINES // for MSVC ("Math Constants are not defined in Standard C/C++")
#include <cmath> // M_PI
#include <xtensor/xarray.hpp>
#include <xtensor-fftw/helper.hpp>
#include "gtest/gtest.h"
TEST(helper, fftshift) {
xt::xarray<double> odd = {3, 4, 0, 1, 2};
xt::xarray<double> even = {3, 4, 5, 0, 1, 2};
xt::xarray<double> odd_range = xt::arange<double>(5);
xt::xarray<double> even_range = xt::arange<double>(6);
EXPECT_EQ(xt::fftw::fftshift(odd_range), odd);
EXPECT_EQ(xt::fftw::fftshift(even_range), even);
}
TEST(helper, ifftshift) {
xt::xarray<double> odd = {3, 4, 0, 1, 2};
xt::xarray<double> even = {3, 4, 5, 0, 1, 2};
EXPECT_EQ(xt::fftw::ifftshift(odd), xt::arange<double>(5));
EXPECT_EQ(xt::fftw::ifftshift(even), xt::arange<double>(6));
}
TEST(helper, fftfreq) {
xt::xarray<double> reference9 = {0., 1., 2., 3., 4., -4., -3., -2., -1.};
xt::xarray<double> reference10 = {0. , 0.04, 0.08, 0.12, 0.16, -0.2 , -0.16, -0.12, -0.08, -0.04};
EXPECT_EQ(xt::fftw::fftfreq(9, 1./9), reference9);
EXPECT_EQ(xt::fftw::fftfreq(10, 2.5), reference10);
}
TEST(helper, fftscale) {
xt::xarray<double> reference9 = {0., 1., 2., 3., 4., -4., -3., -2., -1.};
xt::xarray<double> reference10 = {0. , 0.04, 0.08, 0.12, 0.16, -0.2 , -0.16, -0.12, -0.08, -0.04};
EXPECT_EQ(xt::fftw::fftscale(9, 1./9), 2 * M_PI * reference9);
EXPECT_EQ(xt::fftw::fftscale(10, 2.5), 2 * M_PI * reference10);
}
TEST(helper, rfftfreq) {
xt::xarray<double> reference9 = {0., 1., 2., 3., 4.};
xt::xarray<double> reference10 = {0. , 0.04, 0.08, 0.12, 0.16, 0.2};
EXPECT_EQ(xt::fftw::rfftfreq(9, 1./9), reference9);
EXPECT_EQ(xt::fftw::rfftfreq(10, 2.5), reference10);
}
TEST(helper, rfftscale) {
xt::xarray<double> reference9 = {0., 1., 2., 3., 4.};
xt::xarray<double> reference10 = {0. , 0.04, 0.08, 0.12, 0.16, 0.2};
EXPECT_EQ(xt::fftw::rfftscale(9, 1./9), 2 * M_PI * reference9);
EXPECT_EQ(xt::fftw::rfftscale(10, 2.5), 2 * M_PI * reference10);
}