1#ifndef STAN_MATH_PRIM_FUN_FFT_HPP
2#define STAN_MATH_PRIM_FUN_FFT_HPP
6#include <unsupported/Eigen/FFT>
33template <
typename V, require_eigen_vector_vt<is_complex, V>* =
nullptr,
34 require_not_var_t<base_type_t<value_type_t<V>>>* =
nullptr,
35 require_not_fvar_t<base_type_t<value_type_t<V>>>* =
nullptr>
36inline Eigen::Matrix<scalar_type_t<V>, -1, 1>
fft(
const V& x) {
38 Eigen::Matrix<scalar_type_t<V>, -1, 1> xv = x;
41 Eigen::FFT<base_type_t<V>>
fft;
65template <
typename V, require_eigen_vector_vt<is_complex, V>* =
nullptr,
66 require_not_var_t<base_type_t<value_type_t<V>>>* =
nullptr,
67 require_not_fvar_t<base_type_t<value_type_t<V>>>* =
nullptr>
68inline Eigen::Matrix<scalar_type_t<V>, -1, 1>
inv_fft(
const V& y) {
70 Eigen::Matrix<scalar_type_t<V>, -1, 1> yv = y;
73 Eigen::FFT<base_type_t<V>>
fft;
87template <
typename M, require_eigen_dense_dynamic_vt<is_complex, M>* =
nullptr,
88 require_not_var_t<base_type_t<value_type_t<M>>>* =
nullptr,
89 require_not_fvar_t<base_type_t<value_type_t<M>>>* =
nullptr>
90inline Eigen::Matrix<scalar_type_t<M>, -1, -1>
fft2(
const M& x) {
91 Eigen::Matrix<scalar_type_t<M>, -1, -1> y(x.rows(), x.cols());
92 for (
int i = 0; i < y.rows(); ++i)
93 y.row(i) =
fft(x.row(i));
94 for (
int j = 0; j < y.cols(); ++j)
95 y.col(j) =
fft(y.col(j));
110template <
typename M, require_eigen_dense_dynamic_vt<is_complex, M>* =
nullptr,
111 require_not_var_t<base_type_t<value_type_t<M>>>* =
nullptr,
112 require_not_fvar_t<base_type_t<value_type_t<M>>>* =
nullptr>
113inline Eigen::Matrix<scalar_type_t<M>, -1, -1>
inv_fft2(
const M& y) {
114 Eigen::Matrix<scalar_type_t<M>, -1, -1> x(y.rows(), y.cols());
115 for (
int j = 0; j < x.cols(); ++j)
117 for (
int i = 0; i < x.rows(); ++i)
Eigen::Matrix< scalar_type_t< V >, -1, 1 > inv_fft(V &&y)
Return the inverse discrete Fourier transform of the specified complex vector for forward-mode autodi...
Eigen::Matrix< scalar_type_t< M >, -1, -1 > inv_fft2(M &&y)
Return the two-dimensional inverse discrete Fourier transform of the specified complex matrix for for...
Eigen::Matrix< scalar_type_t< M >, -1, -1 > fft2(M &&x)
Return the two-dimensional discrete Fourier transform of the specified complex matrix for forward-mod...
Eigen::Matrix< scalar_type_t< V >, -1, 1 > fft(V &&x)
Return the discrete Fourier transform of the specified complex vector for forward-mode autodiff.
The lgamma implementation in stan-math is based on either the reentrant safe lgamma_r implementation ...