Skip to content

Commit

Permalink
Kokkos::Array deduction guide (kokkos#6373)
Browse files Browse the repository at this point in the history
* Added a deduction guide for Kokkos::Array

* Added unit test for Kokkos::Array deduction guide

* Decorated is_equal with KOKKOS_FUNCTION
  • Loading branch information
nliber committed Jan 4, 2024
1 parent 654a51f commit efc0c36
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/src/Kokkos_Array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ struct Array<T, KOKKOS_INVALID_INDEX, Array<>::strided> {
: m_elem(arg_ptr), m_size(arg_size), m_stride(arg_stride) {}
};

template <typename T, typename... Us>
Array(T, Us...)->Array<T, 1 + sizeof...(Us)>;

} // namespace Kokkos

//<editor-fold desc="Support for structured binding">
Expand Down
21 changes: 21 additions & 0 deletions core/unit_test/TestArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,25 @@ KOKKOS_FUNCTION constexpr bool test_array_structured_binding_support() {

static_assert(test_array_structured_binding_support());

template <typename L, typename R>
KOKKOS_FUNCTION constexpr bool is_equal(L const& l, R const& r) {
if (std::size(l) != std::size(r)) return false;

for (size_t i = 0; i != std::size(l); ++i) {
if (l[i] != r[i]) return false;
}

return true;
}

KOKKOS_FUNCTION constexpr bool test_array_ctad() {
constexpr int x = 10;
constexpr Kokkos::Array a{1, 2, 3, 5, x};
constexpr Kokkos::Array<int, 5> b{1, 2, 3, 5, x};

return std::is_same_v<decltype(a), decltype(b)> && is_equal(a, b);
}

static_assert(test_array_ctad());

} // namespace

0 comments on commit efc0c36

Please sign in to comment.