File: test_iota.cpp

package info (click to toggle)
boost1.90 1.90.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 593,120 kB
  • sloc: cpp: 4,190,908; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,774; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (90 lines) | stat: -rw-r--r-- 2,699 bytes parent folder | download | duplicates (18)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//---------------------------------------------------------------------------//
// Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
//
// Distributed under the Boost Software License, Version 1.0
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//
// See http://boostorg.github.com/compute for more information.
//---------------------------------------------------------------------------//

#define BOOST_TEST_MODULE TestIota
#include <boost/test/unit_test.hpp>

#include <boost/compute/system.hpp>
#include <boost/compute/context.hpp>
#include <boost/compute/algorithm/iota.hpp>
#include <boost/compute/container/vector.hpp>
#include <boost/compute/iterator/permutation_iterator.hpp>

#include "check_macros.hpp"
#include "context_setup.hpp"

namespace bc = boost::compute;

BOOST_AUTO_TEST_CASE(iota_int)
{
    bc::vector<int> vector(4, context);
    bc::iota(vector.begin(), vector.end(), 0, queue);
    CHECK_RANGE_EQUAL(int, 4, vector, (0, 1, 2, 3));

    bc::iota(vector.begin(), vector.end(), 10, queue);
    CHECK_RANGE_EQUAL(int, 4, vector, (10, 11, 12, 13));

    bc::iota(vector.begin() + 2, vector.end(), -5, queue);
    CHECK_RANGE_EQUAL(int, 4, vector, (10, 11, -5, -4));

    bc::iota(vector.begin(), vector.end() - 2, 4, queue);
    CHECK_RANGE_EQUAL(int, 4, vector, (4, 5, -5, -4));
}

BOOST_AUTO_TEST_CASE(iota_doctest)
{
    boost::compute::vector<int> vec(3, context);

//! [iota]
boost::compute::iota(vec.begin(), vec.end(), 0, queue);
//! [iota]

    CHECK_RANGE_EQUAL(int, 3, vec, (0, 1, 2));
}

BOOST_AUTO_TEST_CASE(iota_permutation_iterator)
{
    bc::vector<int> output(5, context);
    bc::fill(output.begin(), output.end(), 0, queue);

    int map_data[] = { 2, 0, 1, 4, 3 };
    bc::vector<int> map(map_data, map_data + 5, queue);

    bc::iota(
        bc::make_permutation_iterator(output.begin(), map.begin()),
        bc::make_permutation_iterator(output.end(), map.end()),
        1,
        queue
    );
    CHECK_RANGE_EQUAL(int, 5, output, (2, 3, 1, 5, 4));
}

BOOST_AUTO_TEST_CASE(iota_uint)
{
    bc::vector<bc::uint_> vector(4, context);
    bc::iota(vector.begin(), vector.end(), bc::uint_(0), queue);
    CHECK_RANGE_EQUAL(bc::uint_, 4, vector, (0, 1, 2, 3));
}

BOOST_AUTO_TEST_CASE(iota_char)
{
    bc::vector<bc::char_> vector(4, context);
    bc::iota(vector.begin(), vector.end(), bc::uint_(0), queue);
    CHECK_RANGE_EQUAL(bc::char_, 4, vector, (0, 1, 2, 3));
}

BOOST_AUTO_TEST_CASE(iota_uchar)
{
    bc::vector<bc::uchar_> vector(4, context);
    bc::iota(vector.begin(), vector.end(), bc::uint_(0), queue);
    CHECK_RANGE_EQUAL(bc::uchar_, 4, vector, (0, 1, 2, 3));
}

BOOST_AUTO_TEST_SUITE_END()