1 #ifndef SOPT_WAVELETS_WAVELETS_H
2 #define SOPT_WAVELETS_WAVELETS_H
4 #include "sopt/config.h"
18 Wavelet
factory(
const std::string& name =
"DB1",
t_uint nlevels = 1);
33 #define SOPT_WAVELET_MACRO_MULTIPLE(NAME) \
34 if (((NAME).rows() == 1 or (NAME).cols() == 1)) { \
35 if ((NAME).size() % (1 << levels()) != 0) \
36 throw std::length_error("Size of " #NAME " must number a multiple of 2^levels or 1"); \
37 } else if ((NAME).rows() != 1 and (NAME).rows() % (1 << levels()) != 0) \
38 throw std::length_error("Rows of " #NAME " must number a multiple of 2^levels or 1"); \
39 else if ((NAME).cols() % (1 << levels()) != 0) \
40 throw std::length_error("Columns of " #NAME " must number a multiple of 2^levels");
41 #define SOPT_WAVELET_MACRO_EQUAL_SIZE(A, B) \
42 if ((A).rows() != (B).rows() or (A).cols() != (B).cols()) (A).derived().resize((B).rows(), (B).cols()); \
43 if ((A).rows() != (B).rows() or (A).cols() != (B).cols()) \
44 throw std::length_error("Incorrect size for output matrix(or could not resize)")
51 template <
typename T0>
52 auto direct(Eigen::ArrayBase<T0>
const &signal)
const
65 template <
typename T0,
typename T1>
82 template <
typename T0,
typename T1>
94 template <
typename T0>
105 template <
typename T0,
typename T1>
119 template <
typename T0,
typename T1>
120 auto indirect(Eigen::ArrayBase<T1>
const &coeffs, Eigen::ArrayBase<T0> &&signal)
const
126 #undef SOPT_WAVELET_MACRO_MULTIPLE
127 #undef SOPT_WAVELET_MACRO_EQUAL_SIZE
Performs direct and indirect wavelet transforms.
void levels(t_uint l)
Sets number of levels over which to do transform.
virtual ~Wavelet()
Destructor.
auto direct(Eigen::ArrayBase< T1 > &coefficients, Eigen::ArrayBase< T0 > const &signal) const -> decltype(direct_transform(coefficients, signal, 1, *this))
Direct transform.
auto indirect(Eigen::ArrayBase< T1 > const &coeffs, Eigen::ArrayBase< T0 > &&signal) const -> decltype(indirect_transform(coeffs, signal, 1, *this))
Indirect transform.
friend Wavelet factory(const std::string &name, t_uint nlevels)
Creates a wavelet transform object.
auto indirect(Eigen::ArrayBase< T0 > const &coefficients) const -> decltype(indirect_transform(coefficients, 1, *this))
Indirect transform.
auto direct(Eigen::ArrayBase< T1 > &&coefficients, Eigen::ArrayBase< T0 > const &signal) const -> decltype(direct_transform(coefficients, signal, 1, *this))
Direct transform.
t_uint levels() const
Number of levels over which to do transform.
auto indirect(Eigen::ArrayBase< T1 > const &coefficients, Eigen::ArrayBase< T0 > &signal) const -> decltype(indirect_transform(coefficients, signal, 1, *this))
Indirect transform.
auto direct(Eigen::ArrayBase< T0 > const &signal) const -> decltype(direct_transform(signal, 1, *this))
Direct transform.
std::enable_if< T1::IsVectorAtCompileTime, void >::type direct_transform(Eigen::ArrayBase< T0 > &coeffs, Eigen::ArrayBase< T1 > const &signal, t_uint levels, WaveletData const &wavelet)
N-levels 1d direct transform.
Wavelet factory(const std::string &name, t_uint nlevels)
Creates a wavelet transform object.
std::enable_if< T1::IsVectorAtCompileTime, void >::type indirect_transform(Eigen::ArrayBase< T0 > const &coeffs, Eigen::ArrayBase< T1 > &signal, t_uint levels, WaveletData const &wavelet)
N-levels 1d indirect transform.
size_t t_uint
Root of the type hierarchy for unsigned integers.
Holds wavelets coefficients.
t_vector const coefficients
Wavelet coefficient per-se.
WaveletData(std::initializer_list< t_scalar > const &coefs)
Constructs from initializers.
#define SOPT_WAVELET_MACRO_MULTIPLE(NAME)
#define SOPT_WAVELET_MACRO_EQUAL_SIZE(A, B)