Skip to content

Commit

Permalink
Merge pull request #236 from crtrott/fix-200
Browse files Browse the repository at this point in the history
Fix return type of layout_stride operator, and add test
  • Loading branch information
crtrott authored Feb 1, 2023
2 parents fc4b692 + d544d77 commit 0a1ce8c
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 1 deletion.
1 change: 1 addition & 0 deletions compilation_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ add_compilation_test(ctest_constructor_sfinae)
add_compilation_test(ctest_extents_ctors)
add_compilation_test(ctest_extents_type_check)
add_compilation_test(ctest_mdarray_type_check)
add_compilation_test(ctest_layout_type_check)
add_compilation_test(ctest_layout_convertible)
add_compilation_test(ctest_mdspan_convertible)
add_compilation_test(ctest_standard_layout)
Expand Down
88 changes: 88 additions & 0 deletions compilation_tests/ctest_layout_type_check.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//@HEADER
// ************************************************************************
//
// Kokkos v. 4.0
// Copyright (2022) National Technology & Engineering
// Solutions of Sandia, LLC (NTESS).
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.
//
// Part of Kokkos, under the Apache License v2.0 with LLVM Exceptions.
// See https://kokkos.org/LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//@HEADER
#include "ctest_common.hpp"

#include <experimental/mdspan>

namespace stdex = std::experimental;

using E1 = stdex::extents<int32_t, stdex::dynamic_extent, 3>;
using MLR1 = stdex::layout_right::mapping<E1>;
// Note we already separately tested that the extents interface is correct
MDSPAN_STATIC_TEST(
std::is_same<typename MLR1::index_type, typename E1::index_type>::value &&
std::is_same<typename MLR1::size_type, typename E1::size_type>::value &&
std::is_same<typename MLR1::rank_type, typename E1::rank_type>::value &&
std::is_same<typename MLR1::layout_type, stdex::layout_right>::value &&
std::is_same<decltype(MLR1::is_always_unique()), bool>::value &&
std::is_same<decltype(MLR1::is_always_exhaustive()), bool>::value &&
std::is_same<decltype(MLR1::is_always_strided()), bool>::value &&
std::is_same<decltype(std::declval<MLR1>().extents()), const E1&>::value &&
std::is_same<decltype(std::declval<MLR1>().stride(0)), typename E1::index_type>::value &&
std::is_same<decltype(std::declval<MLR1>().required_span_size()), typename E1::index_type>::value &&
std::is_same<decltype(std::declval<MLR1>().is_unique()), bool>::value &&
std::is_same<decltype(std::declval<MLR1>().is_exhaustive()), bool>::value &&
std::is_same<decltype(std::declval<MLR1>().is_strided()), bool>::value &&
std::is_same<decltype(std::declval<MLR1>()(1,1)), typename E1::index_type>::value &&
(MLR1::is_always_unique() == true) &&
(MLR1::is_always_exhaustive()== true) &&
(MLR1::is_always_strided() == true)
);

using MLL1 = stdex::layout_left::mapping<E1>;

MDSPAN_STATIC_TEST(
std::is_same<typename MLL1::index_type, typename E1::index_type>::value &&
std::is_same<typename MLL1::size_type, typename E1::size_type>::value &&
std::is_same<typename MLL1::rank_type, typename E1::rank_type>::value &&
std::is_same<typename MLL1::layout_type, stdex::layout_left>::value &&
std::is_same<decltype(MLL1::is_always_unique()), bool>::value &&
std::is_same<decltype(MLL1::is_always_exhaustive()), bool>::value &&
std::is_same<decltype(MLL1::is_always_strided()), bool>::value &&
std::is_same<decltype(std::declval<MLL1>().extents()), const E1&>::value &&
std::is_same<decltype(std::declval<MLL1>().stride(0)), typename E1::index_type>::value &&
std::is_same<decltype(std::declval<MLL1>().required_span_size()), typename E1::index_type>::value &&
std::is_same<decltype(std::declval<MLL1>().is_unique()), bool>::value &&
std::is_same<decltype(std::declval<MLL1>().is_exhaustive()), bool>::value &&
std::is_same<decltype(std::declval<MLL1>().is_strided()), bool>::value &&
std::is_same<decltype(std::declval<MLL1>()(1,1)), typename E1::index_type>::value &&
(MLL1::is_always_unique() == true) &&
(MLL1::is_always_exhaustive()== true) &&
(MLL1::is_always_strided() == true)
);


using MLS1 = stdex::layout_stride::mapping<E1>;

MDSPAN_STATIC_TEST(
std::is_same<typename MLS1::index_type, typename E1::index_type>::value &&
std::is_same<typename MLS1::size_type, typename E1::size_type>::value &&
std::is_same<typename MLS1::rank_type, typename E1::rank_type>::value &&
std::is_same<typename MLS1::layout_type, stdex::layout_stride>::value &&
std::is_same<decltype(MLS1::is_always_unique()), bool>::value &&
std::is_same<decltype(MLS1::is_always_exhaustive()), bool>::value &&
std::is_same<decltype(MLS1::is_always_strided()), bool>::value &&
std::is_same<decltype(std::declval<MLS1>().extents()), const E1&>::value &&
std::is_same<decltype(std::declval<MLS1>().stride(0)), typename E1::index_type>::value &&
std::is_same<decltype(std::declval<MLS1>().required_span_size()), typename E1::index_type>::value &&
std::is_same<decltype(std::declval<MLS1>().is_unique()), bool>::value &&
std::is_same<decltype(std::declval<MLS1>().is_exhaustive()), bool>::value &&
std::is_same<decltype(std::declval<MLS1>().is_strided()), bool>::value &&
std::is_same<decltype(std::declval<MLS1>()(1,1)), typename E1::index_type>::value &&
(MLS1::is_always_unique() == true) &&
(MLS1::is_always_exhaustive()== false) &&
(MLS1::is_always_strided() == true)
);
2 changes: 1 addition & 1 deletion include/experimental/__p0009_bits/layout_stride.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ struct layout_stride {
)
)
MDSPAN_FORCE_INLINE_FUNCTION
constexpr size_t operator()(Indices... idxs) const noexcept {
constexpr index_type operator()(Indices... idxs) const noexcept {
return __impl::_call_op_impl(*this, static_cast<index_type>(idxs)...);
}

Expand Down

0 comments on commit 0a1ce8c

Please sign in to comment.