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 57dcd901c1db7e733c845b08984103218503212c
parent 16f67cd0fbb660180629820e13429ab83d36cade
Author: [email protected] <[email protected]>
Date:   Wed,  7 Sep 2016 14:48:45 +0300

Fix wrong size in slice function (+test)

Diffstat:
Minclude/kfr/base/basic_expressions.hpp | 2+-
Minclude/kfr/base/expression.hpp | 10+---------
Minclude/kfr/base/types.hpp | 18++++++++++++++++++
Mtests/expression_test.cpp | 12++++++++++++
4 files changed, 32 insertions(+), 10 deletions(-)

diff --git a/include/kfr/base/basic_expressions.hpp b/include/kfr/base/basic_expressions.hpp @@ -177,7 +177,7 @@ struct expression_slice : expression<E1> using T = value_type; expression_slice(E1&& e1, size_t start, size_t size) : expression<E1>(std::forward<E1>(e1)), start(start), - new_size(minsize(size, std::get<0>(this->args).size())) + new_size(size_min(size, size_sub(std::get<0>(this->args).size(), start))) { } template <size_t N> diff --git a/include/kfr/base/expression.hpp b/include/kfr/base/expression.hpp @@ -69,14 +69,6 @@ using is_infinite = typename internal::is_infinite_impl<T>::type; namespace internal { -constexpr inline size_t minsize(size_t x) noexcept { return x; } - -template <typename... Ts> -constexpr inline size_t minsize(size_t x, size_t y, Ts... rest) noexcept -{ - return minsize(x < y ? x : y, rest...); -} - template <typename... Args> struct expression : input_expression { @@ -100,7 +92,7 @@ protected: template <size_t... indices> constexpr size_t size_impl(csizes_t<indices...>) const noexcept { - return minsize(std::get<indices>(this->args).size()...); + return size_min(std::get<indices>(this->args).size()...); } template <typename Fn, typename T, size_t N> diff --git a/include/kfr/base/types.hpp b/include/kfr/base/types.hpp @@ -699,6 +699,24 @@ c == cpu_t::neon ? 16 : common_int_vector_size; constexpr size_t infinite_size = static_cast<size_t>(-1); +constexpr inline size_t size_add(size_t x, size_t y) +{ + return (x == infinite_size || y == infinite_size) ? infinite_size : x + y; +} + +constexpr inline size_t size_sub(size_t x, size_t y) +{ + return (x == infinite_size || y == infinite_size) ? infinite_size : x - y; +} + +constexpr inline size_t size_min(size_t x) noexcept { return x; } + +template <typename... Ts> +constexpr inline size_t size_min(size_t x, size_t y, Ts... rest) noexcept +{ + return size_min(x < y ? x : y, rest...); +} + /// @brief Base class of all input expressoins struct input_expression { diff --git a/tests/expression_test.cpp b/tests/expression_test.cpp @@ -79,6 +79,18 @@ TEST(test_arg_replace) CHECK(v3[9] == -90); } +TEST(size_calc) +{ + auto a = counter(); + CHECK(a.size() == infinite_size); + auto b = slice(counter(), 100); + CHECK(b.size() == infinite_size); + auto c = slice(counter(), 100, 1000); + CHECK(c.size() == 1000); + auto d = slice(c, 100); + CHECK(d.size() == 900); +} + int main(int argc, char** argv) { println(library_version());