-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #240 from crtrott/mdarray-to-mdspan
Mdarray to mdspan
- Loading branch information
Showing
3 changed files
with
117 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
//@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 <experimental/mdarray> | ||
#include <vector> | ||
|
||
#include <gtest/gtest.h> | ||
|
||
|
||
namespace stdex = std::experimental; | ||
_MDSPAN_INLINE_VARIABLE constexpr auto dyn = stdex::dynamic_extent; | ||
|
||
template<class MDSpan, class MDArray> | ||
struct MDArrayToMDSpanOperatorTest { | ||
using mdspan_t = MDSpan; | ||
using c_mdspan_t = stdex::mdspan<const typename mdspan_t::element_type, | ||
typename mdspan_t::extents_type, | ||
typename mdspan_t::layout_type>; | ||
static void test_check(mdspan_t mds, MDArray& mda) { | ||
ASSERT_EQ(mds.data_handle(), mda.data()); | ||
ASSERT_EQ(mds.extents(), mda.extents()); | ||
ASSERT_EQ(mds.mapping(), mda.mapping()); | ||
} | ||
static void test_check_const(c_mdspan_t mds, const MDArray& mda) { | ||
ASSERT_EQ(mds.data_handle(), mda.data()); | ||
ASSERT_EQ(mds.extents(), mda.extents()); | ||
ASSERT_EQ(mds.mapping(), mda.mapping()); | ||
} | ||
template<class ... ConstrArgs> | ||
static void test(ConstrArgs ... args) { | ||
MDArray a(args...); | ||
test_check(a, a); | ||
test_check(a.to_mdspan(), a); | ||
const MDArray& c_a = a; | ||
test_check_const(c_a, a); | ||
test_check_const(c_a.to_mdspan(), a); | ||
} | ||
}; | ||
|
||
TEST(TestMDArray,mdarray_to_mdspan) { | ||
MDArrayToMDSpanOperatorTest<stdex::mdspan <int, stdex::extents<int, dyn>>, | ||
stdex::mdarray<int, stdex::extents<int, dyn>>>::test( | ||
100 | ||
); | ||
MDArrayToMDSpanOperatorTest<stdex::mdspan <int, stdex::extents<int, dyn>>, | ||
stdex::mdarray<int, stdex::extents<int, 100>>>::test( | ||
100 | ||
); | ||
} | ||
|
||
|