forked from alpaka-group/alpaka3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComplexFloat.cpp
More file actions
56 lines (45 loc) · 2.55 KB
/
ComplexFloat.cpp
File metadata and controls
56 lines (45 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* Copyright 2022 Jakob Krude, Benjamin Worpitz, Bernhard Manfred Gruber, Sergei Bastrakov, Jan Stephan
* SPDX-License-Identifier: MPL-2.0
*/
#include "Functor.hpp"
#include "TestTemplate.hpp"
#include "alpaka/math/Complex.hpp"
#include <alpaka/alpaka.hpp>
#include <alpaka/meta/meta.hpp>
#include <catch2/catch_template_test_macros.hpp>
#include <catch2/catch_test_macros.hpp>
#include <complex>
#include <tuple>
#include <type_traits>
using TestBackends = std::decay_t<decltype(onHost::allBackends(onHost::enabledApis, exec::enabledExecutors))>;
// This file only has unit tests for complex numbers in order to split the tests between object files and save compiler
// memory. For the same reason single- and double-precision are done separately and not wrapped into a common template.
using FunctorsComplex = alpaka::meta::Concatenate<mathtest::UnaryFunctorsComplex, mathtest::BinaryFunctorsComplex>;
using TestAccFunctorTuplesComplex = alpaka::meta::CartesianProduct<std::tuple, TestBackends, FunctorsComplex>;
TEMPLATE_LIST_TEST_CASE("mathOpsComplexFloat", "[math] [operator]", TestAccFunctorTuplesComplex)
{
// Same as "mathOpsFloat" template test, but for complex float. See detailed explanation there.
using Backend = std::tuple_element_t<0u, TestType>;
using Functor = std::tuple_element_t<1u, TestType>;
auto cfg = Backend::makeDict();
auto testTemplate = mathtest::TestTemplate<Functor>{};
testTemplate.template operator()<alpaka::math::Complex<float>>(cfg);
}
TEST_CASE("mathArrayOrientedComplexFloat", "[array-oriented]")
{
// Ensure that our implementation matches the behaviour of std::complex with regard to array-oriented access.
// See https://en.cppreference.com/w/cpp/numeric/complex - Array-oriented access - for more information.
auto const complex_alpaka = alpaka::math::Complex<float>{42.f, 42.f};
auto const complex_std = std::complex<float>{42.f, 42.f};
auto const real_alpaka = reinterpret_cast<float const(&)[2]>(complex_alpaka)[0];
auto const real_std = reinterpret_cast<float const(&)[2]>(complex_std)[0];
REQUIRE(alpaka::math::floatEqualExactNoWarning(real_alpaka, real_std));
auto const imag_alpaka = reinterpret_cast<float const(&)[2]>(complex_alpaka)[1];
auto const imag_std = reinterpret_cast<float const(&)[2]>(complex_std)[1];
REQUIRE(alpaka::math::floatEqualExactNoWarning(imag_alpaka, imag_std));
}
TEST_CASE("mathPaddingComplexFloat", "[padding]")
{
// Ensure that we don't accidentally introduce padding
STATIC_REQUIRE(sizeof(alpaka::math::Complex<float>) == 2 * sizeof(float));
}