~ubuntu-branches/ubuntu/trusty/r-cran-rcpparmadillo/trusty

« back to all changes in this revision

Viewing changes to inst/include/armadillo_bits/fn_fft2.hpp

  • Committer: Package Import Robot
  • Author(s): Dirk Eddelbuettel
  • Date: 2013-09-29 16:03:43 UTC
  • mfrom: (1.1.7)
  • Revision ID: package-import@ubuntu.com-20130929160343-8ed4fww4vzoq8067
Tags: 0.3.920.1-1
* New upstream release

* debian/control: Tightened Build-Depends on r-cran-rcpp to (>= 0.10.5)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C) 2013 Conrad Sanderson
 
2
// Copyright (C) 2013 NICTA (www.nicta.com.au)
 
3
// 
 
4
// This Source Code Form is subject to the terms of the Mozilla Public
 
5
// License, v. 2.0. If a copy of the MPL was not distributed with this
 
6
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
7
 
 
8
 
 
9
//! \addtogroup fn_fft2
 
10
//! @{
 
11
 
 
12
 
 
13
 
 
14
// 2D FFT & 2D IFFT
 
15
 
 
16
 
 
17
 
 
18
template<typename T1>
 
19
inline
 
20
typename
 
21
enable_if2
 
22
  <
 
23
  is_arma_type<T1>::value,
 
24
  Mat< std::complex<typename T1::pod_type> >
 
25
  >::result
 
26
fft2(const T1& A)
 
27
  {
 
28
  arma_extra_debug_sigprint();
 
29
  
 
30
  // not exactly efficient, but "better-than-nothing" implementation
 
31
  
 
32
  typedef typename T1::pod_type T;
 
33
  
 
34
  Mat< std::complex<T> > B = fft(A);
 
35
  
 
36
  // for square matrices, strans() will work out that an inplace transpose can be done,
 
37
  // hence we can potentially avoid creating a temporary matrix
 
38
  
 
39
  B = strans(B);
 
40
  
 
41
  return strans( fft(B) );
 
42
  }
 
43
 
 
44
 
 
45
 
 
46
template<typename T1>
 
47
inline
 
48
typename
 
49
enable_if2
 
50
  <
 
51
  is_arma_type<T1>::value,
 
52
  Mat< std::complex<typename T1::pod_type> >
 
53
  >::result
 
54
fft2(const T1& A, const uword n_rows, const uword n_cols)
 
55
  {
 
56
  arma_extra_debug_sigprint();
 
57
  
 
58
  typedef typename T1::elem_type eT;
 
59
  
 
60
  const unwrap<T1>   tmp(A);
 
61
  const Mat<eT>& B = tmp.M;
 
62
  
 
63
  const bool do_resize = (B.n_rows != n_rows) || (B.n_cols != n_cols);
 
64
  
 
65
  return fft2( do_resize ? resize(B,n_rows,n_cols) : B );
 
66
  }
 
67
 
 
68
 
 
69
 
 
70
template<typename T1>
 
71
inline
 
72
typename
 
73
enable_if2
 
74
  <
 
75
  (is_arma_type<T1>::value && is_complex_strict<typename T1::elem_type>::value),
 
76
  Mat< std::complex<typename T1::pod_type> >
 
77
  >::result
 
78
ifft2(const T1& A)
 
79
  {
 
80
  arma_extra_debug_sigprint();
 
81
  
 
82
  // not exactly efficient, but "better-than-nothing" implementation
 
83
  
 
84
  typedef typename T1::pod_type T;
 
85
  
 
86
  Mat< std::complex<T> > B = ifft(A);
 
87
  
 
88
  // for square matrices, strans() will work out that an inplace transpose can be done,
 
89
  // hence we can potentially avoid creating a temporary matrix
 
90
  
 
91
  B = strans(B);
 
92
  
 
93
  return strans( ifft(B) );
 
94
  }
 
95
 
 
96
 
 
97
 
 
98
template<typename T1>
 
99
inline
 
100
typename
 
101
enable_if2
 
102
  <
 
103
  (is_arma_type<T1>::value && is_complex_strict<typename T1::elem_type>::value),
 
104
  Mat< std::complex<typename T1::pod_type> >
 
105
  >::result
 
106
ifft2(const T1& A, const uword n_rows, const uword n_cols)
 
107
  {
 
108
  arma_extra_debug_sigprint();
 
109
  
 
110
  typedef typename T1::elem_type eT;
 
111
  
 
112
  const unwrap<T1>   tmp(A);
 
113
  const Mat<eT>& B = tmp.M;
 
114
  
 
115
  const bool do_resize = (B.n_rows != n_rows) || (B.n_cols != n_cols);
 
116
  
 
117
  return ifft2( do_resize ? resize(B,n_rows,n_cols) : B );
 
118
  }
 
119
 
 
120
 
 
121
 
 
122
//! @}