mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +00:00
add compost dft, spectrum, etc
This commit is contained in:
parent
6b08a81d3e
commit
24d2a229f3
45 changed files with 1490 additions and 61 deletions
|
@ -6,6 +6,8 @@
|
|||
#include <sprout/compost/effects.hpp>
|
||||
#include <sprout/compost/formats.hpp>
|
||||
#include <sprout/compost/ranges.hpp>
|
||||
#include <sprout/compost/analyses.hpp>
|
||||
#include <sprout/compost/utility.hpp>
|
||||
#include <sprout/compost/sources.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_HPP
|
||||
|
|
10
sprout/compost/analyses.hpp
Normal file
10
sprout/compost/analyses.hpp
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifndef SPROUT_COMPOST_ANALYSES_HPP
|
||||
#define SPROUT_COMPOST_ANALYSES_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/compost/analyses/dft.hpp>
|
||||
#include <sprout/compost/analyses/idft.hpp>
|
||||
#include <sprout/compost/analyses/amplitude_spectrum.hpp>
|
||||
#include <sprout/compost/analyses/phase_spectrum.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_ANALYSES_HPP
|
20
sprout/compost/analyses/amplitude_spectrum.hpp
Normal file
20
sprout/compost/analyses/amplitude_spectrum.hpp
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef SPROUT_COMPOST_ANALYSES_AMPLITUDE_SPECTRUM_HPP
|
||||
#define SPROUT_COMPOST_ANALYSES_AMPLITUDE_SPECTRUM_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/range/adaptor/amplitude_spectrum.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace compost {
|
||||
namespace analyses {
|
||||
//
|
||||
// amplitude_spectrum
|
||||
//
|
||||
using sprout::adaptors::amplitude_spectrum;
|
||||
} // namespace analyses
|
||||
|
||||
using sprout::compost::analyses::amplitude_spectrum;
|
||||
} // namespace compost
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_ANALYSES_AMPLITUDE_SPECTRUM_HPP
|
20
sprout/compost/analyses/dft.hpp
Normal file
20
sprout/compost/analyses/dft.hpp
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef SPROUT_COMPOST_ANALYSES_DFT_HPP
|
||||
#define SPROUT_COMPOST_ANALYSES_DFT_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/range/adaptor/dft.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace compost {
|
||||
namespace analyses {
|
||||
//
|
||||
// dft
|
||||
//
|
||||
using sprout::adaptors::dft;
|
||||
} // namespace analyses
|
||||
|
||||
using sprout::compost::analyses::dft;
|
||||
} // namespace compost
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_ANALYSES_DFT_HPP
|
20
sprout/compost/analyses/idft.hpp
Normal file
20
sprout/compost/analyses/idft.hpp
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef SPROUT_COMPOST_ANALYSES_IDFT_HPP
|
||||
#define SPROUT_COMPOST_ANALYSES_IDFT_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/range/adaptor/idft.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace compost {
|
||||
namespace analyses {
|
||||
//
|
||||
// idft
|
||||
//
|
||||
using sprout::adaptors::idft;
|
||||
} // namespace analyses
|
||||
|
||||
using sprout::compost::analyses::idft;
|
||||
} // namespace compost
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_ANALYSES_IDFT_HPP
|
20
sprout/compost/analyses/phase_spectrum.hpp
Normal file
20
sprout/compost/analyses/phase_spectrum.hpp
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef SPROUT_COMPOST_ANALYSES_PHASE_SPECTRUM_HPP
|
||||
#define SPROUT_COMPOST_ANALYSES_PHASE_SPECTRUM_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/range/adaptor/phase_spectrum.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace compost {
|
||||
namespace analyses {
|
||||
//
|
||||
// phase_spectrum
|
||||
//
|
||||
using sprout::adaptors::phase_spectrum;
|
||||
} // namespace analyses
|
||||
|
||||
using sprout::compost::analyses::phase_spectrum;
|
||||
} // namespace compost
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_ANALYSES_PHASE_SPECTRUM_HPP
|
|
@ -9,5 +9,8 @@
|
|||
#include <sprout/compost/formats/effected_each.hpp>
|
||||
#include <sprout/compost/formats/effected_left.hpp>
|
||||
#include <sprout/compost/formats/effected_right.hpp>
|
||||
#include <sprout/compost/formats/as_complex.hpp>
|
||||
#include <sprout/compost/formats/as_real.hpp>
|
||||
#include <sprout/compost/formats/as_imag.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_FORMATS_HPP
|
||||
|
|
56
sprout/compost/formats/as_complex.hpp
Normal file
56
sprout/compost/formats/as_complex.hpp
Normal file
|
@ -0,0 +1,56 @@
|
|||
#ifndef SPROUT_COMPOST_FORMATS_AS_COMPLEX_HPP
|
||||
#define SPROUT_COMPOST_FORMATS_AS_COMPLEX_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/complex.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/range/adaptor/transformed.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace compost {
|
||||
//
|
||||
// to_complex_value
|
||||
//
|
||||
struct to_complex_value {
|
||||
public:
|
||||
template<typename FloatType>
|
||||
SPROUT_CONSTEXPR sprout::complex<FloatType> operator()(FloatType const& x) const {
|
||||
return sprout::complex<FloatType>(x);
|
||||
}
|
||||
};
|
||||
|
||||
namespace formats {
|
||||
//
|
||||
// as_complex_forwarder
|
||||
//
|
||||
class as_complex_forwarder {};
|
||||
|
||||
//
|
||||
// as_complex
|
||||
//
|
||||
namespace {
|
||||
SPROUT_STATIC_CONSTEXPR sprout::compost::formats::as_complex_forwarder as_complex{};
|
||||
} // anonymous-namespace
|
||||
|
||||
//
|
||||
// operator|
|
||||
//
|
||||
template<typename Range>
|
||||
inline SPROUT_CONSTEXPR auto
|
||||
operator|(Range&& lhs, sprout::compost::formats::as_complex_forwarder const& rhs)
|
||||
-> decltype(
|
||||
sprout::forward<Range>(lhs)
|
||||
| sprout::adaptors::transformed(sprout::compost::to_complex_value())
|
||||
)
|
||||
{
|
||||
return sprout::forward<Range>(lhs)
|
||||
| sprout::adaptors::transformed(sprout::compost::to_complex_value())
|
||||
;
|
||||
}
|
||||
} // namespace formats
|
||||
|
||||
using sprout::compost::formats::as_complex;
|
||||
} // namespace compost
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_FORMATS_AS_COMPLEX_HPP
|
57
sprout/compost/formats/as_imag.hpp
Normal file
57
sprout/compost/formats/as_imag.hpp
Normal file
|
@ -0,0 +1,57 @@
|
|||
#ifndef SPROUT_COMPOST_FORMATS_AS_IMAG_HPP
|
||||
#define SPROUT_COMPOST_FORMATS_AS_IMAG_HPP
|
||||
|
||||
#include <utility>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/complex.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/range/adaptor/transformed.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace compost {
|
||||
//
|
||||
// to_imag_value
|
||||
//
|
||||
struct to_imag_value {
|
||||
public:
|
||||
template<typename Complex>
|
||||
SPROUT_CONSTEXPR decltype(imag(std::declval<Complex const&>())) operator()(Complex const& x) const {
|
||||
return imag(x);
|
||||
}
|
||||
};
|
||||
|
||||
namespace formats {
|
||||
//
|
||||
// as_imag_forwarder
|
||||
//
|
||||
class as_imag_forwarder {};
|
||||
|
||||
//
|
||||
// as_imag
|
||||
//
|
||||
namespace {
|
||||
SPROUT_STATIC_CONSTEXPR sprout::compost::formats::as_imag_forwarder as_imag{};
|
||||
} // anonymous-namespace
|
||||
|
||||
//
|
||||
// operator|
|
||||
//
|
||||
template<typename Range>
|
||||
inline SPROUT_CONSTEXPR auto
|
||||
operator|(Range&& lhs, sprout::compost::formats::as_imag_forwarder const& rhs)
|
||||
-> decltype(
|
||||
sprout::forward<Range>(lhs)
|
||||
| sprout::adaptors::transformed(sprout::compost::to_imag_value())
|
||||
)
|
||||
{
|
||||
return sprout::forward<Range>(lhs)
|
||||
| sprout::adaptors::transformed(sprout::compost::to_imag_value())
|
||||
;
|
||||
}
|
||||
} // namespace formats
|
||||
|
||||
using sprout::compost::formats::as_imag;
|
||||
} // namespace compost
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_FORMATS_AS_IMAG_HPP
|
57
sprout/compost/formats/as_real.hpp
Normal file
57
sprout/compost/formats/as_real.hpp
Normal file
|
@ -0,0 +1,57 @@
|
|||
#ifndef SPROUT_COMPOST_FORMATS_AS_REAL_HPP
|
||||
#define SPROUT_COMPOST_FORMATS_AS_REAL_HPP
|
||||
|
||||
#include <utility>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/complex.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/range/adaptor/transformed.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace compost {
|
||||
//
|
||||
// to_real_value
|
||||
//
|
||||
struct to_real_value {
|
||||
public:
|
||||
template<typename Complex>
|
||||
SPROUT_CONSTEXPR decltype(real(std::declval<Complex const&>())) operator()(Complex const& x) const {
|
||||
return real(x);
|
||||
}
|
||||
};
|
||||
|
||||
namespace formats {
|
||||
//
|
||||
// as_real_forwarder
|
||||
//
|
||||
class as_real_forwarder {};
|
||||
|
||||
//
|
||||
// as_real
|
||||
//
|
||||
namespace {
|
||||
SPROUT_STATIC_CONSTEXPR sprout::compost::formats::as_real_forwarder as_real{};
|
||||
} // anonymous-namespace
|
||||
|
||||
//
|
||||
// operator|
|
||||
//
|
||||
template<typename Range>
|
||||
inline SPROUT_CONSTEXPR auto
|
||||
operator|(Range&& lhs, sprout::compost::formats::as_real_forwarder const& rhs)
|
||||
-> decltype(
|
||||
sprout::forward<Range>(lhs)
|
||||
| sprout::adaptors::transformed(sprout::compost::to_real_value())
|
||||
)
|
||||
{
|
||||
return sprout::forward<Range>(lhs)
|
||||
| sprout::adaptors::transformed(sprout::compost::to_real_value())
|
||||
;
|
||||
}
|
||||
} // namespace formats
|
||||
|
||||
using sprout::compost::formats::as_real;
|
||||
} // namespace compost
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_FORMATS_AS_REAL_HPP
|
7
sprout/compost/utility.hpp
Normal file
7
sprout/compost/utility.hpp
Normal file
|
@ -0,0 +1,7 @@
|
|||
#ifndef SPROUT_COMPOST_UTILITY_HPP
|
||||
#define SPROUT_COMPOST_UTILITY_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/compost/utility/equal_temperament.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_UTILITY_HPP
|
28
sprout/compost/utility/equal_temperament.hpp
Normal file
28
sprout/compost/utility/equal_temperament.hpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
#ifndef SPROUT_COMPOST_UTILITY_EQUAL_TEMPERAMENT_HPP
|
||||
#define SPROUT_COMPOST_UTILITY_EQUAL_TEMPERAMENT_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/math/pow.hpp>
|
||||
#include <sprout/type_traits/float_promote.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace compost {
|
||||
//
|
||||
// equal_temperament_value
|
||||
//
|
||||
template<typename ArithmeticType1, typename ArithmeticType2>
|
||||
SPROUT_CONSTEXPR typename sprout::float_promote<ArithmeticType1, ArithmeticType2>::type
|
||||
equal_temperament_value(ArithmeticType1 i, ArithmeticType2 div) {
|
||||
typedef typename sprout::float_promote<ArithmeticType1, ArithmeticType2>::type type;
|
||||
using sprout::pow;
|
||||
return pow(type(2), type(i) / type(div));
|
||||
}
|
||||
template<typename ArithmeticType>
|
||||
SPROUT_CONSTEXPR typename sprout::float_promote<ArithmeticType, int>::type
|
||||
equal_temperament_value(ArithmeticType i) {
|
||||
return sprout::compost::equal_temperament_value(i, 12);
|
||||
}
|
||||
} // namespace compost
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_COMPOST_UTILITY_EQUAL_TEMPERAMENT_HPP
|
|
@ -48,7 +48,7 @@ namespace sprout {
|
|||
private:
|
||||
typedef Res (Class::*functor)(Args...);
|
||||
private:
|
||||
functor pmf_;
|
||||
Res (Class::*pmf_)(Args...);
|
||||
private:
|
||||
template<typename T>
|
||||
Res call(T& object, Class const volatile*, Args... args) const {
|
||||
|
@ -59,7 +59,7 @@ namespace sprout {
|
|||
return ((*ptr).*pmf_)(sprout::forward<Args>(args)...);
|
||||
}
|
||||
public:
|
||||
explicit SPROUT_CONSTEXPR mem_fn_adaptor(functor pmf)
|
||||
explicit SPROUT_CONSTEXPR mem_fn_adaptor(Res (Class::*pmf)(Args...))
|
||||
: pmf_(pmf)
|
||||
{}
|
||||
Res operator()(Class& object, Args... args) const {
|
||||
|
@ -82,7 +82,7 @@ namespace sprout {
|
|||
private:
|
||||
typedef Res (Class::*functor)(Args...) const;
|
||||
private:
|
||||
functor pmf_;
|
||||
Res (Class::*pmf_)(Args...) const;
|
||||
private:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR Res call(T const& object, Class const volatile*, Args... args) const {
|
||||
|
@ -93,7 +93,7 @@ namespace sprout {
|
|||
return ((*ptr).*pmf_)(sprout::forward<Args>(args)...);
|
||||
}
|
||||
public:
|
||||
explicit SPROUT_CONSTEXPR mem_fn_adaptor(functor pmf)
|
||||
explicit SPROUT_CONSTEXPR mem_fn_adaptor(Res (Class::*pmf)(Args...) const)
|
||||
: pmf_(pmf)
|
||||
{}
|
||||
SPROUT_CONSTEXPR Res operator()(Class const& object, Args... args) const {
|
||||
|
@ -116,7 +116,7 @@ namespace sprout {
|
|||
private:
|
||||
typedef Res (Class::*functor)(Args...) volatile;
|
||||
private:
|
||||
functor pmf_;
|
||||
Res (Class::*pmf_)(Args...) volatile;
|
||||
private:
|
||||
template<typename T>
|
||||
Res call(T& object, Class const volatile*, Args... args) const {
|
||||
|
@ -127,7 +127,7 @@ namespace sprout {
|
|||
return ((*ptr).*pmf_)(sprout::forward<Args>(args)...);
|
||||
}
|
||||
public:
|
||||
explicit SPROUT_CONSTEXPR mem_fn_adaptor(functor pmf)
|
||||
explicit SPROUT_CONSTEXPR mem_fn_adaptor(Res (Class::*pmf)(Args...) volatile)
|
||||
: pmf_(pmf)
|
||||
{}
|
||||
Res operator()(Class volatile& object, Args... args) const {
|
||||
|
@ -150,7 +150,7 @@ namespace sprout {
|
|||
private:
|
||||
typedef Res (Class::*functor)(Args...) const volatile;
|
||||
private:
|
||||
functor pmf_;
|
||||
Res (Class::*pmf_)(Args...) const volatile;
|
||||
private:
|
||||
template<typename T>
|
||||
SPROUT_CONSTEXPR Res call(T const& object, Class const volatile*, Args... args) const {
|
||||
|
@ -161,7 +161,7 @@ namespace sprout {
|
|||
return ((*ptr).*pmf_)(sprout::forward<Args>(args)...);
|
||||
}
|
||||
public:
|
||||
explicit SPROUT_CONSTEXPR mem_fn_adaptor(functor pmf)
|
||||
explicit SPROUT_CONSTEXPR mem_fn_adaptor(Res (Class::*pmf)(Args...) const volatile)
|
||||
: pmf_(pmf)
|
||||
{}
|
||||
SPROUT_CONSTEXPR Res operator()(Class const volatile& object, Args... args) const {
|
||||
|
|
|
@ -34,14 +34,14 @@ namespace sprout {
|
|||
typedef typename std::iterator_traits<iterator_type>::reference reference;
|
||||
protected:
|
||||
iterator_type current;
|
||||
compare_type comp;
|
||||
Compare comp;
|
||||
value_type low;
|
||||
value_type up;
|
||||
private:
|
||||
public:
|
||||
clamp_iterator() = default;
|
||||
clamp_iterator(clamp_iterator const&) = default;
|
||||
SPROUT_CONSTEXPR clamp_iterator(iterator_type it, value_type const& low, value_type const& up, compare_type comp = compare_type())
|
||||
SPROUT_CONSTEXPR clamp_iterator(iterator_type it, value_type const& low, value_type const& up, Compare comp = Compare())
|
||||
: current(it), comp(comp), low(low), up(up)
|
||||
{}
|
||||
template<typename U, typename V>
|
||||
|
@ -57,7 +57,7 @@ namespace sprout {
|
|||
SPROUT_CONSTEXPR iterator_type const& base() const {
|
||||
return current;
|
||||
}
|
||||
SPROUT_CONSTEXPR compare_type const& compare() const {
|
||||
SPROUT_CONSTEXPR Compare const& compare() const {
|
||||
return comp;
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type const& lower() const {
|
||||
|
|
8
sprout/iterator/dft.hpp
Normal file
8
sprout/iterator/dft.hpp
Normal file
|
@ -0,0 +1,8 @@
|
|||
#ifndef SPROUT_ITERATOR_DFT_HPP
|
||||
#define SPROUT_ITERATOR_DFT_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/iterator/dft_iterator.hpp>
|
||||
#include <sprout/iterator/idft_iterator.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_ITERATOR_DFT_HPP
|
213
sprout/iterator/dft_iterator.hpp
Normal file
213
sprout/iterator/dft_iterator.hpp
Normal file
|
@ -0,0 +1,213 @@
|
|||
#ifndef SPROUT_ITERATOR_DFT_ITERATOR_HPP
|
||||
#define SPROUT_ITERATOR_DFT_ITERATOR_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/iterator/next.hpp>
|
||||
#include <sprout/iterator/prev.hpp>
|
||||
#include <sprout/iterator/distance.hpp>
|
||||
#include <sprout/utility/swap.hpp>
|
||||
#include <sprout/numeric/dft/dft_element.hpp>
|
||||
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// dft_iterator
|
||||
//
|
||||
template<typename Iterator>
|
||||
class dft_iterator
|
||||
: public std::iterator<
|
||||
std::random_access_iterator_tag,
|
||||
typename std::iterator_traits<Iterator>::value_type,
|
||||
typename std::iterator_traits<Iterator>::difference_type,
|
||||
void,
|
||||
typename std::iterator_traits<Iterator>::value_type
|
||||
>
|
||||
{
|
||||
private:
|
||||
typedef std::iterator<
|
||||
std::random_access_iterator_tag,
|
||||
typename std::iterator_traits<Iterator>::value_type,
|
||||
typename std::iterator_traits<Iterator>::difference_type,
|
||||
void,
|
||||
typename std::iterator_traits<Iterator>::value_type
|
||||
> base_type;
|
||||
public:
|
||||
typedef Iterator iterator_type;
|
||||
typedef typename base_type::iterator_category iterator_category;
|
||||
typedef typename base_type::value_type value_type;
|
||||
typedef typename base_type::difference_type difference_type;
|
||||
typedef typename base_type::pointer pointer;
|
||||
typedef typename base_type::reference reference;
|
||||
private:
|
||||
iterator_type first_;
|
||||
iterator_type last_;
|
||||
difference_type index_;
|
||||
difference_type size_;
|
||||
private:
|
||||
SPROUT_CONSTEXPR dft_iterator(iterator_type first, iterator_type last, difference_type index, difference_type size)
|
||||
: first_(first), last_(last), index_(index)
|
||||
, size_(size)
|
||||
{}
|
||||
public:
|
||||
SPROUT_CONSTEXPR dft_iterator()
|
||||
: first_(), last_(), index_()
|
||||
, size_()
|
||||
{}
|
||||
dft_iterator(dft_iterator const&) = default;
|
||||
SPROUT_CONSTEXPR dft_iterator(iterator_type first, iterator_type last, difference_type index = 0)
|
||||
: first_(first), last_(last), index_(index)
|
||||
, size_(NS_SSCRISK_CEL_OR_SPROUT::distance(first, last))
|
||||
{}
|
||||
SPROUT_CONSTEXPR dft_iterator next() const {
|
||||
return dft_iterator(first_, last_, index_, index_ + 1, size_);
|
||||
}
|
||||
SPROUT_CONSTEXPR dft_iterator prev() const {
|
||||
return dft_iterator(first_, last_, index_, index_ - 1, size_);
|
||||
}
|
||||
void swap(dft_iterator& other)
|
||||
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::swap(first_, other.first_)) && SPROUT_NOEXCEPT_EXPR(sprout::swap(last_, other.last_)))
|
||||
{
|
||||
sprout::swap(first_, other.first_);
|
||||
sprout::swap(last_, other.last_);
|
||||
sprout::swap(index_, other.index_);
|
||||
sprout::swap(size_, other.size_);
|
||||
}
|
||||
friend SPROUT_CONSTEXPR bool operator==(dft_iterator const& lhs, dft_iterator const& rhs) {
|
||||
return lhs.index_ == rhs.index_;
|
||||
}
|
||||
friend SPROUT_CONSTEXPR bool operator!=(dft_iterator const& lhs, dft_iterator const& rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
friend SPROUT_CONSTEXPR bool operator<(dft_iterator const& lhs, dft_iterator const& rhs) {
|
||||
return lhs.index_ < rhs.index_;
|
||||
}
|
||||
friend SPROUT_CONSTEXPR bool operator>(dft_iterator const& lhs, dft_iterator const& rhs) {
|
||||
return rhs < lhs;
|
||||
}
|
||||
friend SPROUT_CONSTEXPR bool operator<=(dft_iterator const& lhs, dft_iterator const& rhs) {
|
||||
return !(rhs < lhs);
|
||||
}
|
||||
friend SPROUT_CONSTEXPR bool operator>=(dft_iterator const& lhs, dft_iterator const& rhs) {
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
SPROUT_CONSTEXPR reference operator*() const {
|
||||
return sprout::detail::dft_element_impl(first_, last_, index_, size_);
|
||||
}
|
||||
dft_iterator& operator++() {
|
||||
dft_iterator temp(next());
|
||||
temp.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
dft_iterator operator++(int) {
|
||||
dft_iterator result(*this);
|
||||
++*this;
|
||||
return result;
|
||||
}
|
||||
dft_iterator& operator--() {
|
||||
dft_iterator temp(prev());
|
||||
temp.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
dft_iterator operator--(int) {
|
||||
dft_iterator result(*this);
|
||||
--*this;
|
||||
return result;
|
||||
}
|
||||
SPROUT_CONSTEXPR dft_iterator operator+(difference_type n) const {
|
||||
return dft_iterator(first_, last_, index_, index_ + n, size_);
|
||||
}
|
||||
SPROUT_CONSTEXPR dft_iterator operator-(difference_type n) const {
|
||||
return dft_iterator(first_, last_, index_, index_ - n, size_);
|
||||
}
|
||||
dft_iterator& operator+=(difference_type n) {
|
||||
dft_iterator temp(first_, last_, index_, index_ + n, size_);
|
||||
temp.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
dft_iterator& operator-=(difference_type n) {
|
||||
dft_iterator temp(first_, last_, index_, index_ - n, size_);
|
||||
temp.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CONSTEXPR reference operator[](difference_type n) const {
|
||||
return sprout::detail::dft_element_impl(first_, last_, index_ + n, size_);
|
||||
}
|
||||
friend SPROUT_CONSTEXPR difference_type operator-(dft_iterator const& lhs, dft_iterator const& rhs) {
|
||||
return lhs.index_ - rhs.index_;
|
||||
}
|
||||
friend SPROUT_CONSTEXPR dft_iterator operator+(difference_type n, dft_iterator const& it) {
|
||||
return it + n;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// make_dft_iterator
|
||||
//
|
||||
template<typename Iterator>
|
||||
inline SPROUT_CONSTEXPR sprout::dft_iterator<Iterator>
|
||||
make_dft_iterator(Iterator first, Iterator last, typename std::iterator_traits<Iterator>::difference_type i = 0) {
|
||||
return sprout::dft_iterator<Iterator>(first, last, i);
|
||||
}
|
||||
|
||||
//
|
||||
// swap
|
||||
//
|
||||
template<typename Iterator>
|
||||
inline void
|
||||
swap(sprout::dft_iterator<Iterator>& lhs, sprout::dft_iterator<Iterator>& rhs)
|
||||
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs)))
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
//
|
||||
// iterator_distance
|
||||
//
|
||||
template<typename Iterator>
|
||||
inline SPROUT_CONSTEXPR typename std::iterator_traits<sprout::dft_iterator<Iterator> >::difference_type
|
||||
iterator_distance(sprout::dft_iterator<Iterator> first, sprout::dft_iterator<Iterator> last) {
|
||||
return last - first;
|
||||
}
|
||||
|
||||
//
|
||||
// iterator_next
|
||||
//
|
||||
template<typename Iterator>
|
||||
inline SPROUT_CONSTEXPR sprout::dft_iterator<Iterator>
|
||||
iterator_next(sprout::dft_iterator<Iterator> const& it) {
|
||||
return it.next();
|
||||
}
|
||||
template<typename Iterator>
|
||||
inline SPROUT_CONSTEXPR sprout::dft_iterator<Iterator>
|
||||
iterator_next(
|
||||
sprout::dft_iterator<Iterator> const& it,
|
||||
typename sprout::dft_iterator<Iterator>::difference_type n
|
||||
)
|
||||
{
|
||||
return it + n;
|
||||
}
|
||||
|
||||
//
|
||||
// iterator_prev
|
||||
//
|
||||
template<typename Iterator>
|
||||
inline SPROUT_CONSTEXPR sprout::dft_iterator<Iterator>
|
||||
iterator_prev(sprout::dft_iterator<Iterator> const& it) {
|
||||
return it.prev();
|
||||
}
|
||||
template<typename Iterator>
|
||||
inline SPROUT_CONSTEXPR sprout::dft_iterator<Iterator>
|
||||
iterator_prev(
|
||||
sprout::dft_iterator<Iterator> const& it,
|
||||
typename sprout::dft_iterator<Iterator>::difference_type n
|
||||
)
|
||||
{
|
||||
return it - n;
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ITERATOR_DFT_ITERATOR_HPP
|
|
@ -43,10 +43,10 @@ namespace sprout {
|
|||
private:
|
||||
struct private_constructor_tag {};
|
||||
private:
|
||||
static SPROUT_CONSTEXPR iterator_type find_next(iterator_type first, iterator_type last, predicate_type pred) {
|
||||
static SPROUT_CONSTEXPR iterator_type find_next(iterator_type first, iterator_type last, Predicate pred) {
|
||||
return sprout::find_if(first, last, pred);
|
||||
}
|
||||
static SPROUT_CONSTEXPR iterator_type find_prev(iterator_type first, predicate_type pred) {
|
||||
static SPROUT_CONSTEXPR iterator_type find_prev(iterator_type first, Predicate pred) {
|
||||
return pred(*first) ? first
|
||||
: find_prev(sprout::prev(first), pred)
|
||||
;
|
||||
|
@ -54,7 +54,7 @@ namespace sprout {
|
|||
protected:
|
||||
iterator_type current;
|
||||
iterator_type last;
|
||||
predicate_type pred;
|
||||
Predicate pred;
|
||||
private:
|
||||
void satisfy_predicate() {
|
||||
while (current != last && !pred(*current)) {
|
||||
|
@ -66,7 +66,7 @@ namespace sprout {
|
|||
--current;
|
||||
}
|
||||
}
|
||||
SPROUT_CONSTEXPR filter_iterator(predicate_type pred, iterator_type it, iterator_type last, private_constructor_tag)
|
||||
SPROUT_CONSTEXPR filter_iterator(Predicate pred, iterator_type it, iterator_type last, private_constructor_tag)
|
||||
: current(it)
|
||||
, last(last)
|
||||
, pred(pred)
|
||||
|
@ -74,7 +74,7 @@ namespace sprout {
|
|||
public:
|
||||
filter_iterator() = default;
|
||||
filter_iterator(filter_iterator const&) = default;
|
||||
SPROUT_CONSTEXPR filter_iterator(predicate_type pred, iterator_type it, iterator_type last = iterator_type())
|
||||
SPROUT_CONSTEXPR filter_iterator(Predicate pred, iterator_type it, iterator_type last = iterator_type())
|
||||
: current(find_next(it, last, pred))
|
||||
, last(last)
|
||||
, pred(pred)
|
||||
|
@ -97,7 +97,7 @@ namespace sprout {
|
|||
SPROUT_CONSTEXPR iterator_type end() const {
|
||||
return last;
|
||||
}
|
||||
SPROUT_CONSTEXPR predicate_type predicate() const {
|
||||
SPROUT_CONSTEXPR Predicate predicate() const {
|
||||
return pred;
|
||||
}
|
||||
SPROUT_CONSTEXPR reference operator*() const {
|
||||
|
|
213
sprout/iterator/idft_iterator.hpp
Normal file
213
sprout/iterator/idft_iterator.hpp
Normal file
|
@ -0,0 +1,213 @@
|
|||
#ifndef SPROUT_ITERATOR_IDFT_ITERATOR_HPP
|
||||
#define SPROUT_ITERATOR_IDFT_ITERATOR_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <utility>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/iterator/next.hpp>
|
||||
#include <sprout/iterator/prev.hpp>
|
||||
#include <sprout/iterator/distance.hpp>
|
||||
#include <sprout/utility/swap.hpp>
|
||||
#include <sprout/numeric/dft/idft_element.hpp>
|
||||
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// idft_iterator
|
||||
//
|
||||
template<typename Iterator>
|
||||
class idft_iterator
|
||||
: public std::iterator<
|
||||
std::random_access_iterator_tag,
|
||||
typename std::iterator_traits<Iterator>::value_type,
|
||||
typename std::iterator_traits<Iterator>::difference_type,
|
||||
void,
|
||||
typename std::iterator_traits<Iterator>::value_type
|
||||
>
|
||||
{
|
||||
private:
|
||||
typedef std::iterator<
|
||||
std::random_access_iterator_tag,
|
||||
typename std::iterator_traits<Iterator>::value_type,
|
||||
typename std::iterator_traits<Iterator>::difference_type,
|
||||
void,
|
||||
typename std::iterator_traits<Iterator>::value_type
|
||||
> base_type;
|
||||
public:
|
||||
typedef Iterator iterator_type;
|
||||
typedef typename base_type::iterator_category iterator_category;
|
||||
typedef typename base_type::value_type value_type;
|
||||
typedef typename base_type::difference_type difference_type;
|
||||
typedef typename base_type::pointer pointer;
|
||||
typedef typename base_type::reference reference;
|
||||
private:
|
||||
iterator_type first_;
|
||||
iterator_type last_;
|
||||
difference_type index_;
|
||||
difference_type size_;
|
||||
private:
|
||||
SPROUT_CONSTEXPR idft_iterator(iterator_type first, iterator_type last, difference_type index, difference_type size)
|
||||
: first_(first), last_(last), index_(index)
|
||||
, size_(size)
|
||||
{}
|
||||
public:
|
||||
SPROUT_CONSTEXPR idft_iterator()
|
||||
: first_(), last_(), index_()
|
||||
, size_()
|
||||
{}
|
||||
idft_iterator(idft_iterator const&) = default;
|
||||
SPROUT_CONSTEXPR idft_iterator(iterator_type first, iterator_type last, difference_type index = 0)
|
||||
: first_(first), last_(last), index_(index)
|
||||
, size_(NS_SSCRISK_CEL_OR_SPROUT::distance(first, last))
|
||||
{}
|
||||
SPROUT_CONSTEXPR idft_iterator next() const {
|
||||
return idft_iterator(first_, last_, index_, index_ + 1, size_);
|
||||
}
|
||||
SPROUT_CONSTEXPR idft_iterator prev() const {
|
||||
return idft_iterator(first_, last_, index_, index_ - 1, size_);
|
||||
}
|
||||
void swap(idft_iterator& other)
|
||||
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::swap(first_, other.first_)) && SPROUT_NOEXCEPT_EXPR(sprout::swap(last_, other.last_)))
|
||||
{
|
||||
sprout::swap(first_, other.first_);
|
||||
sprout::swap(last_, other.last_);
|
||||
sprout::swap(index_, other.index_);
|
||||
sprout::swap(size_, other.size_);
|
||||
}
|
||||
friend SPROUT_CONSTEXPR bool operator==(idft_iterator const& lhs, idft_iterator const& rhs) {
|
||||
return lhs.index_ == rhs.index_;
|
||||
}
|
||||
friend SPROUT_CONSTEXPR bool operator!=(idft_iterator const& lhs, idft_iterator const& rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
friend SPROUT_CONSTEXPR bool operator<(idft_iterator const& lhs, idft_iterator const& rhs) {
|
||||
return lhs.index_ < rhs.index_;
|
||||
}
|
||||
friend SPROUT_CONSTEXPR bool operator>(idft_iterator const& lhs, idft_iterator const& rhs) {
|
||||
return rhs < lhs;
|
||||
}
|
||||
friend SPROUT_CONSTEXPR bool operator<=(idft_iterator const& lhs, idft_iterator const& rhs) {
|
||||
return !(rhs < lhs);
|
||||
}
|
||||
friend SPROUT_CONSTEXPR bool operator>=(idft_iterator const& lhs, idft_iterator const& rhs) {
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
SPROUT_CONSTEXPR reference operator*() const {
|
||||
return sprout::detail::idft_element_impl(first_, last_, index_, size_);
|
||||
}
|
||||
idft_iterator& operator++() {
|
||||
idft_iterator temp(next());
|
||||
temp.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
idft_iterator operator++(int) {
|
||||
idft_iterator result(*this);
|
||||
++*this;
|
||||
return result;
|
||||
}
|
||||
idft_iterator& operator--() {
|
||||
idft_iterator temp(prev());
|
||||
temp.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
idft_iterator operator--(int) {
|
||||
idft_iterator result(*this);
|
||||
--*this;
|
||||
return result;
|
||||
}
|
||||
SPROUT_CONSTEXPR idft_iterator operator+(difference_type n) const {
|
||||
return idft_iterator(first_, last_, index_, index_ + n, size_);
|
||||
}
|
||||
SPROUT_CONSTEXPR idft_iterator operator-(difference_type n) const {
|
||||
return idft_iterator(first_, last_, index_, index_ - n, size_);
|
||||
}
|
||||
idft_iterator& operator+=(difference_type n) {
|
||||
idft_iterator temp(first_, last_, index_, index_ + n, size_);
|
||||
temp.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
idft_iterator& operator-=(difference_type n) {
|
||||
idft_iterator temp(first_, last_, index_, index_ - n, size_);
|
||||
temp.swap(*this);
|
||||
return *this;
|
||||
}
|
||||
SPROUT_CONSTEXPR reference operator[](difference_type n) const {
|
||||
return sprout::detail::idft_element_impl(first_, last_, index_ + n, size_);
|
||||
}
|
||||
friend SPROUT_CONSTEXPR difference_type operator-(idft_iterator const& lhs, idft_iterator const& rhs) {
|
||||
return lhs.index_ - rhs.index_;
|
||||
}
|
||||
friend SPROUT_CONSTEXPR idft_iterator operator+(difference_type n, idft_iterator const& it) {
|
||||
return it + n;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// make_idft_iterator
|
||||
//
|
||||
template<typename Iterator>
|
||||
inline SPROUT_CONSTEXPR sprout::idft_iterator<Iterator>
|
||||
make_idft_iterator(Iterator first, Iterator last, typename std::iterator_traits<Iterator>::difference_type i = 0) {
|
||||
return sprout::idft_iterator<Iterator>(first, last, i);
|
||||
}
|
||||
|
||||
//
|
||||
// swap
|
||||
//
|
||||
template<typename Iterator>
|
||||
inline void
|
||||
swap(sprout::idft_iterator<Iterator>& lhs, sprout::idft_iterator<Iterator>& rhs)
|
||||
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs)))
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
//
|
||||
// iterator_distance
|
||||
//
|
||||
template<typename Iterator>
|
||||
inline SPROUT_CONSTEXPR typename std::iterator_traits<sprout::idft_iterator<Iterator> >::difference_type
|
||||
iterator_distance(sprout::idft_iterator<Iterator> first, sprout::idft_iterator<Iterator> last) {
|
||||
return last - first;
|
||||
}
|
||||
|
||||
//
|
||||
// iterator_next
|
||||
//
|
||||
template<typename Iterator>
|
||||
inline SPROUT_CONSTEXPR sprout::idft_iterator<Iterator>
|
||||
iterator_next(sprout::idft_iterator<Iterator> const& it) {
|
||||
return it.next();
|
||||
}
|
||||
template<typename Iterator>
|
||||
inline SPROUT_CONSTEXPR sprout::idft_iterator<Iterator>
|
||||
iterator_next(
|
||||
sprout::idft_iterator<Iterator> const& it,
|
||||
typename sprout::idft_iterator<Iterator>::difference_type n
|
||||
)
|
||||
{
|
||||
return it + n;
|
||||
}
|
||||
|
||||
//
|
||||
// iterator_prev
|
||||
//
|
||||
template<typename Iterator>
|
||||
inline SPROUT_CONSTEXPR sprout::idft_iterator<Iterator>
|
||||
iterator_prev(sprout::idft_iterator<Iterator> const& it) {
|
||||
return it.prev();
|
||||
}
|
||||
template<typename Iterator>
|
||||
inline SPROUT_CONSTEXPR sprout::idft_iterator<Iterator>
|
||||
iterator_prev(
|
||||
sprout::idft_iterator<Iterator> const& it,
|
||||
typename sprout::idft_iterator<Iterator>::difference_type n
|
||||
)
|
||||
{
|
||||
return it - n;
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_ITERATOR_IDFT_ITERATOR_HPP
|
|
@ -5,5 +5,6 @@
|
|||
#include <sprout/iterator/various.hpp>
|
||||
#include <sprout/iterator/adaptor.hpp>
|
||||
#include <sprout/iterator/wave.hpp>
|
||||
#include <sprout/iterator/dft.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_ITERATOR_PREDEFINED_HPP
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
#include <sprout/config.hpp>
|
||||
#include <sprout/math/detail/config.hpp>
|
||||
#include <sprout/math/factorial.hpp>
|
||||
#include <sprout/math/fmod.hpp>
|
||||
#include <sprout/math/constants.hpp>
|
||||
#include <sprout/math/fmod.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
|
||||
namespace sprout {
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
#include <sprout/numeric/dft/dft_element.hpp>
|
||||
#include <sprout/numeric/dft/idft_element.hpp>
|
||||
#include <sprout/numeric/dft/spectrum.hpp>
|
||||
#include <sprout/numeric/dft/amplitude_spectrum_value.hpp>
|
||||
#include <sprout/numeric/dft/phase_spectrum_value.hpp>
|
||||
#include <sprout/numeric/dft/wave.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_NUMERIC_DFT_HPP
|
||||
|
|
21
sprout/numeric/dft/amplitude_spectrum_value.hpp
Normal file
21
sprout/numeric/dft/amplitude_spectrum_value.hpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#ifndef SPROUT_NUMERIC_DFT_AMPLITUDE_SPECTRUM_VALUE_HPP
|
||||
#define SPROUT_NUMERIC_DFT_AMPLITUDE_SPECTRUM_VALUE_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/complex.hpp>
|
||||
#include <sprout/math/sqrt.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// amplitude_spectrum_value
|
||||
//
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR typename T::value_type
|
||||
amplitude_spectrum_value(T const& x) {
|
||||
using sprout::real;
|
||||
using sprout::imag;
|
||||
return sprout::sqrt(real(x) * real(x) + imag(x) * imag(x));
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_NUMERIC_DFT_AMPLITUDE_SPECTRUM_VALUE_HPP
|
|
@ -7,12 +7,48 @@
|
|||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/math/sin.hpp>
|
||||
#include <sprout/math/cos.hpp>
|
||||
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT
|
||||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
template<typename RandomAccessIterator>
|
||||
inline SPROUT_CONSTEXPR typename std::iterator_traits<RandomAccessIterator>::value_type
|
||||
dft_element_gen_impl_ra(
|
||||
RandomAccessIterator first, RandomAccessIterator last,
|
||||
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(
|
||||
sprout::next(first, pivot), last, arg, (NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) - pivot) / 2, k + pivot
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename RandomAccessIterator>
|
||||
inline SPROUT_CONSTEXPR typename std::iterator_traits<RandomAccessIterator>::value_type
|
||||
dft_element_gen_impl(
|
||||
RandomAccessIterator first, RandomAccessIterator last,
|
||||
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()
|
||||
: sprout::detail::dft_element_gen_impl_ra(first, last, arg, NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2)
|
||||
;
|
||||
}
|
||||
|
||||
template<typename InputIterator>
|
||||
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::value_type
|
||||
dft_element_gen(
|
||||
dft_element_gen_impl_1(
|
||||
InputIterator first, InputIterator last,
|
||||
typename std::iterator_traits<InputIterator>::value_type::value_type arg,
|
||||
typename std::iterator_traits<InputIterator>::difference_type k = 0,
|
||||
|
@ -25,18 +61,42 @@ namespace sprout {
|
|||
typedef typename std::iterator_traits<InputIterator>::value_type value_type;
|
||||
using sprout::cos;
|
||||
using sprout::sin;
|
||||
return first != last
|
||||
? value + sprout::detail::dft_element_gen(
|
||||
sprout::next(first),
|
||||
last,
|
||||
return first == last ? value
|
||||
: value + sprout::detail::dft_element_gen_impl_1(
|
||||
sprout::next(first), last,
|
||||
arg,
|
||||
k + 1,
|
||||
*first * value_type(cos(theta), sin(theta)),
|
||||
arg * (k + 1)
|
||||
)
|
||||
: value
|
||||
;
|
||||
}
|
||||
template<typename InputIterator>
|
||||
inline SPROUT_CONSTEXPR typename std::iterator_traits<InputIterator>::value_type
|
||||
dft_element_gen_impl(
|
||||
InputIterator first, InputIterator last,
|
||||
typename std::iterator_traits<InputIterator>::value_type::value_type arg,
|
||||
void*
|
||||
)
|
||||
{
|
||||
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(
|
||||
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>::iterator_category* category;
|
||||
return sprout::detail::dft_element_gen_impl(first, last, arg, category());
|
||||
}
|
||||
} // namespace detail
|
||||
} // namespace sprout
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef SPROUT_NUMERIC_DFT_FIXED_DFT_ELEMENT_HPP
|
||||
#define SPROUT_NUMERIC_DFT_FIXED_DFT_ELEMENT_HPP
|
||||
#ifndef SPROUT_NUMERIC_DFT_DFT_ELEMENT_HPP
|
||||
#define SPROUT_NUMERIC_DFT_DFT_ELEMENT_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <sprout/config.hpp>
|
||||
|
@ -38,4 +38,4 @@ namespace sprout {
|
|||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_NUMERIC_DFT_FIXED_DFT_ELEMENT_HPP
|
||||
#endif // #ifndef SPROUT_NUMERIC_DFT_DFT_ELEMENT_HPP
|
||||
|
|
|
@ -7,8 +7,7 @@
|
|||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/algorithm/fixed/result_of.hpp>
|
||||
#include <sprout/complex.hpp>
|
||||
#include <sprout/math/sqrt.hpp>
|
||||
#include <sprout/numeric/dft/amplitude_spectrum_value.hpp>
|
||||
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT
|
||||
|
||||
namespace sprout {
|
||||
|
@ -24,16 +23,11 @@ namespace sprout {
|
|||
typename sprout::container_traits<Result>::size_type input_size
|
||||
)
|
||||
{
|
||||
using sprout::real;
|
||||
using sprout::imag;
|
||||
return sprout::remake<Result>(
|
||||
result,
|
||||
size,
|
||||
(Indexes >= offset && Indexes < offset + size && Indexes < offset + input_size
|
||||
? sprout::sqrt(
|
||||
real(*sprout::next(first, Indexes)) * real(*sprout::next(first, Indexes))
|
||||
+ imag(*sprout::next(first, Indexes)) * imag(*sprout::next(first, Indexes))
|
||||
)
|
||||
? sprout::amplitude_spectrum_value(*sprout::next(first, Indexes))
|
||||
: *sprout::next(sprout::internal_begin(result), Indexes)
|
||||
)...
|
||||
);
|
||||
|
|
|
@ -7,9 +7,7 @@
|
|||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/operation.hpp>
|
||||
#include <sprout/algorithm/fixed/result_of.hpp>
|
||||
#include <sprout/complex.hpp>
|
||||
#include <sprout/math/atan2.hpp>
|
||||
#include <sprout/math/llround.hpp>
|
||||
#include <sprout/numeric/dft/phase_spectrum_value.hpp>
|
||||
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT
|
||||
|
||||
namespace sprout {
|
||||
|
@ -31,10 +29,7 @@ namespace sprout {
|
|||
result,
|
||||
size,
|
||||
(Indexes >= offset && Indexes < offset + size && Indexes < offset + input_size
|
||||
? sprout::atan2(
|
||||
sprout::llround(imag(*sprout::next(first, Indexes))),
|
||||
sprout::llround(real(*sprout::next(first, Indexes)))
|
||||
)
|
||||
? sprout::phase_spectrum_value(*sprout::next(first, Indexes))
|
||||
: *sprout::next(sprout::internal_begin(result), Indexes)
|
||||
)...
|
||||
);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#ifndef SPROUT_NUMERIC_DFT_FIXED_IDFT_ELEMENT_HPP
|
||||
#define SPROUT_NUMERIC_DFT_FIXED_IDFT_ELEMENT_HPP
|
||||
#ifndef SPROUT_NUMERIC_DFT_IDFT_ELEMENT_HPP
|
||||
#define SPROUT_NUMERIC_DFT_IDFT_ELEMENT_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <sprout/config.hpp>
|
||||
|
@ -40,4 +40,4 @@ namespace sprout {
|
|||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_NUMERIC_DFT_FIXED_IDFT_ELEMENT_HPP
|
||||
#endif // #ifndef SPROUT_NUMERIC_DFT_IDFT_ELEMENT_HPP
|
||||
|
|
22
sprout/numeric/dft/phase_spectrum_value.hpp
Normal file
22
sprout/numeric/dft/phase_spectrum_value.hpp
Normal file
|
@ -0,0 +1,22 @@
|
|||
#ifndef SPROUT_NUMERIC_DFT_PHASE_SPECTRUM_VALUE_HPP
|
||||
#define SPROUT_NUMERIC_DFT_PHASE_SPECTRUM_VALUE_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/complex.hpp>
|
||||
#include <sprout/math/atan2.hpp>
|
||||
#include <sprout/math/llround.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// phase_spectrum_value
|
||||
//
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR typename T::value_type
|
||||
phase_spectrum_value(T const& x) {
|
||||
using sprout::real;
|
||||
using sprout::imag;
|
||||
return sprout::atan2(sprout::llround(imag(x)), sprout::llround(real(x)));
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_NUMERIC_DFT_PHASE_SPECTRUM_VALUE_HPP
|
|
@ -4,5 +4,7 @@
|
|||
#include <sprout/config.hpp>
|
||||
#include <sprout/numeric/accumulate.hpp>
|
||||
#include <sprout/numeric/inner_product.hpp>
|
||||
#include <sprout/numeric/unstable_accumulate.hpp>
|
||||
#include <sprout/numeric/unstable_inner_product.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_NUMERIC_NON_MODIFYIING_HPP
|
||||
|
|
81
sprout/numeric/unstable_accumulate.hpp
Normal file
81
sprout/numeric/unstable_accumulate.hpp
Normal file
|
@ -0,0 +1,81 @@
|
|||
#ifndef SPROUT_NUMERIC_UNSTABLE_ACCUMLATE_HPP
|
||||
#define SPROUT_NUMERIC_UNSTABLE_ACCUMLATE_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/numeric/accumulate.hpp>
|
||||
#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT
|
||||
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// unstable_accumulate
|
||||
//
|
||||
namespace detail {
|
||||
template<typename T, typename RandomAccessIterator, typename BinaryOperation>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
unstable_accumulate_ra(
|
||||
RandomAccessIterator first, RandomAccessIterator last, BinaryOperation binary_op,
|
||||
typename std::iterator_traits<RandomAccessIterator>::difference_type pivot
|
||||
)
|
||||
{
|
||||
return pivot == 0 ? *first
|
||||
: binary_op(
|
||||
sprout::detail::unstable_accumulate_ra<T>(
|
||||
first, sprout::next(first, pivot), binary_op,
|
||||
pivot / 2
|
||||
),
|
||||
sprout::detail::unstable_accumulate_ra<T>(
|
||||
sprout::next(first, pivot), last, binary_op,
|
||||
(NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) - pivot) / 2
|
||||
)
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename RandomAccessIterator, typename T, typename BinaryOperation>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
unstable_accumulate(
|
||||
RandomAccessIterator first, RandomAccessIterator last, T init, BinaryOperation binary_op,
|
||||
std::random_access_iterator_tag*
|
||||
)
|
||||
{
|
||||
return first == last ? init
|
||||
: binary_op(
|
||||
init,
|
||||
sprout::detail::unstable_accumulate_ra<T>(
|
||||
first, last, binary_op,
|
||||
NS_SSCRISK_CEL_OR_SPROUT::distance(first, last) / 2
|
||||
)
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
template<typename InputIterator, typename T, typename BinaryOperation>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
unstable_accumulate(
|
||||
InputIterator first, InputIterator last, T init, BinaryOperation binary_op,
|
||||
void*
|
||||
)
|
||||
{
|
||||
return sprout::accumulate(first, last, init, binary_op);
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
template<typename InputIterator, typename T, typename BinaryOperation>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
unstable_accumulate(InputIterator first, InputIterator last, T init, BinaryOperation binary_op) {
|
||||
typedef typename std::iterator_traits<InputIterator>::iterator_category* category;
|
||||
return sprout::detail::unstable_accumulate(first, last, init, binary_op, category());
|
||||
}
|
||||
|
||||
template<typename InputIterator, typename T>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
unstable_accumulate(InputIterator first, InputIterator last, T init) {
|
||||
return sprout::unstable_accumulate(
|
||||
first, last, init,
|
||||
NS_SSCRISK_CEL_OR_SPROUT::plus<typename std::iterator_traits<InputIterator>::value_type>()
|
||||
);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_NUMERIC_UNSTABLE_ACCUMLATE_HPP
|
89
sprout/numeric/unstable_inner_product.hpp
Normal file
89
sprout/numeric/unstable_inner_product.hpp
Normal file
|
@ -0,0 +1,89 @@
|
|||
#ifndef SPROUT_NUMERIC_UNSTABLE_INNNER_PRODUCT_HPP
|
||||
#define SPROUT_NUMERIC_UNSTABLE_INNNER_PRODUCT_HPP
|
||||
|
||||
#include <iterator>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/numeric/inner_product.hpp>
|
||||
#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT
|
||||
#include HDR_ITERATOR_SSCRISK_CEL_OR_SPROUT
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// unstable_inner_product
|
||||
//
|
||||
namespace detail {
|
||||
template<typename T, typename RandomAccessIterator1, typename RandomAccessIterator2, typename BinaryOperation1, typename BinaryOperation2>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
unstable_inner_product_ra(
|
||||
RandomAccessIterator1 first1, RandomAccessIterator1 last1, RandomAccessIterator2 first2,
|
||||
BinaryOperation1 binary_op1, BinaryOperation2 binary_op2,
|
||||
typename std::iterator_traits<RandomAccessIterator1>::difference_type pivot
|
||||
)
|
||||
{
|
||||
return pivot == 0 ? binary_op2(*first1, *first2)
|
||||
: binary_op1(
|
||||
sprout::detail::unstable_inner_product_ra<T>(
|
||||
first1, sprout::next(first1, pivot), first2, binary_op1, binary_op2,
|
||||
pivot / 2
|
||||
),
|
||||
sprout::detail::unstable_inner_product_ra<T>(
|
||||
sprout::next(first1, pivot), last1, sprout::next(first2, pivot), binary_op1, binary_op2,
|
||||
(NS_SSCRISK_CEL_OR_SPROUT::distance(first1, last1) - pivot) / 2
|
||||
)
|
||||
)
|
||||
;
|
||||
}
|
||||
template<typename RandomAccessIterator1, typename RandomAccessIterator2, typename T, typename BinaryOperation1, typename BinaryOperation2>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
unstable_inner_product(
|
||||
RandomAccessIterator1 first1, RandomAccessIterator1 last1, RandomAccessIterator2 first2, T init,
|
||||
BinaryOperation1 binary_op1, BinaryOperation2 binary_op2,
|
||||
std::random_access_iterator_tag*
|
||||
)
|
||||
{
|
||||
return first1 == last1 ? init
|
||||
: binary_op1(
|
||||
init,
|
||||
sprout::detail::unstable_inner_product_ra<T>(
|
||||
first1, last1, first2, binary_op1, binary_op2,
|
||||
NS_SSCRISK_CEL_OR_SPROUT::distance(first1, last1) / 2
|
||||
)
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
template<typename InputIterator1, typename InputIterator2, typename T, typename BinaryOperation1, typename BinaryOperation2>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
unstable_inner_product(
|
||||
InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init,
|
||||
BinaryOperation1 binary_op1, BinaryOperation2 binary_op2,
|
||||
void*
|
||||
)
|
||||
{
|
||||
return sprout::inner_product(first1, last1, first2, init, binary_op1, binary_op2);
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
template<typename InputIterator1, typename InputIterator2, typename T, typename BinaryOperation1, typename BinaryOperation2>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
unstable_inner_product(
|
||||
InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init,
|
||||
BinaryOperation1 binary_op1, BinaryOperation2 binary_op2
|
||||
)
|
||||
{
|
||||
typedef typename std::iterator_traits<InputIterator1>::iterator_category* category;
|
||||
return sprout::detail::unstable_inner_product(first1, last1, first2, init, binary_op1, binary_op2, category());
|
||||
}
|
||||
|
||||
template<typename InputIterator1, typename InputIterator2, typename T>
|
||||
inline SPROUT_CONSTEXPR T
|
||||
unstable_inner_product(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, T init) {
|
||||
return sprout::unstable_inner_product(
|
||||
first1, last1, first2, init,
|
||||
sprout::plus<typename std::iterator_traits<InputIterator1>::value_type>(),
|
||||
NS_SSCRISK_CEL_OR_SPROUT::multiplies<typename std::iterator_traits<InputIterator1>::value_type>()
|
||||
);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_NUMERIC_UNSTABLE_INNNER_PRODUCT_HPP
|
103
sprout/range/adaptor/amplitude_spectrum.hpp
Normal file
103
sprout/range/adaptor/amplitude_spectrum.hpp
Normal file
|
@ -0,0 +1,103 @@
|
|||
#ifndef SPROUT_RANGE_ADAPTOR_AMPLITUDE_SPECTRUM_HPP
|
||||
#define SPROUT_RANGE_ADAPTOR_AMPLITUDE_SPECTRUM_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/transform_iterator.hpp>
|
||||
#include <sprout/range/adaptor/detail/adapted_range_default.hpp>
|
||||
#include <sprout/range/algorithm/copy.hpp>
|
||||
#include <sprout/type_traits/lvalue_reference.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/utility/lvalue_forward.hpp>
|
||||
#include <sprout/numeric/dft/amplitude_spectrum_value.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace adaptors {
|
||||
namespace detail {
|
||||
template<typename T>
|
||||
class amplitude_spectrum_value {
|
||||
public:
|
||||
typedef typename T::value_type result_type;
|
||||
typedef T argument_type;
|
||||
public:
|
||||
SPROUT_CONSTEXPR result_type operator()(T const& value) const {
|
||||
return sprout::amplitude_spectrum_value(value);
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
//
|
||||
// amplitude_spectrum_range
|
||||
//
|
||||
template<typename Range>
|
||||
class amplitude_spectrum_range
|
||||
: public sprout::adaptors::detail::adapted_range_default<
|
||||
Range,
|
||||
sprout::transform_iterator<
|
||||
sprout::adaptors::detail::amplitude_spectrum_value<typename sprout::container_traits<Range>::value_type>,
|
||||
typename sprout::container_traits<Range>::iterator
|
||||
>
|
||||
>
|
||||
{
|
||||
public:
|
||||
typedef sprout::adaptors::detail::adapted_range_default<
|
||||
Range,
|
||||
sprout::transform_iterator<
|
||||
sprout::adaptors::detail::amplitude_spectrum_value<typename sprout::container_traits<Range>::value_type>,
|
||||
typename sprout::container_traits<Range>::iterator
|
||||
>
|
||||
> base_type;
|
||||
typedef typename base_type::range_type range_type;
|
||||
typedef typename base_type::iterator iterator;
|
||||
typedef typename base_type::value_type value_type;
|
||||
public:
|
||||
amplitude_spectrum_range() = default;
|
||||
amplitude_spectrum_range(amplitude_spectrum_range const&) = default;
|
||||
explicit SPROUT_CONSTEXPR amplitude_spectrum_range(range_type& range)
|
||||
: base_type(
|
||||
iterator(sprout::begin(range), typename iterator::functor_type()),
|
||||
iterator(sprout::end(range), typename iterator::functor_type())
|
||||
)
|
||||
{}
|
||||
};
|
||||
|
||||
//
|
||||
// amplitude_spectrum_forwarder
|
||||
//
|
||||
class amplitude_spectrum_forwarder {};
|
||||
|
||||
//
|
||||
// amplitude_spectrum
|
||||
//
|
||||
namespace {
|
||||
SPROUT_STATIC_CONSTEXPR sprout::adaptors::amplitude_spectrum_forwarder amplitude_spectrum{};
|
||||
} // anonymous-namespace
|
||||
|
||||
//
|
||||
// operator|
|
||||
//
|
||||
template<typename Range>
|
||||
inline SPROUT_CONSTEXPR sprout::adaptors::amplitude_spectrum_range<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>
|
||||
operator|(Range&& lhs, amplitude_spectrum_forwarder) {
|
||||
return sprout::adaptors::amplitude_spectrum_range<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>(
|
||||
sprout::lvalue_forward<Range>(lhs)
|
||||
);
|
||||
}
|
||||
} // namespace adaptors
|
||||
|
||||
//
|
||||
// container_construct_traits
|
||||
//
|
||||
template<typename Range>
|
||||
struct container_construct_traits<sprout::adaptors::amplitude_spectrum_range<Range> >
|
||||
: public sprout::container_construct_traits<typename sprout::adaptors::amplitude_spectrum_range<Range>::base_type>
|
||||
{};
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_RANGE_ADAPTOR_AMPLITUDE_SPECTRUM_HPP
|
|
@ -45,14 +45,14 @@ namespace sprout {
|
|||
range_type& range,
|
||||
value_type const& low,
|
||||
value_type const& up,
|
||||
compare_type comp = compare_type()
|
||||
Compare comp = Compare()
|
||||
)
|
||||
: base_type(
|
||||
iterator(sprout::begin(range), low, up, comp),
|
||||
iterator(sprout::end(range), low, up, comp)
|
||||
)
|
||||
{}
|
||||
SPROUT_CONSTEXPR compare_type compare() const {
|
||||
SPROUT_CONSTEXPR Compare compare() const {
|
||||
return base_type::begin().compare();
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type lower() const {
|
||||
|
@ -72,14 +72,14 @@ namespace sprout {
|
|||
typedef Value value_type;
|
||||
typedef Compare compare_type;
|
||||
private:
|
||||
compare_type comp_;
|
||||
Compare comp_;
|
||||
value_type low_;
|
||||
value_type up_;
|
||||
public:
|
||||
SPROUT_CONSTEXPR clamp_holder(value_type const& low, value_type const& up, compare_type comp = compare_type())
|
||||
SPROUT_CONSTEXPR clamp_holder(value_type const& low, value_type const& up, Compare comp = Compare())
|
||||
: comp_(comp), low_(low), up_(up)
|
||||
{}
|
||||
SPROUT_CONSTEXPR compare_type const& compare() const {
|
||||
SPROUT_CONSTEXPR Compare const& compare() const {
|
||||
return comp_;
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type const& lower() const {
|
||||
|
|
83
sprout/range/adaptor/dft.hpp
Normal file
83
sprout/range/adaptor/dft.hpp
Normal file
|
@ -0,0 +1,83 @@
|
|||
#ifndef SPROUT_RANGE_ADAPTOR_DFT_HPP
|
||||
#define SPROUT_RANGE_ADAPTOR_DFT_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/dft_iterator.hpp>
|
||||
#include <sprout/range/adaptor/detail/adapted_range_default.hpp>
|
||||
#include <sprout/range/algorithm/copy.hpp>
|
||||
#include <sprout/type_traits/lvalue_reference.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/utility/lvalue_forward.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace adaptors {
|
||||
//
|
||||
// dft_range
|
||||
//
|
||||
template<typename Range>
|
||||
class dft_range
|
||||
: public sprout::adaptors::detail::adapted_range_default<
|
||||
Range,
|
||||
sprout::dft_iterator<typename sprout::container_traits<Range>::iterator>
|
||||
>
|
||||
{
|
||||
public:
|
||||
typedef sprout::adaptors::detail::adapted_range_default<
|
||||
Range,
|
||||
sprout::dft_iterator<typename sprout::container_traits<Range>::iterator>
|
||||
> base_type;
|
||||
typedef typename base_type::range_type range_type;
|
||||
typedef typename base_type::iterator iterator;
|
||||
public:
|
||||
dft_range() = default;
|
||||
dft_range(dft_range const&) = default;
|
||||
explicit SPROUT_CONSTEXPR dft_range(range_type& range)
|
||||
: base_type(
|
||||
iterator(sprout::begin(range), sprout::end(range)),
|
||||
iterator(sprout::begin(range), sprout::end(range), sprout::size(range))
|
||||
)
|
||||
{}
|
||||
};
|
||||
|
||||
//
|
||||
// dft_forwarder
|
||||
//
|
||||
class dft_forwarder {};
|
||||
|
||||
//
|
||||
// dft
|
||||
//
|
||||
namespace {
|
||||
SPROUT_STATIC_CONSTEXPR sprout::adaptors::dft_forwarder dft{};
|
||||
} // anonymous-namespace
|
||||
|
||||
//
|
||||
// operator|
|
||||
//
|
||||
template<typename Range>
|
||||
inline SPROUT_CONSTEXPR sprout::adaptors::dft_range<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>
|
||||
operator|(Range&& lhs, sprout::adaptors::dft_forwarder) {
|
||||
return sprout::adaptors::dft_range<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>(
|
||||
sprout::lvalue_forward<Range>(lhs)
|
||||
);
|
||||
}
|
||||
} // namespace adaptors
|
||||
|
||||
//
|
||||
// container_construct_traits
|
||||
//
|
||||
template<typename Range>
|
||||
struct container_construct_traits<sprout::adaptors::dft_range<Range> >
|
||||
: public sprout::container_construct_traits<typename sprout::adaptors::dft_range<Range>::base_type>
|
||||
{};
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_RANGE_ADAPTOR_DFT_HPP
|
|
@ -42,7 +42,7 @@ namespace sprout {
|
|||
public:
|
||||
filtered_range() = default;
|
||||
filtered_range(filtered_range const&) = default;
|
||||
SPROUT_CONSTEXPR filtered_range(predicate_type pred, range_type& range)
|
||||
SPROUT_CONSTEXPR filtered_range(Predicate pred, range_type& range)
|
||||
: base_type(
|
||||
iterator(pred, sprout::begin(range), sprout::end(range)),
|
||||
iterator(pred, sprout::end(range), sprout::end(range))
|
||||
|
@ -58,14 +58,14 @@ namespace sprout {
|
|||
public:
|
||||
typedef Predicate predicate_type;
|
||||
private:
|
||||
predicate_type pred_;
|
||||
Predicate pred_;
|
||||
public:
|
||||
filter_holder() = default;
|
||||
filter_holder(filter_holder const&) = default;
|
||||
SPROUT_CONSTEXPR filter_holder(predicate_type pred)
|
||||
SPROUT_CONSTEXPR filter_holder(Predicate pred)
|
||||
: pred_(pred)
|
||||
{}
|
||||
SPROUT_CONSTEXPR predicate_type predicate() const {
|
||||
SPROUT_CONSTEXPR Predicate predicate() const {
|
||||
return pred_;
|
||||
}
|
||||
};
|
||||
|
|
83
sprout/range/adaptor/idft.hpp
Normal file
83
sprout/range/adaptor/idft.hpp
Normal file
|
@ -0,0 +1,83 @@
|
|||
#ifndef SPROUT_RANGE_ADAPTOR_IDFT_HPP
|
||||
#define SPROUT_RANGE_ADAPTOR_IDFT_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/idft_iterator.hpp>
|
||||
#include <sprout/range/adaptor/detail/adapted_range_default.hpp>
|
||||
#include <sprout/range/algorithm/copy.hpp>
|
||||
#include <sprout/type_traits/lvalue_reference.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/utility/lvalue_forward.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace adaptors {
|
||||
//
|
||||
// idft_range
|
||||
//
|
||||
template<typename Range>
|
||||
class idft_range
|
||||
: public sprout::adaptors::detail::adapted_range_default<
|
||||
Range,
|
||||
sprout::idft_iterator<typename sprout::container_traits<Range>::iterator>
|
||||
>
|
||||
{
|
||||
public:
|
||||
typedef sprout::adaptors::detail::adapted_range_default<
|
||||
Range,
|
||||
sprout::idft_iterator<typename sprout::container_traits<Range>::iterator>
|
||||
> base_type;
|
||||
typedef typename base_type::range_type range_type;
|
||||
typedef typename base_type::iterator iterator;
|
||||
public:
|
||||
idft_range() = default;
|
||||
idft_range(idft_range const&) = default;
|
||||
explicit SPROUT_CONSTEXPR idft_range(range_type& range)
|
||||
: base_type(
|
||||
iterator(sprout::begin(range), sprout::end(range)),
|
||||
iterator(sprout::begin(range), sprout::end(range), sprout::size(range))
|
||||
)
|
||||
{}
|
||||
};
|
||||
|
||||
//
|
||||
// idft_forwarder
|
||||
//
|
||||
class idft_forwarder {};
|
||||
|
||||
//
|
||||
// idft
|
||||
//
|
||||
namespace {
|
||||
SPROUT_STATIC_CONSTEXPR sprout::adaptors::idft_forwarder idft{};
|
||||
} // anonymous-namespace
|
||||
|
||||
//
|
||||
// operator|
|
||||
//
|
||||
template<typename Range>
|
||||
inline SPROUT_CONSTEXPR sprout::adaptors::idft_range<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>
|
||||
operator|(Range&& lhs, sprout::adaptors::idft_forwarder) {
|
||||
return sprout::adaptors::idft_range<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>(
|
||||
sprout::lvalue_forward<Range>(lhs)
|
||||
);
|
||||
}
|
||||
} // namespace adaptors
|
||||
|
||||
//
|
||||
// container_construct_traits
|
||||
//
|
||||
template<typename Range>
|
||||
struct container_construct_traits<sprout::adaptors::idft_range<Range> >
|
||||
: public sprout::container_construct_traits<typename sprout::adaptors::idft_range<Range>::base_type>
|
||||
{};
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_RANGE_ADAPTOR_IDFT_HPP
|
103
sprout/range/adaptor/phase_spectrum.hpp
Normal file
103
sprout/range/adaptor/phase_spectrum.hpp
Normal file
|
@ -0,0 +1,103 @@
|
|||
#ifndef SPROUT_RANGE_ADAPTOR_PHASE_SPECTRUM_HPP
|
||||
#define SPROUT_RANGE_ADAPTOR_PHASE_SPECTRUM_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/pit.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/iterator/transform_iterator.hpp>
|
||||
#include <sprout/range/adaptor/detail/adapted_range_default.hpp>
|
||||
#include <sprout/range/algorithm/copy.hpp>
|
||||
#include <sprout/type_traits/lvalue_reference.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/utility/lvalue_forward.hpp>
|
||||
#include <sprout/numeric/dft/phase_spectrum_value.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace adaptors {
|
||||
namespace detail {
|
||||
template<typename T>
|
||||
class phase_spectrum_value {
|
||||
public:
|
||||
typedef typename T::value_type result_type;
|
||||
typedef T argument_type;
|
||||
public:
|
||||
SPROUT_CONSTEXPR result_type operator()(T const& value) const {
|
||||
return sprout::phase_spectrum_value(value);
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
//
|
||||
// phase_spectrum_range
|
||||
//
|
||||
template<typename Range>
|
||||
class phase_spectrum_range
|
||||
: public sprout::adaptors::detail::adapted_range_default<
|
||||
Range,
|
||||
sprout::transform_iterator<
|
||||
sprout::adaptors::detail::phase_spectrum_value<typename sprout::container_traits<Range>::value_type>,
|
||||
typename sprout::container_traits<Range>::iterator
|
||||
>
|
||||
>
|
||||
{
|
||||
public:
|
||||
typedef sprout::adaptors::detail::adapted_range_default<
|
||||
Range,
|
||||
sprout::transform_iterator<
|
||||
sprout::adaptors::detail::phase_spectrum_value<typename sprout::container_traits<Range>::value_type>,
|
||||
typename sprout::container_traits<Range>::iterator
|
||||
>
|
||||
> base_type;
|
||||
typedef typename base_type::range_type range_type;
|
||||
typedef typename base_type::iterator iterator;
|
||||
typedef typename base_type::value_type value_type;
|
||||
public:
|
||||
phase_spectrum_range() = default;
|
||||
phase_spectrum_range(phase_spectrum_range const&) = default;
|
||||
explicit SPROUT_CONSTEXPR phase_spectrum_range(range_type& range)
|
||||
: base_type(
|
||||
iterator(sprout::begin(range), typename iterator::functor_type()),
|
||||
iterator(sprout::end(range), typename iterator::functor_type())
|
||||
)
|
||||
{}
|
||||
};
|
||||
|
||||
//
|
||||
// phase_spectrum_forwarder
|
||||
//
|
||||
class phase_spectrum_forwarder {};
|
||||
|
||||
//
|
||||
// phase_spectrum
|
||||
//
|
||||
namespace {
|
||||
SPROUT_STATIC_CONSTEXPR sprout::adaptors::phase_spectrum_forwarder phase_spectrum{};
|
||||
} // anonymous-namespace
|
||||
|
||||
//
|
||||
// operator|
|
||||
//
|
||||
template<typename Range>
|
||||
inline SPROUT_CONSTEXPR sprout::adaptors::phase_spectrum_range<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>
|
||||
operator|(Range&& lhs, phase_spectrum_forwarder) {
|
||||
return sprout::adaptors::phase_spectrum_range<
|
||||
typename std::remove_reference<typename sprout::lvalue_reference<Range>::type>::type
|
||||
>(
|
||||
sprout::lvalue_forward<Range>(lhs)
|
||||
);
|
||||
}
|
||||
} // namespace adaptors
|
||||
|
||||
//
|
||||
// container_construct_traits
|
||||
//
|
||||
template<typename Range>
|
||||
struct container_construct_traits<sprout::adaptors::phase_spectrum_range<Range> >
|
||||
: public sprout::container_construct_traits<typename sprout::adaptors::phase_spectrum_range<Range>::base_type>
|
||||
{};
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_RANGE_ADAPTOR_PHASE_SPECTRUM_HPP
|
|
@ -20,7 +20,7 @@ namespace sprout {
|
|||
class replace_value {
|
||||
public:
|
||||
typedef T const& result_type;
|
||||
typedef T const& first_argument_type;
|
||||
typedef T const& argument_type;
|
||||
private:
|
||||
T old_;
|
||||
T new_;
|
||||
|
@ -61,7 +61,7 @@ namespace sprout {
|
|||
public:
|
||||
replaced_range() = default;
|
||||
replaced_range(replaced_range const&) = default;
|
||||
explicit SPROUT_CONSTEXPR replaced_range(range_type& range, value_type const& old_value, value_type const& new_value)
|
||||
SPROUT_CONSTEXPR replaced_range(range_type& range, value_type const& old_value, value_type const& new_value)
|
||||
: base_type(
|
||||
iterator(sprout::begin(range), typename iterator::functor_type(old_value, new_value)),
|
||||
iterator(sprout::end(range), typename iterator::functor_type(old_value, new_value))
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace sprout {
|
|||
public:
|
||||
typedef Predicate predicate_type;
|
||||
typedef T const& result_type;
|
||||
typedef T const& first_argument_type;
|
||||
typedef T const& argument_type;
|
||||
private:
|
||||
Predicate pred_;
|
||||
T new_;
|
||||
|
@ -63,7 +63,7 @@ namespace sprout {
|
|||
public:
|
||||
replaced_if_range() = default;
|
||||
replaced_if_range(replaced_if_range const&) = default;
|
||||
explicit SPROUT_CONSTEXPR replaced_if_range(range_type& range, predicate_type pred, value_type const& new_value)
|
||||
SPROUT_CONSTEXPR replaced_if_range(range_type& range, Predicate pred, value_type const& new_value)
|
||||
: base_type(
|
||||
iterator(sprout::begin(range), typename iterator::functor_type(pred, new_value)),
|
||||
iterator(sprout::end(range), typename iterator::functor_type(pred, new_value))
|
||||
|
@ -80,14 +80,14 @@ namespace sprout {
|
|||
typedef Predicate predicate_type;
|
||||
typedef T value_type;
|
||||
private:
|
||||
predicate_type pred_;
|
||||
Predicate pred_;
|
||||
value_type new_;
|
||||
public:
|
||||
SPROUT_CONSTEXPR replace_if_holder(predicate_type pred, value_type const& new_value)
|
||||
SPROUT_CONSTEXPR replace_if_holder(Predicate pred, value_type const& new_value)
|
||||
: pred_(pred)
|
||||
, new_(new_value)
|
||||
{}
|
||||
SPROUT_CONSTEXPR predicate_type const& predicate() const {
|
||||
SPROUT_CONSTEXPR Predicate const& predicate() const {
|
||||
return pred_;
|
||||
}
|
||||
SPROUT_CONSTEXPR value_type const& new_value() const {
|
||||
|
|
|
@ -6,5 +6,9 @@
|
|||
#include <sprout/range/adaptor/sawtooth_wave.hpp>
|
||||
#include <sprout/range/adaptor/triangle_wave.hpp>
|
||||
#include <sprout/range/adaptor/square_wave.hpp>
|
||||
#include <sprout/range/adaptor/dft.hpp>
|
||||
#include <sprout/range/adaptor/idft.hpp>
|
||||
#include <sprout/range/adaptor/amplitude_spectrum.hpp>
|
||||
#include <sprout/range/adaptor/phase_spectrum.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_RANGE_ADAPTOR_WAVE_HPP
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include <sprout/config.hpp>
|
||||
#include <sprout/range/numeric/dft/dft.hpp>
|
||||
#include <sprout/range/numeric/dft/idft.hpp>
|
||||
#include <sprout/range/numeric/dft/dft_element.hpp>
|
||||
#include <sprout/range/numeric/dft/idft_element.hpp>
|
||||
#include <sprout/range/numeric/dft/spectrum.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_RANGE_NUMERIC_DFT_HPP
|
||||
|
|
22
sprout/range/numeric/dft/dft_element.hpp
Normal file
22
sprout/range/numeric/dft/dft_element.hpp
Normal file
|
@ -0,0 +1,22 @@
|
|||
#ifndef SPROUT_RANGE_NUMERIC_DFT_DFT_ELEMENT_HPP
|
||||
#define SPROUT_RANGE_NUMERIC_DFT_DFT_ELEMENT_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/numeric/dft/dft_element.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace range {
|
||||
//
|
||||
// dft_element
|
||||
//
|
||||
template<typename Input>
|
||||
inline SPROUT_CONSTEXPR typename sprout::container_traits<Input>::value_type
|
||||
dft_element(Input const& input, typename sprout::container_traits<Input>::difference_type i) {
|
||||
return sprout::dft_element(sprout::begin(input), sprout::end(input), i);
|
||||
}
|
||||
} // namespace range
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_RANGE_NUMERIC_DFT_DFT_ELEMENT_HPP
|
|
@ -22,4 +22,7 @@ namespace sprout {
|
|||
} // namespace range
|
||||
} // namespace sprout
|
||||
|
||||
#include <sprout/range/numeric/dft/fit/amplitude_spectrum.hpp>
|
||||
#include <sprout/range/numeric/dft/fit/phase_spectrum.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_RANGE_NUMERIC_DFT_FIT_SPECTRUM_HPP
|
||||
|
|
|
@ -24,4 +24,7 @@ namespace sprout {
|
|||
} // namespace range
|
||||
} // namespace sprout
|
||||
|
||||
#include <sprout/range/numeric/dft/fixed/amplitude_spectrum.hpp>
|
||||
#include <sprout/range/numeric/dft/fixed/phase_spectrum.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_RANGE_NUMERIC_DFT_FIXED_SPECTRUM_HPP
|
||||
|
|
22
sprout/range/numeric/dft/idft_element.hpp
Normal file
22
sprout/range/numeric/dft/idft_element.hpp
Normal file
|
@ -0,0 +1,22 @@
|
|||
#ifndef SPROUT_RANGE_NUMERIC_DFT_IDFT_ELEMENT_HPP
|
||||
#define SPROUT_RANGE_NUMERIC_DFT_IDFT_ELEMENT_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/container/traits.hpp>
|
||||
#include <sprout/container/functions.hpp>
|
||||
#include <sprout/numeric/dft/idft_element.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace range {
|
||||
//
|
||||
// idft_element
|
||||
//
|
||||
template<typename Input>
|
||||
inline SPROUT_CONSTEXPR typename sprout::container_traits<Input>::value_type
|
||||
idft_element(Input const& input, typename sprout::container_traits<Input>::difference_type i) {
|
||||
return sprout::idft_element(sprout::begin(input), sprout::end(input), i);
|
||||
}
|
||||
} // namespace range
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_RANGE_NUMERIC_DFT_IDFT_ELEMENT_HPP
|
Loading…
Reference in a new issue