mirror of
https://github.com/bolero-MURAKAMI/Sprout
synced 2025-08-03 12:49:50 +00:00
sprout/functional/dft.hpp 追加
sprout/complex.hpp 修正
This commit is contained in:
parent
aa96f9ce73
commit
10c73ea3e3
17 changed files with 453 additions and 24 deletions
40
sprout/functional/dft/detail/dft_element_gen.hpp
Normal file
40
sprout/functional/dft/detail/dft_element_gen.hpp
Normal file
|
@ -0,0 +1,40 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_DFT_DETAIL_DFT_ELEMENT_GEN_HPP
|
||||
#define SPROUT_FUNCTIONAL_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>
|
||||
SPROUT_CONSTEXPR inline 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_FUNCTIONAL_DFT_DETAIL_DFT_ELEMENT_GEN_HPP
|
8
sprout/functional/dft/dft.hpp
Normal file
8
sprout/functional/dft/dft.hpp
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_DFT_DFT_HPP
|
||||
#define SPROUT_FUNCTIONAL_DFT_DFT_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/dft/fixed/dft.hpp>
|
||||
#include <sprout/functional/dft/fit/dft.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_DFT_DFT_HPP
|
48
sprout/functional/dft/dft_element.hpp
Normal file
48
sprout/functional/dft/dft_element.hpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_DFT_FIXED_DFT_ELEMENT_HPP
|
||||
#define SPROUT_FUNCTIONAL_DFT_FIXED_DFT_ELEMENT_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/dft/detail/dft_element_gen.hpp>
|
||||
#include <sprout/math/constants.hpp>
|
||||
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT_DETAIL
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
template<typename InputIterator, typename Size>
|
||||
SPROUT_CONSTEXPR inline typename std::iterator_traits<InputIterator>::value_type dft_element_impl(
|
||||
InputIterator first,
|
||||
InputIterator last,
|
||||
typename std::iterator_traits<InputIterator>::difference_type i,
|
||||
Size size
|
||||
)
|
||||
{
|
||||
typedef typename std::iterator_traits<InputIterator>::value_type value_type;
|
||||
typedef typename value_type::value_type elem_type;
|
||||
return sprout::detail::dft_element_gen(
|
||||
first,
|
||||
last,
|
||||
-(2 * sprout::math::pi<elem_type>() * i / size)
|
||||
);
|
||||
}
|
||||
} // namespace detail
|
||||
//
|
||||
// dft_element
|
||||
//
|
||||
template<typename InputIterator>
|
||||
SPROUT_CONSTEXPR inline typename std::iterator_traits<InputIterator>::value_type dft_element(
|
||||
InputIterator first,
|
||||
InputIterator last,
|
||||
typename std::iterator_traits<InputIterator>::difference_type i
|
||||
)
|
||||
{
|
||||
return sprout::detail::dft_element_impl(
|
||||
first,
|
||||
last,
|
||||
i,
|
||||
NS_SSCRISK_CEL_OR_SPROUT_DETAIL::distance(first, last)
|
||||
);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_DFT_FIXED_DFT_ELEMENT_HPP
|
46
sprout/functional/dft/fit/dft.hpp
Normal file
46
sprout/functional/dft/fit/dft.hpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_DFT_FIT_DFT_HPP
|
||||
#define SPROUT_FUNCTIONAL_DFT_FIT_DFT_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/fixed_container/traits.hpp>
|
||||
#include <sprout/fixed_container/functions.hpp>
|
||||
#include <sprout/functional/dft/fixed/dft.hpp>
|
||||
#include <sprout/algorithm/fit/result_of.hpp>
|
||||
#include <sprout/sub_array.hpp>
|
||||
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT_DETAIL
|
||||
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT_DETAIL
|
||||
|
||||
namespace sprout {
|
||||
namespace fit {
|
||||
namespace detail {
|
||||
template<typename InputIterator, typename Result>
|
||||
SPROUT_CONSTEXPR inline typename sprout::fit::result_of::algorithm<Result>::type dft_impl(
|
||||
InputIterator first,
|
||||
InputIterator last,
|
||||
Result const& result,
|
||||
typename sprout::fixed_container_traits<Result>::difference_type offset
|
||||
)
|
||||
{
|
||||
return sprout::sub_copy(
|
||||
sprout::get_fixed(sprout::fixed::dft(first, last, result)),
|
||||
offset,
|
||||
offset + NS_SSCRISK_CEL_OR_SPROUT_DETAIL::min(NS_SSCRISK_CEL_OR_SPROUT_DETAIL::distance(first, last), sprout::size(result))
|
||||
);
|
||||
}
|
||||
} // namespace detail
|
||||
//
|
||||
// dft
|
||||
//
|
||||
template<typename InputIterator, typename Result>
|
||||
SPROUT_CONSTEXPR inline typename sprout::fit::result_of::algorithm<Result>::type dft(
|
||||
InputIterator first,
|
||||
InputIterator last,
|
||||
Result const& result
|
||||
)
|
||||
{
|
||||
return sprout::fit::detail::dft_impl(first, last, result, sprout::fixed_begin_offset(result));
|
||||
}
|
||||
} // namespace fit
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_DFT_FIT_DFT_HPP
|
46
sprout/functional/dft/fit/idft.hpp
Normal file
46
sprout/functional/dft/fit/idft.hpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_DFT_FIT_IDFT_HPP
|
||||
#define SPROUT_FUNCTIONAL_DFT_FIT_IDFT_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/fixed_container/traits.hpp>
|
||||
#include <sprout/fixed_container/functions.hpp>
|
||||
#include <sprout/functional/dft/fixed/idft.hpp>
|
||||
#include <sprout/algorithm/fit/result_of.hpp>
|
||||
#include <sprout/sub_array.hpp>
|
||||
#include HDR_ALGORITHM_SSCRISK_CEL_OR_SPROUT_DETAIL
|
||||
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT_DETAIL
|
||||
|
||||
namespace sprout {
|
||||
namespace fit {
|
||||
namespace detail {
|
||||
template<typename InputIterator, typename Result>
|
||||
SPROUT_CONSTEXPR inline typename sprout::fit::result_of::algorithm<Result>::type idft_impl(
|
||||
InputIterator first,
|
||||
InputIterator last,
|
||||
Result const& result,
|
||||
typename sprout::fixed_container_traits<Result>::difference_type offset
|
||||
)
|
||||
{
|
||||
return sprout::sub_copy(
|
||||
sprout::get_fixed(sprout::fixed::idft(first, last, result)),
|
||||
offset,
|
||||
offset + NS_SSCRISK_CEL_OR_SPROUT_DETAIL::min(NS_SSCRISK_CEL_OR_SPROUT_DETAIL::distance(first, last), sprout::size(result))
|
||||
);
|
||||
}
|
||||
} // namespace detail
|
||||
//
|
||||
// idft
|
||||
//
|
||||
template<typename InputIterator, typename Result>
|
||||
SPROUT_CONSTEXPR inline typename sprout::fit::result_of::algorithm<Result>::type idft(
|
||||
InputIterator first,
|
||||
InputIterator last,
|
||||
Result const& result
|
||||
)
|
||||
{
|
||||
return sprout::fit::detail::idft_impl(first, last, result, sprout::fixed_begin_offset(result));
|
||||
}
|
||||
} // namespace fit
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_DFT_FIT_IDFT_HPP
|
72
sprout/functional/dft/fixed/dft.hpp
Normal file
72
sprout/functional/dft/fixed/dft.hpp
Normal file
|
@ -0,0 +1,72 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_DFT_FIXED_DFT_HPP
|
||||
#define SPROUT_FUNCTIONAL_DFT_FIXED_DFT_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/index_tuple.hpp>
|
||||
#include <sprout/fixed_container/traits.hpp>
|
||||
#include <sprout/fixed_container/functions.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/algorithm/fixed/result_of.hpp>
|
||||
#include <sprout/functional/dft/dft_element.hpp>
|
||||
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT_DETAIL
|
||||
|
||||
namespace sprout {
|
||||
namespace fixed {
|
||||
namespace detail {
|
||||
template<typename InputIterator, typename Result, std::ptrdiff_t... Indexes>
|
||||
SPROUT_CONSTEXPR inline typename sprout::fixed::result_of::algorithm<Result>::type dft_impl(
|
||||
InputIterator first,
|
||||
InputIterator last,
|
||||
Result const& result,
|
||||
sprout::index_tuple<Indexes...>,
|
||||
typename sprout::fixed_container_traits<Result>::difference_type offset,
|
||||
typename sprout::fixed_container_traits<Result>::size_type size,
|
||||
typename sprout::fixed_container_traits<Result>::size_type input_size
|
||||
)
|
||||
{
|
||||
return sprout::remake_clone<Result>(
|
||||
result,
|
||||
sprout::size(result),
|
||||
(Indexes >= offset && Indexes < offset + size && Indexes < offset + input_size
|
||||
? sprout::detail::dft_element_impl(first, last, Indexes - offset, input_size)
|
||||
: *sprout::next(sprout::fixed_begin(result), Indexes)
|
||||
)...
|
||||
);
|
||||
}
|
||||
template<typename InputIterator, typename Result>
|
||||
SPROUT_CONSTEXPR inline typename sprout::fixed::result_of::algorithm<Result>::type dft(
|
||||
InputIterator first,
|
||||
InputIterator last,
|
||||
Result const& result
|
||||
)
|
||||
{
|
||||
return sprout::fixed::detail::dft_impl(
|
||||
first,
|
||||
last,
|
||||
result,
|
||||
typename sprout::index_range<0, sprout::fixed_container_traits<Result>::fixed_size>::type(),
|
||||
sprout::fixed_begin_offset(result),
|
||||
sprout::size(result),
|
||||
NS_SSCRISK_CEL_OR_SPROUT_DETAIL::distance(first, last)
|
||||
);
|
||||
}
|
||||
} // namespace detail
|
||||
//
|
||||
// dft
|
||||
//
|
||||
template<typename InputIterator, typename Result>
|
||||
SPROUT_CONSTEXPR inline typename sprout::fixed::result_of::algorithm<Result>::type dft(
|
||||
InputIterator first,
|
||||
InputIterator last,
|
||||
Result const& result
|
||||
)
|
||||
{
|
||||
return sprout::fixed::detail::dft(first, last, result);
|
||||
}
|
||||
} // namespace fixed
|
||||
|
||||
using sprout::fixed::dft;
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_DFT_FIXED_DFT_HPP
|
72
sprout/functional/dft/fixed/idft.hpp
Normal file
72
sprout/functional/dft/fixed/idft.hpp
Normal file
|
@ -0,0 +1,72 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_DFT_FIXED_IDFT_HPP
|
||||
#define SPROUT_FUNCTIONAL_DFT_FIXED_IDFT_HPP
|
||||
|
||||
#include <cstddef>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/index_tuple.hpp>
|
||||
#include <sprout/fixed_container/traits.hpp>
|
||||
#include <sprout/fixed_container/functions.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/algorithm/fixed/result_of.hpp>
|
||||
#include <sprout/functional/dft/idft_element.hpp>
|
||||
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT_DETAIL
|
||||
|
||||
namespace sprout {
|
||||
namespace fixed {
|
||||
namespace detail {
|
||||
template<typename InputIterator, typename Result, std::ptrdiff_t... Indexes>
|
||||
SPROUT_CONSTEXPR inline typename sprout::fixed::result_of::algorithm<Result>::type idft_impl(
|
||||
InputIterator first,
|
||||
InputIterator last,
|
||||
Result const& result,
|
||||
sprout::index_tuple<Indexes...>,
|
||||
typename sprout::fixed_container_traits<Result>::difference_type offset,
|
||||
typename sprout::fixed_container_traits<Result>::size_type size,
|
||||
typename sprout::fixed_container_traits<Result>::size_type input_size
|
||||
)
|
||||
{
|
||||
return sprout::remake_clone<Result>(
|
||||
result,
|
||||
sprout::size(result),
|
||||
(Indexes >= offset && Indexes < offset + size && Indexes < offset + input_size
|
||||
? sprout::detail::idft_element_impl(first, last, Indexes - offset, input_size)
|
||||
: *sprout::next(sprout::fixed_begin(result), Indexes)
|
||||
)...
|
||||
);
|
||||
}
|
||||
template<typename InputIterator, typename Result>
|
||||
SPROUT_CONSTEXPR inline typename sprout::fixed::result_of::algorithm<Result>::type idft(
|
||||
InputIterator first,
|
||||
InputIterator last,
|
||||
Result const& result
|
||||
)
|
||||
{
|
||||
return sprout::fixed::detail::idft_impl(
|
||||
first,
|
||||
last,
|
||||
result,
|
||||
typename sprout::index_range<0, sprout::fixed_container_traits<Result>::fixed_size>::type(),
|
||||
sprout::fixed_begin_offset(result),
|
||||
sprout::size(result),
|
||||
NS_SSCRISK_CEL_OR_SPROUT_DETAIL::distance(first, last)
|
||||
);
|
||||
}
|
||||
} // namespace detail
|
||||
//
|
||||
// idft
|
||||
//
|
||||
template<typename InputIterator, typename Result>
|
||||
SPROUT_CONSTEXPR inline typename sprout::fixed::result_of::algorithm<Result>::type idft(
|
||||
InputIterator first,
|
||||
InputIterator last,
|
||||
Result const& result
|
||||
)
|
||||
{
|
||||
return sprout::fixed::detail::idft(first, last, result);
|
||||
}
|
||||
} // namespace fixed
|
||||
|
||||
using sprout::fixed::idft;
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_DFT_FIXED_IDFT_HPP
|
8
sprout/functional/dft/idft.hpp
Normal file
8
sprout/functional/dft/idft.hpp
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_DFT_IDFT_HPP
|
||||
#define SPROUT_FUNCTIONAL_DFT_IDFT_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/dft/fixed/idft.hpp>
|
||||
#include <sprout/functional/dft/fit/idft.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_DFT_IDFT_HPP
|
50
sprout/functional/dft/idft_element.hpp
Normal file
50
sprout/functional/dft/idft_element.hpp
Normal file
|
@ -0,0 +1,50 @@
|
|||
#ifndef SPROUT_FUNCTIONAL_DFT_FIXED_IDFT_ELEMENT_HPP
|
||||
#define SPROUT_FUNCTIONAL_DFT_FIXED_IDFT_ELEMENT_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/functional/dft/detail/dft_element_gen.hpp>
|
||||
#include <sprout/math/constants.hpp>
|
||||
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT_DETAIL
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
template<typename InputIterator, typename Size>
|
||||
SPROUT_CONSTEXPR inline typename std::iterator_traits<InputIterator>::value_type idft_element_impl(
|
||||
InputIterator first,
|
||||
InputIterator last,
|
||||
typename std::iterator_traits<InputIterator>::difference_type i,
|
||||
Size size
|
||||
)
|
||||
{
|
||||
typedef typename std::iterator_traits<InputIterator>::value_type value_type;
|
||||
typedef typename value_type::value_type elem_type;
|
||||
return sprout::detail::dft_element_gen(
|
||||
first,
|
||||
last,
|
||||
2 * sprout::math::pi<elem_type>() * i / size
|
||||
)
|
||||
/ static_cast<elem_type>(size)
|
||||
;
|
||||
}
|
||||
} // namespace detail
|
||||
//
|
||||
// idft_element
|
||||
//
|
||||
template<typename InputIterator>
|
||||
SPROUT_CONSTEXPR inline typename std::iterator_traits<InputIterator>::value_type idft_element(
|
||||
InputIterator first,
|
||||
InputIterator last,
|
||||
typename std::iterator_traits<InputIterator>::difference_type i
|
||||
)
|
||||
{
|
||||
return sprout::detail::idft_element_impl(
|
||||
first,
|
||||
last,
|
||||
i,
|
||||
NS_SSCRISK_CEL_OR_SPROUT_DETAIL::distance(first, last)
|
||||
);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_FUNCTIONAL_DFT_FIXED_IDFT_ELEMENT_HPP
|
Loading…
Add table
Add a link
Reference in a new issue