ddemidov / vexcl
1
#define BOOST_TEST_MODULE VectorArithmetics
2
#include <boost/test/unit_test.hpp>
3
#include <vexcl/vector.hpp>
4
#include <vexcl/cast.hpp>
5
#include "context_setup.hpp"
6

7 6
BOOST_AUTO_TEST_CASE(casted_expession)
8
{
9
    const size_t N = 1024;
10

11 6
    vex::vector<double> x(ctx, N);
12

13 6
    x = vex::cast<double>(5);
14

15 6
    check_sample(x, [](size_t, double a) { BOOST_CHECK_EQUAL(a, 5); });
16
}
17

18
#if defined(VEXCL_BACKEND_OPENCL) || defined(VEXCL_BACKEND_COMPUTE)
19 4
BOOST_AUTO_TEST_CASE(convert_functions)
20
{
21
    const size_t N = 1024;
22

23 4
    vex::vector<cl_int2> x(ctx, N);
24

25 4
    union {
26
        cl_float2 f;
27
        cl_int2   i;
28
    } y;
29

30 4
    y.f = {{4.2f, 8.4f}};
31

32 4
    x = vex::convert_int2(y.f);
33

34 4
    check_sample(x, [y](size_t, cl_int2 a) {
35 4
            BOOST_CHECK_EQUAL(a.s[0], static_cast<int>(y.f.s[0]));
36 4
            BOOST_CHECK_EQUAL(a.s[1], static_cast<int>(y.f.s[1]));
37 4
            });
38

39 4
    x = vex::as_int2(y.f);
40

41 4
    check_sample(x, [y](size_t, cl_int2 a) {
42 4
            BOOST_CHECK_EQUAL(a.s[0], y.i.s[0]);
43 4
            BOOST_CHECK_EQUAL(a.s[1], y.i.s[1]);
44 4
            });
45

46
}
47
#endif
48

49 6
BOOST_AUTO_TEST_SUITE_END()
50

Read our documentation on viewing source code .

Loading