kokkos-utils 0.0.1
 
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_Core.hpp"
5
7
8using execution_space = Kokkos::DefaultExecutionSpace;
9
21
23{
24
25constexpr size_t dim_1 = 5, dim_2 = 3, dim_3 = 6, dim_4 = 9;
26
28TEST(view, extents_rank_0)
29{
30 const Kokkos::View<double, execution_space> view_0("rank-0 view");
31
32 static_assert(utils::view::extents(view_0) == Kokkos::Array<size_t, 0>{});
33}
34
36TEST(view, extents_rank_1)
37{
38 const Kokkos::View<double[dim_1], execution_space> view_1_static("rank-1 view with static extent");
39 const Kokkos::View<double* , execution_space> view_1_dynami("rank-1 view with dynamic extent", dim_1);
40
41 ASSERT_EQ(utils::view::extents(view_1_static), Kokkos::Array{dim_1});
42 ASSERT_EQ(utils::view::extents(view_1_dynami), Kokkos::Array{dim_1});
43}
44
46TEST(view, extents_rank_2)
47{
48 const Kokkos::View<double[dim_1][dim_2], execution_space> view_2_static("rank-2 view with static extents");
49 const Kokkos::View<double** , execution_space> view_2_dynami("rank-2 view with dynamic extents", dim_1, dim_2);
50 const Kokkos::View<double*[dim_2] , execution_space> view_2_mixed ("rank-2 view with mixed extents" , dim_1);
51
52 ASSERT_EQ(utils::view::extents(view_2_static), (Kokkos::Array{dim_1, dim_2}));
53 ASSERT_EQ(utils::view::extents(view_2_dynami), (Kokkos::Array{dim_1, dim_2}));
54 ASSERT_EQ(utils::view::extents(view_2_mixed ), (Kokkos::Array{dim_1, dim_2}));
55}
56
58TEST(view, extents_rank_3)
59{
60 const Kokkos::View<double[dim_1][dim_2][dim_3], execution_space> view_3_static("rank-3 view of static extents");
61 const Kokkos::View<double*** , execution_space> view_3_dynami("rank-3 view of dynamic extents", dim_1, dim_2, dim_3);
62 const Kokkos::View<double*[dim_2][dim_3] , execution_space> view_3_mixed ("rank-3 view of mixed extents" , dim_1);
63
64 ASSERT_EQ(utils::view::extents(view_3_static), (Kokkos::Array{dim_1, dim_2, dim_3}));
65 ASSERT_EQ(utils::view::extents(view_3_dynami), (Kokkos::Array{dim_1, dim_2, dim_3}));
66 ASSERT_EQ(utils::view::extents(view_3_mixed ), (Kokkos::Array{dim_1, dim_2, dim_3}));
67}
68
70TEST(view, extents_rank_4)
71{
72 const Kokkos::View<double[dim_1][dim_2][dim_3][dim_4], execution_space> view_4_static("rank-4 view of static extents");
73
74 ASSERT_EQ(utils::view::extents(view_4_static), (Kokkos::Array{dim_1, dim_2, dim_3, dim_4}));
75}
76
77} // 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