23 #ifndef NDARRAY_FFT_FourierOps_h_INCLUDED
24 #define NDARRAY_FFT_FourierOps_h_INCLUDED
32 #include <boost/noncopyable.hpp>
44 template <
typename T,
int N>
50 std::complex<T>
const & factor,
51 ArrayRef<std::complex<T>,N,C>
const & array,
52 int const real_last_dim
54 typename ArrayRef<std::complex<T>,N,C>::Iterator
iter = array.begin();
55 T u = -2.0 * M_PI * (*offset) / array.size();
56 int kMid = (array.size() + 1) / 2;
57 for (
int k = 0; k < kMid; ++k, ++
iter) {
59 *iter, real_last_dim);
61 if (array.size() % 2 == 0) {
66 for (
int k_n = kMid - array.size(); k_n < 0; ++k_n, ++
iter) {
68 *iter, real_last_dim);
73 static void differentiate(
int m, ArrayRef<std::complex<T>,N,C>
const & array,
int const real_last_dim) {
74 typename ArrayRef<std::complex<T>,N,C>::Iterator iter = array.begin();
75 int kMid = (array.size() + 1) / 2;
76 T u = 2.0 * M_PI / array.size();
77 for (
int k = 0; k < kMid; ++k, ++
iter) {
78 if (m == N) (*iter) *= std::complex<T>(
static_cast<T
>(0), u * T(k));
81 if (array.size() % 2 == 0) {
82 (*iter) =
static_cast<T
>(0);
86 for (
int k_n = kMid - array.size(); k_n < 0; ++k_n, ++
iter) {
87 if (m == N) (*iter) *= std::complex<T>(
static_cast<T
>(0), u * T(k_n));
99 struct FourierOps<T,1> {
104 std::complex<T>
const & factor,
105 ArrayRef<std::complex<T>,1,C>
const & array,
106 int const real_last_dim
108 typename ArrayRef<std::complex<T>,1,C>::Iterator iter = array.begin();
109 T u = -2.0 * M_PI * (*offset) / real_last_dim;
110 int kMid = (real_last_dim + 1) / 2;
111 for (
int k = 0; k < kMid; ++k, ++
iter) {
112 (*iter) *= factor * std::polar(1.0, u * T(k));
114 if (real_last_dim % 2 == 0) {
115 (*iter) *= factor * std::cos(u * kMid);
121 static void differentiate(
int m, ArrayRef<std::complex<T>,1,C>
const & array,
int const real_last_dim) {
122 typename ArrayRef<std::complex<T>,1,C>::Iterator iter = array.begin();
123 int kMid = (real_last_dim + 1) / 2;
125 T u = 2.0 * M_PI / real_last_dim;
126 for (
int k = 0; k < kMid; ++k, ++
iter) {
127 (*iter) *= std::complex<T>(
static_cast<T
>(0), u * T(k));
130 if (real_last_dim % 2 == 0) {
131 array[kMid] =
static_cast<T
>(0);
145 template <
typename T,
int N,
int C>
148 Array<std::complex<T>,N,C>
const & array,
149 int const real_last_dim
153 static_cast< std::complex<T>
>(1),
164 template <
typename T,
int N,
int C>
167 Array<std::complex<T>,N,C>
const & array,
168 int const real_last_dim
175 #endif // !NDARRAY_FFT_FourierOps_h_INCLUDED
void shift(Vector< T, N > const &offset, Array< std::complex< T >, N, C > const &array, int const real_last_dim)
Perform a Fourier-space translation transform.
void differentiate(int n, Array< std::complex< T >, N, C > const &array, int const real_last_dim)
Numerically differentiate the array in Fourier-space in the given dimension.
A fixed-size 1D array class.
iterator begin()
Return an iterator to the beginning of the Vector.
A multidimensional strided array.