kokkos-utils 0.0.7
Loading...
Searching...
No Matches
test_extents.cpp
Go to the documentation of this file.
1#include "gmock/gmock.h"
2#include "gtest/gtest.h"
3
4#include "Kokkos_Macros.hpp"
5#ifdef KOKKOS_ENABLE_EXPERIMENTAL_CXX20_MODULES
6import kokkos.core;
7#else
8#include "Kokkos_Core.hpp"
9#endif
10
12
13using execution_space = Kokkos::DefaultExecutionSpace;
14
26
28{
29
30constexpr size_t dim_1 = 5, dim_2 = 3, dim_3 = 6, dim_4 = 9;
31
33TEST(view, extents_rank_0)
34{
35 const Kokkos::View<double, execution_space> view_0("rank-0 view");
36
37 static_assert(utils::view::extents(view_0) == Kokkos::Array<size_t, 0>{});
38}
39
41TEST(view, extents_rank_1)
42{
43 const Kokkos::View<double[dim_1], execution_space> view_1_static("rank-1 view with static extent");
44 const Kokkos::View<double* , execution_space> view_1_dynami("rank-1 view with dynamic extent", dim_1);
45
46 ASSERT_EQ(utils::view::extents(view_1_static), Kokkos::Array{dim_1});
47 ASSERT_EQ(utils::view::extents(view_1_dynami), Kokkos::Array{dim_1});
48}
49
51TEST(view, extents_rank_2)
52{
53 const Kokkos::View<double[dim_1][dim_2], execution_space> view_2_static("rank-2 view with static extents");
54 const Kokkos::View<double** , execution_space> view_2_dynami("rank-2 view with dynamic extents", dim_1, dim_2);
55 const Kokkos::View<double*[dim_2] , execution_space> view_2_mixed ("rank-2 view with mixed extents" , dim_1);
56
57 ASSERT_EQ(utils::view::extents(view_2_static), (Kokkos::Array{dim_1, dim_2}));
58 ASSERT_EQ(utils::view::extents(view_2_dynami), (Kokkos::Array{dim_1, dim_2}));
59 ASSERT_EQ(utils::view::extents(view_2_mixed ), (Kokkos::Array{dim_1, dim_2}));
60}
61
63TEST(view, extents_rank_3)
64{
65 const Kokkos::View<double[dim_1][dim_2][dim_3], execution_space> view_3_static("rank-3 view of static extents");
66 const Kokkos::View<double*** , execution_space> view_3_dynami("rank-3 view of dynamic extents", dim_1, dim_2, dim_3);
67 const Kokkos::View<double*[dim_2][dim_3] , execution_space> view_3_mixed ("rank-3 view of mixed extents" , dim_1);
68
69 ASSERT_EQ(utils::view::extents(view_3_static), (Kokkos::Array{dim_1, dim_2, dim_3}));
70 ASSERT_EQ(utils::view::extents(view_3_dynami), (Kokkos::Array{dim_1, dim_2, dim_3}));
71 ASSERT_EQ(utils::view::extents(view_3_mixed ), (Kokkos::Array{dim_1, dim_2, dim_3}));
72}
73
75TEST(view, extents_rank_4)
76{
77 const Kokkos::View<double[dim_1][dim_2][dim_3][dim_4], execution_space> view_4_static("rank-4 view of static extents");
78
79 ASSERT_EQ(utils::view::extents(view_4_static), (Kokkos::Array{dim_1, dim_2, dim_3, dim_4}));
80}
81
82} // namespace Kokkos::utils::tests::view
TEST(view, extents_rank_0)
KOKKOS_FUNCTION constexpr auto extents(const ViewType &view)
Get all extents of view.
Definition extents.hpp:34
Kokkos::DefaultExecutionSpace execution_space