Skip to content

Commit

Permalink
Merge pull request #324 from mhoemmen/implement-P2389R1
Browse files Browse the repository at this point in the history
Implement P2389R1 (add dims template alias)
  • Loading branch information
crtrott authored May 2, 2024
2 parents 721efd8 + edae617 commit f0ba298
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 0 deletions.
28 changes: 28 additions & 0 deletions include/experimental/__p2389_bits/dims.hpp
Original file line number Diff line number Diff line change
@@ -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<IndexType, Rank>;

} // namespace MDSPAN_IMPL_PROPOSED_NAMESPACE
} // namespace MDSPAN_IMPL_STANDARD_NAMESPACE
1 change: 1 addition & 0 deletions include/mdspan/mdspan.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
75 changes: 75 additions & 0 deletions tests/test_dims.cpp
Original file line number Diff line number Diff line change
@@ -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 <mdspan/mdspan.hpp>
#include <type_traits>
#include <gtest/gtest.h>

namespace test {

template<class Extents>
static constexpr bool is_extents_v = false;

template<class IndexType, std::size_t ... Exts>
static constexpr bool is_extents_v<
MDSPAN_IMPL_STANDARD_NAMESPACE :: extents<IndexType, Exts...>
> = true;

template<std::size_t Rank>
void test_dims_with_one_template_argument()
{
using d = MDSPAN_IMPL_STANDARD_NAMESPACE :: MDSPAN_IMPL_PROPOSED_NAMESPACE :: dims<Rank>;
static_assert(test::is_extents_v<d>);
static_assert(std::is_same_v<typename d::index_type, std::size_t>);
static_assert(d::rank() == Rank);
}

template<std::size_t Rank, class ExpectedIndexType>
void test_dims_with_two_template_arguments()
{
using d = MDSPAN_IMPL_STANDARD_NAMESPACE :: MDSPAN_IMPL_PROPOSED_NAMESPACE :: dims<Rank, ExpectedIndexType>;
static_assert(test::is_extents_v<d>);
static_assert(std::is_same_v<typename d::index_type, ExpectedIndexType>);
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>();
}

0 comments on commit f0ba298

Please sign in to comment.