kfr

Fast, modern C++ DSP framework, FFT, Sample Rate Conversion, FIR/IIR/Biquad Filters (SSE, AVX, AVX-512, ARM NEON)
Log | Files | Refs | README

commit 8027006309d970baba76db0136d3f07a4b1d7a1b
parent cb86ca55d0532d0f6eb33a61a909d5813362abbf
Author: d.levin256@gmail.com <d.levin256@gmail.com>
Date:   Wed,  7 Sep 2016 20:16:06 +0300

Automatically get the size of expression rather than pass it as an argument

Diffstat:
Minclude/kfr/base/expression.hpp | 11++++++-----
Minclude/kfr/base/operators.hpp | 2+-
Minclude/kfr/base/reduce.hpp | 3+--
Minclude/kfr/base/univector.hpp | 2+-
Minclude/kfr/io/audiofile.hpp | 6+++---
5 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/include/kfr/base/expression.hpp b/include/kfr/base/expression.hpp @@ -258,13 +258,13 @@ CMT_INLINE void process_cycle(OutputExpr&& outfn, const InputExpr& fn, size_t& i } } -template <typename Tout, cpu_t c = cpu_t::native, size_t width = 0, typename OutputExpr, typename InputExpr> -CMT_INLINE void process(OutputExpr&& out, const InputExpr& in, size_t size) +template <typename Tout, cpu_t c = cpu_t::native, size_t width = 0, typename OutputExpr, typename InputExpr, + size_t groupsize = 1> +CMT_INLINE size_t process(OutputExpr&& out, const InputExpr& in, csize_t<groupsize> = csize_t<groupsize>()) { + const size_t size = size_min(out.size(), in.size()) * groupsize; static_assert(is_output_expression<OutputExpr>::value, "OutFn must be an expression"); static_assert(is_input_expression<InputExpr>::value, "Fn must be an expression"); - constexpr size_t comp = lcm(func_ratio<OutputExpr>::input, func_ratio<InputExpr>::output); - size *= comp; out.output_begin_block(size); in.begin_block(size); @@ -276,10 +276,11 @@ CMT_INLINE void process(OutputExpr&& out, const InputExpr& in, size_t size) size_t i = 0; internal::process_cycle<w>(std::forward<OutputExpr>(out), in, i, size); - internal::process_cycle<comp>(std::forward<OutputExpr>(out), in, i, size); + internal::process_cycle<groupsize>(std::forward<OutputExpr>(out), in, i, size); in.end_block(size); out.output_end_block(size); + return size; } template <typename T> diff --git a/include/kfr/base/operators.hpp b/include/kfr/base/operators.hpp @@ -736,7 +736,7 @@ struct expression_unpack : private expression<E...>, output_expression CMT_INLINE expression_unpack& operator=(Input&& input) { using value_type = vec<common_type<value_type_of<E>...>, count>; - process<value_type>(*this, std::forward<Input>(input), size()); + process<value_type>(*this, std::forward<Input>(input)); return *this; } diff --git a/include/kfr/base/reduce.hpp b/include/kfr/base/reduce.hpp @@ -113,11 +113,10 @@ KFR_SINTRIN T reduce(E1&& e1, ReduceFn&& reducefn, TransformFn&& transformfn = f FinalFn&& finalfn = fn_pass_through()) { static_assert(!is_infinite<E1>::value, "e1 must be a sized expression (use slice())"); - const size_t size = e1.size(); using reducer_t = expression_reduce<T, decay<ReduceFn>, decay<TransformFn>, decay<FinalFn>>; reducer_t red(std::forward<ReduceFn>(reducefn), std::forward<TransformFn>(transformfn), std::forward<FinalFn>(finalfn)); - process<T>(red, std::forward<E1>(e1), size); + process<T>(red, std::forward<E1>(e1)); return red.get(); } diff --git a/include/kfr/base/univector.hpp b/include/kfr/base/univector.hpp @@ -184,7 +184,7 @@ protected: template <typename Input> CMT_INLINE void assign_expr(Input&& input) { - process<T>(*this, std::forward<Input>(input), get_size()); + process<T>(*derived_cast<Class>(this), std::forward<Input>(input)); } private: diff --git a/include/kfr/io/audiofile.hpp b/include/kfr/io/audiofile.hpp @@ -38,17 +38,17 @@ template <typename Tout, typename Tin, size_t Tag1, size_t Tag2, typename E1> void write_interleaved(E1&& dest, const univector2d<Tin, Tag1, Tag2>& src) { const size_t channels = src.size(); - const size_t size = src[0].size(); if (channels == 1) { - process<Tout>(std::forward<E1>(dest), src[0], size); + process<Tout>(std::forward<E1>(dest), src[0]); } else if (channels == 2) { - process<Tout>(std::forward<E1>(dest), bind_expression(fn_interleave(), src[0], src[1]), size); + process<Tout>(std::forward<E1>(dest), pack(src[0], src[1]), csize<2>); } else { + const size_t size = src[0].size(); internal::expression_writer<Tout, E1> wr = writer<Tout>(std::forward<E1>(dest)); for (size_t i = 0; i < size; i++) for (size_t ch = 0; ch < channels; ch++)