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 09372a5a13ca0d5ec692ae13ab77a6f68fd36ae5
parent ab8644002761823ce09f70be3379ffde30f31754
Author: d.levin256@gmail.com <d.levin256@gmail.com>
Date:   Fri, 22 Jul 2016 19:50:25 +0300

Added test: stat_test

Diffstat:
Minclude/kfr/expressions/reduce.hpp | 17+++++++++++++++++
Mtests/CMakeLists.txt | 6++++--
Atests/stat_test.cpp | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 78 insertions(+), 2 deletions(-)

diff --git a/include/kfr/expressions/reduce.hpp b/include/kfr/expressions/reduce.hpp @@ -191,6 +191,14 @@ struct in_reduce return reduce(std::forward<E1>(x), fn_add(), fn_sqr()); } + template <typename E1, typename T = value_type_of<E1>> + KFR_SINTRIN T product(E1&& x) + { + static_assert(!is_generic<E1>::value, "e1 must be a typed expression (use typed<T>())"); + static_assert(!is_infinite<E1>::value, "e1 must be a sized expression (use typed<T>())"); + return reduce(std::forward<E1>(x), fn_mul()); + } + KFR_SPEC_FN(in_reduce, reduce) KFR_SPEC_FN(in_reduce, sum) KFR_SPEC_FN(in_reduce, dotproduct) @@ -199,6 +207,7 @@ struct in_reduce KFR_SPEC_FN(in_reduce, mean) KFR_SPEC_FN(in_reduce, min) KFR_SPEC_FN(in_reduce, max) + KFR_SPEC_FN(in_reduce, product) }; } @@ -261,5 +270,13 @@ KFR_SINTRIN T sumsqr(E1&& x) static_assert(!is_infinite<E1>::value, "e1 must be a sized expression (use typed<T>())"); return internal::in_reduce<>::sumsqr(std::forward<E1>(x)); } + +template <typename E1, typename T = value_type_of<E1>, KFR_ENABLE_IF(is_input_expression<E1>::value)> +KFR_SINTRIN T product(E1&& x) +{ + static_assert(!is_generic<E1>::value, "e1 must be a typed expression (use typed<T>())"); + static_assert(!is_infinite<E1>::value, "e1 must be a sized expression (use typed<T>())"); + return internal::in_reduce<>::product(std::forward<E1>(x)); +} } } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt @@ -34,6 +34,7 @@ add_executable(fracdelay_test fracdelay_test.cpp ${KFR_SRC}) add_executable(empty_test empty_test.cpp ${KFR_SRC}) add_executable(complex_test complex_test.cpp ${KFR_SRC}) add_executable(vec_test vec_test.cpp ${KFR_SRC}) +add_executable(stat_test stat_test.cpp ${KFR_SRC}) enable_testing() @@ -46,4 +47,6 @@ add_test(NAME conv_test add_test(NAME complex_test COMMAND ${PROJECT_BINARY_DIR}/tests/complex_test) add_test(NAME vec_test - COMMAND ${PROJECT_BINARY_DIR}/tests/vec_test) -\ No newline at end of file + COMMAND ${PROJECT_BINARY_DIR}/tests/vec_test) +add_test(NAME stat_test + COMMAND ${PROJECT_BINARY_DIR}/tests/stat_test) diff --git a/tests/stat_test.cpp b/tests/stat_test.cpp @@ -0,0 +1,57 @@ +/** + * KFR (http://kfrlib.com) + * Copyright (C) 2016 D Levin + * See LICENSE.txt for details + */ + +// library_version() +#include <kfr/io/tostring.hpp> +#include <kfr/version.hpp> + +#include <kfr/expressions/reduce.hpp> + +#include <tuple> + +#include "testo/testo.hpp" + +using namespace kfr; + +TEST(test_stat) +{ + { + univector<float, 5> a({ 1, 2, 3, 4, 5 }); + CHECK(native::sum(a) == 15); + CHECK(native::mean(a) == 3); + CHECK(native::min(a) == 1); + CHECK(native::max(a) == 5); + CHECK(native::sumsqr(a) == 55); + CHECK(native::rms(a) == 3.316624790355399849115f); + CHECK(native::product(a) == 120); + } + { + univector<double, 5> a({ 1, 2, 3, 4, 5 }); + CHECK(native::sum(a) == 15); + CHECK(native::mean(a) == 3); + CHECK(native::min(a) == 1); + CHECK(native::max(a) == 5); + CHECK(native::sumsqr(a) == 55); + CHECK(native::rms(a) == 3.316624790355399849115); + CHECK(native::product(a) == 120); + } + { + univector<int, 5> a({ 1, 2, 3, 4, 5 }); + CHECK(native::sum(a) == 15); + CHECK(native::mean(a) == 3); + CHECK(native::min(a) == 1); + CHECK(native::max(a) == 5); + CHECK(native::sumsqr(a) == 55); + CHECK(native::product(a) == 120); + } +} + +int main(int argc, char** argv) +{ + println(library_version()); + + return testo::run_all("", true); +}