tensor-0.1.0
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Enumerator Groups Pages
fftw.cc
1 // -*- mode: c++; fill-column: 80; c-basic-offset: 2; indent-tabs-mode: nil -*-
2 /*
3  Copyright (c) 2010-2013 Juan Jose Garcia Ripoll
4 
5  Tensor is free software; you can redistribute it and/or modify it
6  under the terms of the GNU Library General Public License as published
7  by the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Library General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 /* MULTIDIMENSIONAL FAST FOURIER TRANSFORM */
21 
22 #include <tensor/fftw.h>
23 #include <fftw3.h>
24 #include "fftw_common.hpp"
25 
26 namespace tensor {
27 
28  const CTensor
29  fftw(const CTensor &in, int direction)
30  {
31  CTensor out(in.dimensions());
32 
33  fftw_complex *pin =
34  const_cast<fftw_complex*>
35  (reinterpret_cast<const fftw_complex*> (in.begin()));
36  fftw_complex *pout = reinterpret_cast<fftw_complex*> (out.begin());
37  do_fftw(pin, pout, in.dimensions(), direction);
38 
39  return out;
40  }
41 
42  const CTensor
43  fftw(const CTensor& in, index dim, int direction) {
44  assert(dim >=0 && dim < in.rank());
45  CTensor out(in.dimensions());
46 
47  fftw_complex *pin =
48  const_cast<fftw_complex*>
49  (reinterpret_cast<const fftw_complex*> (in.begin()));
50  fftw_complex *pout = reinterpret_cast<fftw_complex*> (out.begin());
51  do_fftw(pin, pout, dim, in.dimensions(), direction);
52 
53  return out;
54  }
55 
56  const CTensor
57  fftw(const CTensor& in, const Booleans& convert, int direction) {
58  assert(convert.size() == in.rank());
59  CTensor out(in.dimensions());
60 
61  fftw_complex *pin =
62  const_cast<fftw_complex*>
63  (reinterpret_cast<const fftw_complex*> (in.begin()));
64  fftw_complex *pout = reinterpret_cast<fftw_complex*> (out.begin());
65  do_fftw(pin, pout, convert, in.dimensions(), direction);
66 
67  return out;
68  }
69 
70 } // namespace tensor