2013-08-08 09:54:33 +00:00
|
|
|
/*=============================================================================
|
2017-07-29 05:20:01 +00:00
|
|
|
Copyright (c) 2011-2017 Bolero MURAKAMI
|
2013-08-08 09:54:33 +00:00
|
|
|
https://github.com/bolero-MURAKAMI/Sprout
|
|
|
|
|
|
|
|
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
=============================================================================*/
|
2012-04-10 03:54:38 +00:00
|
|
|
#ifndef SPROUT_NUMERIC_DFT_DETAIL_DFT_ELEMENT_GEN_HPP
|
|
|
|
#define SPROUT_NUMERIC_DFT_DETAIL_DFT_ELEMENT_GEN_HPP
|
2012-02-25 14:59:46 +00:00
|
|
|
|
|
|
|
#include <iterator>
|
|
|
|
#include <type_traits>
|
|
|
|
#include <sprout/config.hpp>
|
|
|
|
#include <sprout/iterator/operation.hpp>
|
2012-05-09 01:15:19 +00:00
|
|
|
#include <sprout/math/sin.hpp>
|
|
|
|
#include <sprout/math/cos.hpp>
|
2012-02-25 14:59:46 +00:00
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
namespace detail {
|
2012-12-03 12:48:50 +00:00
|
|
|
template<typename RandomAccessIterator>
|
|
|
|
inline SPROUT_CONSTEXPR typename std::iterator_traits<RandomAccessIterator>::value_type
|
|
|
|
dft_element_gen_impl_ra(
|
2016-04-01 14:37:48 +00:00
|
|
|
RandomAccessIterator const& first, RandomAccessIterator const& last,
|
2012-12-03 12:48:50 +00:00
|
|
|
typename std::iterator_traits<RandomAccessIterator>::value_type::value_type arg,
|
|
|
|
typename std::iterator_traits<RandomAccessIterator>::difference_type pivot,
|
|
|
|
typename std::iterator_traits<RandomAccessIterator>::difference_type k = 0
|
|
|
|
)
|
|
|
|
{
|
|
|
|
typedef typename std::iterator_traits<RandomAccessIterator>::value_type value_type;
|
|
|
|
using sprout::cos;
|
|
|
|
using sprout::sin;
|
|
|
|
return pivot == 0 ? *first * value_type(cos(arg * k), sin(arg * k))
|
|
|
|
: sprout::detail::dft_element_gen_impl_ra(
|
|
|
|
first, sprout::next(first, pivot), arg, pivot / 2, k
|
|
|
|
)
|
|
|
|
+ sprout::detail::dft_element_gen_impl_ra(
|
2013-01-03 08:01:50 +00:00
|
|
|
sprout::next(first, pivot), last, arg, (sprout::distance(first, last) - pivot) / 2, k + pivot
|
2012-12-03 12:48:50 +00:00
|
|
|
)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
template<typename RandomAccessIterator>
|
|
|
|
inline SPROUT_CONSTEXPR typename std::iterator_traits<RandomAccessIterator>::value_type
|
|
|
|
dft_element_gen_impl(
|
2016-04-01 14:37:48 +00:00
|
|
|
RandomAccessIterator const& first, RandomAccessIterator const& last,
|
2012-12-03 12:48:50 +00:00
|
|
|
typename std::iterator_traits<RandomAccessIterator>::value_type::value_type arg,
|
|
|
|
std::random_access_iterator_tag*
|
|
|
|
)
|
|
|
|
{
|
|
|
|
typedef typename std::iterator_traits<RandomAccessIterator>::value_type value_type;
|
|
|
|
return first == last ? value_type()
|
2013-01-03 08:01:50 +00:00
|
|
|
: sprout::detail::dft_element_gen_impl_ra(first, last, arg, sprout::distance(first, last) / 2)
|
2012-12-03 12:48:50 +00:00
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2012-02-25 14:59:46 +00:00
|
|
|
template<typename InputIterator>
|
2012-10-06 04:53:07 +00:00
|
|
|
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::value_type
|
2012-12-03 12:48:50 +00:00
|
|
|
dft_element_gen_impl_1(
|
2016-04-01 14:37:48 +00:00
|
|
|
InputIterator const& first, InputIterator const& last,
|
2012-02-25 14:59:46 +00:00
|
|
|
typename std::iterator_traits<InputIterator>::value_type::value_type arg,
|
|
|
|
typename std::iterator_traits<InputIterator>::difference_type k = 0,
|
2012-10-06 04:53:07 +00:00
|
|
|
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()
|
2012-02-25 14:59:46 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
typedef typename std::iterator_traits<InputIterator>::value_type value_type;
|
2012-05-09 01:15:19 +00:00
|
|
|
using sprout::cos;
|
|
|
|
using sprout::sin;
|
2012-12-03 12:48:50 +00:00
|
|
|
return first == last ? value
|
|
|
|
: value + sprout::detail::dft_element_gen_impl_1(
|
|
|
|
sprout::next(first), last,
|
2012-02-25 14:59:46 +00:00
|
|
|
arg,
|
|
|
|
k + 1,
|
|
|
|
*first * value_type(cos(theta), sin(theta)),
|
|
|
|
arg * (k + 1)
|
|
|
|
)
|
|
|
|
;
|
|
|
|
}
|
2012-12-03 12:48:50 +00:00
|
|
|
template<typename InputIterator>
|
|
|
|
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::value_type
|
|
|
|
dft_element_gen_impl(
|
2016-04-01 14:37:48 +00:00
|
|
|
InputIterator const& first, InputIterator const& last,
|
2012-12-03 12:48:50 +00:00
|
|
|
typename std::iterator_traits<InputIterator>::value_type::value_type arg,
|
2013-02-23 06:21:27 +00:00
|
|
|
std::input_iterator_tag*
|
2012-12-03 12:48:50 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
return sprout::detail::dft_element_gen_impl_1(first, last, arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename InputIterator>
|
|
|
|
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::value_type
|
|
|
|
dft_element_gen(
|
2016-04-01 14:37:48 +00:00
|
|
|
InputIterator const& first, InputIterator const& last,
|
2013-07-22 13:00:09 +00:00
|
|
|
typename std::iterator_traits<InputIterator>::value_type::value_type arg
|
2012-12-03 12:48:50 +00:00
|
|
|
)
|
|
|
|
{
|
|
|
|
typedef typename std::iterator_traits<InputIterator>::iterator_category* category;
|
|
|
|
return sprout::detail::dft_element_gen_impl(first, last, arg, category());
|
|
|
|
}
|
2012-02-25 14:59:46 +00:00
|
|
|
} // namespace detail
|
|
|
|
} // namespace sprout
|
|
|
|
|
2012-04-10 03:54:38 +00:00
|
|
|
#endif // #ifndef SPROUT_NUMERIC_DFT_DETAIL_DFT_ELEMENT_GEN_HPP
|