Line data Source code
1 : /** 2 : * \file HadamardMixture.hxx 3 : */ 4 : 5 : #include "HadamardMixture.h" 6 : #include <ATK/Delay/FeedbackDelayNetworkFilter.hxx> 7 : 8 : #include <ATK/Core/TypeTraits.h> 9 : #include <ATK/Utility/fmath.h> 10 : 11 : #include <Eigen/Dense> 12 : 13 : namespace ATK 14 : { 15 : template<typename DataType_, unsigned int order> 16 : class HadamardMixture<DataType_, order>::MixtureImpl 17 : { 18 : public: 19 : using Vector = Eigen::Matrix<DataType, nb_channels, 1>; 20 : using Matrix = Eigen::Matrix<DataType, nb_channels, nb_channels>; 21 : 22 1147320 : Vector mix(const Vector& x) const 23 : { 24 2294640 : return transition * x; 25 : } 26 : 27 : protected: 28 : const Matrix transition = create(); 29 : 30 15 : static Matrix create() 31 : { 32 15 : return (DataType_(1 / fmath::pow(2, order / 2.)) * recursive_create<order>()).template cast<DataType_>(); 33 : } 34 : 35 : template<unsigned int recursive_order> 36 53 : static Eigen::Matrix<typename TypeTraits<DataType_>::Scalar, (1U<<recursive_order), (1U<<recursive_order)> recursive_create() 37 : { 38 : if constexpr(recursive_order == 0) 39 : { 40 15 : return Eigen::Matrix<typename TypeTraits<DataType_>::Scalar, 1U, 1U>::Constant(1); 41 : } 42 : else 43 : { 44 38 : constexpr auto big_size = (1U << recursive_order); 45 38 : constexpr auto small_size = (1U << (recursive_order - 1)); 46 38 : Eigen::Matrix<typename TypeTraits<DataType_>::Scalar, big_size, big_size> cur_transition; 47 : 48 38 : auto M_1 = recursive_create<recursive_order - 1>(); 49 38 : cur_transition.block(0, 0, small_size, small_size) = M_1; 50 38 : cur_transition.block(0, small_size, small_size, small_size) = M_1; 51 38 : cur_transition.block(small_size, 0, small_size, small_size) = -M_1; 52 38 : cur_transition.block(small_size, small_size, small_size, small_size) = M_1; 53 76 : return cur_transition; 54 : } 55 : } 56 : }; 57 : }