Sprout/sprout/numeric/dft/detail/dft_element_gen.hpp
2012-04-10 12:54:38 +09:00

40 lines
1.4 KiB
C++

#ifndef SPROUT_NUMERIC_DFT_DETAIL_DFT_ELEMENT_GEN_HPP
#define SPROUT_NUMERIC_DFT_DETAIL_DFT_ELEMENT_GEN_HPP
#include <cmath>
#include <iterator>
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/iterator/operation.hpp>
namespace sprout {
namespace detail {
template<typename InputIterator>
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::value_type dft_element_gen(
InputIterator first,
InputIterator last,
typename std::iterator_traits<InputIterator>::value_type::value_type arg,
typename std::iterator_traits<InputIterator>::difference_type k = 0,
typename std::iterator_traits<InputIterator>::value_type value = typename std::iterator_traits<InputIterator>::value_type(),
typename std::iterator_traits<InputIterator>::value_type::value_type theta = typename std::iterator_traits<InputIterator>::value_type::value_type()
)
{
typedef typename std::iterator_traits<InputIterator>::value_type value_type;
using std::cos;
using std::sin;
return first != last
? value + sprout::detail::dft_element_gen(
sprout::next(first),
last,
arg,
k + 1,
*first * value_type(cos(theta), sin(theta)),
arg * (k + 1)
)
: value
;
}
} // namespace detail
} // namespace sprout
#endif // #ifndef SPROUT_NUMERIC_DFT_DETAIL_DFT_ELEMENT_GEN_HPP