1#ifndef STAN_MATH_REV_FUN_FFT_HPP
2#define STAN_MATH_REV_FUN_FFT_HPP
40template <
typename V, require_eigen_vector_vt<is_complex, V>* =
nullptr,
41 require_var_t<base_type_t<value_type_t<V>>>* =
nullptr>
52 adj_inv_fft *= res.size();
53 arena_v.real().adj() += adj_inv_fft.real();
54 arena_v.imag().adj() += adj_inv_fft.imag();
85template <
typename V, require_eigen_vector_vt<is_complex, V>* =
nullptr,
86 require_var_t<base_type_t<value_type_t<V>>>* =
nullptr>
97 auto adj_fft =
fft(
to_complex(res.real().adj(), res.imag().adj()));
98 adj_fft /= res.size();
100 arena_v.real().adj() += adj_fft.real();
101 arena_v.imag().adj() += adj_fft.imag();
121template <
typename M, require_eigen_dense_dynamic_vt<is_complex, M>* =
nullptr,
122 require_var_t<base_type_t<value_type_t<M>>>* =
nullptr>
129 adj_inv_fft *= res.size();
130 arena_v.real().adj() += adj_inv_fft.real();
131 arena_v.imag().adj() += adj_inv_fft.imag();
153template <
typename M, require_eigen_dense_dynamic_vt<is_complex, M>* =
nullptr,
154 require_var_t<base_type_t<value_type_t<M>>>* =
nullptr>
161 auto adj_fft =
fft2(
to_complex(res.real().adj(), res.imag().adj()));
162 adj_fft /= res.size();
164 arena_v.real().adj() += adj_fft.real();
165 arena_v.imag().adj() += adj_fft.imag();
Eigen::Matrix< scalar_type_t< M >, -1, -1 > fft2(const M &x)
Return the two-dimensional discrete Fourier transform of the specified complex matrix.
constexpr std::complex< stan::real_return_t< T, S > > to_complex(const T &re=0, const S &im=0)
Return a complex value from a real component and an imaginary component.
void reverse_pass_callback(F &&functor)
Puts a callback on the autodiff stack to be called in reverse pass.
Eigen::Matrix< scalar_type_t< V >, -1, 1 > fft(const V &x)
Return the discrete Fourier transform of the specified complex vector.
Eigen::Matrix< scalar_type_t< V >, -1, 1 > inv_fft(const V &y)
Return the inverse discrete Fourier transform of the specified complex vector.
Eigen::Matrix< scalar_type_t< M >, -1, -1 > inv_fft2(const M &y)
Return the two-dimensional inverse discrete Fourier transform of the specified complex matrix.
typename plain_type< T >::type plain_type_t
typename internal::arena_type_impl< std::decay_t< T > >::type arena_t
Determines a type that can be used in place of T that does any dynamic allocations on the AD stack.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...