Skip to content

Commit 9ef820e

Browse files
Allow the reordering of a DiscreteDomain (#420)
* Add a reordered assignment operator --------- Co-authored-by: Emily Bourne <emily.bourne@epfl.ch> Co-authored-by: Thomas Padioleau <thomas.padioleau@cea.fr>
1 parent c13d10e commit 9ef820e

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

include/ddc/discrete_domain.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,25 @@ class DiscreteDomain
100100

101101
KOKKOS_DEFAULTED_FUNCTION DiscreteDomain& operator=(DiscreteDomain&& x) = default;
102102

103+
/**
104+
* @brief Copy a DiscreteDomain by reordering and slicing.
105+
*
106+
* An assign operator to build a DiscreteDomain from another compatible domain.
107+
* A domain is compatible if it either contains the same dimensions as this
108+
* domain (even if they are in a different order) or if it contains at
109+
* the dimensions of this domain plus some additional dimensions which will
110+
* be unused here.
111+
*
112+
* @param domain A compatible domain.
113+
*/
114+
template <class... ODDims>
115+
DiscreteDomain& KOKKOS_FUNCTION operator=(DiscreteDomain<ODDims...> const& domain)
116+
{
117+
m_element_begin = DiscreteElement<DDims...>(domain.front());
118+
m_element_end = m_element_begin + DiscreteVector<DDims...>(domain.extents());
119+
return *this;
120+
}
121+
103122
template <class... ODims>
104123
KOKKOS_FUNCTION constexpr bool operator==(DiscreteDomain<ODims...> const& other) const
105124
{

tests/discrete_domain.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ using DElemXYZ = ddc::DiscreteElement<DDimX, DDimY, DDimZ>;
5454
using DVectXYZ = ddc::DiscreteVector<DDimX, DDimY, DDimZ>;
5555
using DDomXYZ = ddc::DiscreteDomain<DDimX, DDimY, DDimZ>;
5656

57+
using DElemZYX = ddc::DiscreteElement<DDimZ, DDimY, DDimX>;
58+
using DVectZYX = ddc::DiscreteVector<DDimZ, DDimY, DDimX>;
59+
using DDomZYX = ddc::DiscreteDomain<DDimZ, DDimY, DDimX>;
5760

5861
static DElemX constexpr lbound_x(50);
5962
static DVectX constexpr nelems_x(3);
@@ -234,3 +237,34 @@ TEST(ProductMDomainTest, SliceDomainXToolate)
234237
R"rgx([Aa]ssert.*uid<ODDims>\(m_element_end\).*uid<ODDims>\(odomain\.m_element_end\).*)rgx");
235238
#endif
236239
}
240+
241+
TEST(ProductMDomainTest, Transpose3DConstructor)
242+
{
243+
DDomX const dom_x(lbound_x, nelems_x);
244+
DDomY const dom_y(lbound_y, nelems_y);
245+
DDomZ const dom_z(lbound_z, nelems_z);
246+
DDomXYZ const dom_x_y_z(dom_x, dom_y, dom_z);
247+
DDomZYX const dom_z_y_x(dom_x_y_z);
248+
EXPECT_EQ(ddc::select<DDimX>(dom_x_y_z.front()), ddc::select<DDimX>(dom_z_y_x.front()));
249+
EXPECT_EQ(ddc::select<DDimY>(dom_x_y_z.front()), ddc::select<DDimY>(dom_z_y_x.front()));
250+
EXPECT_EQ(ddc::select<DDimZ>(dom_x_y_z.front()), ddc::select<DDimZ>(dom_z_y_x.front()));
251+
EXPECT_EQ(ddc::select<DDimX>(dom_x_y_z.back()), ddc::select<DDimX>(dom_z_y_x.back()));
252+
EXPECT_EQ(ddc::select<DDimY>(dom_x_y_z.back()), ddc::select<DDimY>(dom_z_y_x.back()));
253+
EXPECT_EQ(ddc::select<DDimZ>(dom_x_y_z.back()), ddc::select<DDimZ>(dom_z_y_x.back()));
254+
}
255+
256+
TEST(ProductMDomainTest, Transpose3DAssign)
257+
{
258+
DDomX const dom_x(lbound_x, nelems_x);
259+
DDomY const dom_y(lbound_y, nelems_y);
260+
DDomZ const dom_z(lbound_z, nelems_z);
261+
DDomXYZ const dom_x_y_z(dom_x, dom_y, dom_z);
262+
DDomZYX dom_z_y_x;
263+
dom_z_y_x = dom_x_y_z;
264+
EXPECT_EQ(ddc::select<DDimX>(dom_x_y_z.front()), ddc::select<DDimX>(dom_z_y_x.front()));
265+
EXPECT_EQ(ddc::select<DDimY>(dom_x_y_z.front()), ddc::select<DDimY>(dom_z_y_x.front()));
266+
EXPECT_EQ(ddc::select<DDimZ>(dom_x_y_z.front()), ddc::select<DDimZ>(dom_z_y_x.front()));
267+
EXPECT_EQ(ddc::select<DDimX>(dom_x_y_z.back()), ddc::select<DDimX>(dom_z_y_x.back()));
268+
EXPECT_EQ(ddc::select<DDimY>(dom_x_y_z.back()), ddc::select<DDimY>(dom_z_y_x.back()));
269+
EXPECT_EQ(ddc::select<DDimZ>(dom_x_y_z.back()), ddc::select<DDimZ>(dom_z_y_x.back()));
270+
}

0 commit comments

Comments
 (0)