File: test_sid_shift_sid_origin.cpp

package info (click to toggle)
gridtools 2.3.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 29,480 kB
  • sloc: cpp: 228,792; python: 17,561; javascript: 9,164; ansic: 4,101; sh: 850; makefile: 231; f90: 201
file content (67 lines) | stat: -rw-r--r-- 2,145 bytes parent folder | download | duplicates (2)
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
/*
 * GridTools
 *
 * Copyright (c) 2014-2023, ETH Zurich
 * All rights reserved.
 *
 * Please, refer to the LICENSE file in the root directory.
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <gridtools/sid/sid_shift_origin.hpp>

#include <gtest/gtest.h>

#include <gridtools/common/integral_constant.hpp>
#include <gridtools/common/tuple.hpp>
#include <gridtools/common/tuple_util.hpp>
#include <gridtools/sid/simple_ptr_holder.hpp>
#include <gridtools/sid/synthetic.hpp>

namespace gridtools {
    namespace {
        using sid::property;
        using namespace literals;
        namespace tu = tuple_util;

        TEST(shift_sid_origin, synthetic) {
            double data[3][5][7];

            auto src = sid::synthetic()
                           .set<property::origin>(sid::simple_ptr_holder(&data[0][0][0]))
                           .set<property::strides>(tuple(5_c * 7_c, 7_c, 1_c))
                           .set<property::upper_bounds>(tuple(3));

            auto offset = tuple(1_c, 2);
            auto testee = sid::shift_sid_origin(src, offset);

            static_assert(is_sid<decltype(testee)>());

            EXPECT_EQ(&data[0][0][0], sid::get_origin(src)());
            EXPECT_EQ(&data[1][2][0], sid::get_origin(testee)());

            EXPECT_EQ(2, tu::get<0>(sid::get_upper_bounds(testee)));
        }

        TEST(shift_sid_origin, c_array) {
            double data[3][5][7];

            auto offset = tuple(1_c, 2);
            auto testee = sid::shift_sid_origin(data, offset);

            static_assert(is_sid<decltype(testee)>());

            EXPECT_EQ(&data[1][2][0], sid::get_origin(testee)());

            auto lower_bounds = sid::get_lower_bounds(testee);
            EXPECT_EQ(-1, tu::get<0>(lower_bounds));
            EXPECT_EQ(-2, tu::get<1>(lower_bounds));
            EXPECT_EQ(0, tu::get<2>(lower_bounds));

            auto upper_bounds = sid::get_upper_bounds(testee);
            EXPECT_EQ(2, tu::get<0>(upper_bounds));
            EXPECT_EQ(3, tu::get<1>(upper_bounds));
            EXPECT_EQ(7, tu::get<2>(upper_bounds));
        }
    } // namespace
} // namespace gridtools