Skip to content

Commit 9fb1d13

Browse files
authored
Fix slicing operator (#893)
* Fix slicing operator * Avoid mixing ADL and RebindDomain
1 parent 0c112d9 commit 9fb1d13

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

include/ddc/chunk_span.hpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,15 @@ class ChunkSpan : public ChunkCommon<ElementType, SupportType, LayoutStridedPoli
270270
KOKKOS_FUNCTION constexpr auto operator[](
271271
DiscreteElement<QueryDDims...> const& slice_spec) const
272272
{
273-
assert(select<QueryDDims...>(this->m_domain).contains(slice_spec));
273+
using detail::TypeSeq;
274+
using QueryDDom = typename detail::RebindDomain<SupportType, TypeSeq<QueryDDims...>>::type;
275+
assert(QueryDDom(this->m_domain).contains(slice_spec));
274276
slicer<to_type_seq_t<SupportType>> const slicer;
275277
auto subview = slicer(
276278
this->allocation_mdspan(),
277-
ddc::DiscreteDomain<QueryDDims...>(this->m_domain).distance_from_front(slice_spec));
279+
QueryDDom(this->m_domain).distance_from_front(slice_spec));
278280
using layout_type = typename decltype(subview)::layout_type;
279281
using extents_type = typename decltype(subview)::extents_type;
280-
using detail::TypeSeq;
281282
using OutTypeSeqDDims
282283
= type_seq_remove_t<to_type_seq_t<SupportType>, TypeSeq<QueryDDims...>>;
283284
using OutDDom = typename detail::RebindDomain<SupportType, OutTypeSeqDDims>::type;

tests/chunk.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ TEST(Chunk2DTest, SliceCoordXOutOfBounds)
526526
ChunkXY<double> chunk(dom_x_y);
527527

528528
char const* const death_msg
529-
= R"rgx([Aa]ssert.*select<QueryDDims...>\(this->m_domain\).contains\(slice_spec\))rgx";
529+
= R"rgx([Aa]ssert.*QueryDDom\(this->m_domain\).contains\(slice_spec\))rgx";
530530

531531
EXPECT_DEATH(chunk[dom_x.front() - 1], death_msg);
532532
EXPECT_DEATH(chunk[dom_x.back() + 1], death_msg);
@@ -684,3 +684,10 @@ TEST(ChunkStridedDiscreteDomain, Constructor)
684684
EXPECT_EQ(chk(lbound_x_y), 2);
685685
EXPECT_EQ(chk(lbound_x_y + DVectXY(10, 10)), 2);
686686
}
687+
688+
TEST(ChunkStridedDiscreteDomain, Slice)
689+
{
690+
ddc::StridedDiscreteDomain<DDimX, DDimY> const dom(lbound_x_y, nelems_x_y, DVectXY(10, 10));
691+
ddc::Chunk chk("", dom, ddc::HostAllocator<int>());
692+
EXPECT_EQ(chk(lbound_x_y), chk[lbound_x_y]());
693+
}

0 commit comments

Comments
 (0)