generators.cpp (1682B)
1 /** 2 * KFR (https://www.kfrlib.com) 3 * Copyright (C) 2016-2023 Dan Cazarin 4 * See LICENSE.txt for details 5 */ 6 7 #include <kfr/base/basic_expressions.hpp> 8 #include <kfr/base/generators.hpp> 9 #include <kfr/base/math_expressions.hpp> 10 #include <kfr/base/reduce.hpp> 11 #include <kfr/base/simd_expressions.hpp> 12 #include <kfr/base/univector.hpp> 13 14 using namespace kfr; 15 16 namespace CMT_ARCH_NAME 17 { 18 19 TEST(test_gen_expj) 20 { 21 univector<cbase> v = truncate(gen_expj(0.f, constants<float>::pi_s(2) * 0.1f), 1000); 22 CHECK(rms(cabs( 23 v.slice(990) - 24 univector<cbase>({ cbase(1., +0.00000000e+00), cbase(0.80901699, +5.87785252e-01), 25 cbase(0.30901699, +9.51056516e-01), cbase(-0.30901699, +9.51056516e-01), 26 cbase(-0.80901699, +5.87785252e-01), cbase(-1., +1.22464680e-16), 27 cbase(-0.80901699, -5.87785252e-01), cbase(-0.30901699, -9.51056516e-01), 28 cbase(0.30901699, -9.51056516e-01), cbase(0.80901699, -5.87785252e-01) }))) < 29 0.00006); // error here depends on vector width 30 // In most cases error is much lower (less than 0.00001) 31 } 32 33 TEST(gen_sin) 34 { 35 kfr::univector<kfr::fbase> x; 36 constexpr size_t size = 132; 37 kfr::fbase step = kfr::c_pi<kfr::fbase> / (size + 1); 38 kfr::univector<kfr::fbase> up; 39 up = kfr::truncate(kfr::gen_sin<kfr::fbase>(kfr::c_pi<kfr::fbase> / 2, step), size); 40 41 kfr::univector<kfr::fbase> up2(size); 42 for (int i = 0; i < size; ++i) 43 { 44 up2[i] = std::sin(kfr::c_pi<kfr::fbase> / 2 + i * step); 45 } 46 CHECK(rms(up - up2) < 0.00001); 47 } 48 49 } // namespace CMT_ARCH_NAME