From edae61736ca990794bc392ebed25ce4052d4d682 Mon Sep 17 00:00:00 2001 From: Mark Hoemmen Date: Mon, 8 Apr 2024 10:05:42 -0600 Subject: [PATCH] Implement P2389R1 (add dims template alias) --- include/experimental/__p2389_bits/dims.hpp | 28 ++++++++ include/mdspan/mdspan.hpp | 1 + tests/CMakeLists.txt | 1 + tests/test_dims.cpp | 75 ++++++++++++++++++++++ 4 files changed, 105 insertions(+) create mode 100644 include/experimental/__p2389_bits/dims.hpp create mode 100644 tests/test_dims.cpp diff --git a/include/experimental/__p2389_bits/dims.hpp b/include/experimental/__p2389_bits/dims.hpp new file mode 100644 index 00000000..00045215 --- /dev/null +++ b/include/experimental/__p2389_bits/dims.hpp @@ -0,0 +1,28 @@ +//@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 + +#pragma once + +// backward compatibility import into experimental +namespace MDSPAN_IMPL_STANDARD_NAMESPACE { +namespace MDSPAN_IMPL_PROPOSED_NAMESPACE { + +template< ::std::size_t Rank, class IndexType = std::size_t> +using dims = + :: MDSPAN_IMPL_STANDARD_NAMESPACE :: dextents; + +} // namespace MDSPAN_IMPL_PROPOSED_NAMESPACE +} // namespace MDSPAN_IMPL_STANDARD_NAMESPACE diff --git a/include/mdspan/mdspan.hpp b/include/mdspan/mdspan.hpp index ac72a1a4..4a0e354f 100644 --- a/include/mdspan/mdspan.hpp +++ b/include/mdspan/mdspan.hpp @@ -38,5 +38,6 @@ #include "../experimental/__p2642_bits/layout_padded.hpp" #include "../experimental/__p2630_bits/submdspan.hpp" #endif +#include "../experimental/__p2389_bits/dims.hpp" #endif // MDSPAN_HPP_ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f8420b42..1dcebcbd 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -48,6 +48,7 @@ else() ) endif() +mdspan_add_test(test_dims) mdspan_add_test(test_extents) mdspan_add_test(test_mdspan_ctors) mdspan_add_test(test_mdspan_swap) diff --git a/tests/test_dims.cpp b/tests/test_dims.cpp new file mode 100644 index 00000000..4de05e7f --- /dev/null +++ b/tests/test_dims.cpp @@ -0,0 +1,75 @@ +//@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 +#include +#include + +namespace test { + +template +static constexpr bool is_extents_v = false; + +template +static constexpr bool is_extents_v< + MDSPAN_IMPL_STANDARD_NAMESPACE :: extents +> = true; + +template +void test_dims_with_one_template_argument() +{ + using d = MDSPAN_IMPL_STANDARD_NAMESPACE :: MDSPAN_IMPL_PROPOSED_NAMESPACE :: dims; + static_assert(test::is_extents_v); + static_assert(std::is_same_v); + static_assert(d::rank() == Rank); +} + +template +void test_dims_with_two_template_arguments() +{ + using d = MDSPAN_IMPL_STANDARD_NAMESPACE :: MDSPAN_IMPL_PROPOSED_NAMESPACE :: dims; + static_assert(test::is_extents_v); + static_assert(std::is_same_v); + static_assert(d::rank() == Rank); +} + +} // namespace test + +TEST(TestDims, Test0) +{ + using test::test_dims_with_one_template_argument; + using test::test_dims_with_two_template_arguments; + + test_dims_with_one_template_argument<0>(); + test_dims_with_one_template_argument<1>(); + test_dims_with_one_template_argument<2>(); + test_dims_with_one_template_argument<3>(); + test_dims_with_one_template_argument<4>(); + test_dims_with_one_template_argument<5>(); + test_dims_with_one_template_argument<6>(); + test_dims_with_one_template_argument<7>(); + test_dims_with_one_template_argument<8>(); + + test_dims_with_two_template_arguments<0, std::size_t>(); + test_dims_with_two_template_arguments<1, std::size_t>(); + test_dims_with_two_template_arguments<2, std::size_t>(); + test_dims_with_two_template_arguments<3, std::size_t>(); + test_dims_with_two_template_arguments<4, std::size_t>(); + test_dims_with_two_template_arguments<5, std::size_t>(); + test_dims_with_two_template_arguments<6, std::size_t>(); + test_dims_with_two_template_arguments<7, std::size_t>(); + test_dims_with_two_template_arguments<8, std::size_t>(); +}