|
6 | 6 |
|
7 | 7 | #include <cassert> |
8 | 8 | #include <string> |
| 9 | +#include <type_traits> |
9 | 10 | #include <utility> |
10 | 11 |
|
11 | 12 | #include <Kokkos_Core.hpp> |
|
14 | 15 | #include "ddc/chunk_span.hpp" |
15 | 16 | #include "ddc/chunk_traits.hpp" |
16 | 17 | #include "ddc/detail/kokkos.hpp" |
| 18 | +#include "ddc/detail/type_traits.hpp" |
17 | 19 | #include "ddc/kokkos_allocator.hpp" |
18 | 20 |
|
19 | 21 | namespace ddc { |
@@ -60,6 +62,8 @@ class Chunk<ElementType, DiscreteDomain<DDims...>, Allocator> |
60 | 62 |
|
61 | 63 | using discrete_element_type = typename base_type::discrete_element_type; |
62 | 64 |
|
| 65 | + using discrete_vector_type = typename base_type::discrete_vector_type; |
| 66 | + |
63 | 67 | using extents_type = typename base_type::extents_type; |
64 | 68 |
|
65 | 69 | using layout_type = typename base_type::layout_type; |
@@ -181,38 +185,72 @@ class Chunk<ElementType, DiscreteDomain<DDims...>, Allocator> |
181 | 185 | * @param delems discrete coordinates |
182 | 186 | * @return const-reference to this element |
183 | 187 | */ |
184 | | - template <class... DElems> |
| 188 | + template < |
| 189 | + class... DElems, |
| 190 | + std::enable_if_t<detail::all_of_v<is_discrete_element_v<DElems>...>, int> = 0> |
185 | 191 | element_type const& operator()(DElems const&... delems) const noexcept |
186 | 192 | { |
187 | 193 | static_assert( |
188 | 194 | sizeof...(DDims) == (0 + ... + DElems::size()), |
189 | 195 | "Invalid number of dimensions"); |
190 | 196 | static_assert((is_discrete_element_v<DElems> && ...), "Expected DiscreteElements"); |
191 | | - assert(((DiscreteElement<DDims>(take<DDims>(delems...)) >= front<DDims>(this->m_domain)) |
192 | | - && ...)); |
193 | | - assert(((DiscreteElement<DDims>(take<DDims>(delems...)) <= back<DDims>(this->m_domain)) |
194 | | - && ...)); |
| 197 | + assert(this->m_domain.contains(delems...)); |
195 | 198 | return DDC_MDSPAN_ACCESS_OP(this->m_internal_mdspan, uid<DDims>(take<DDims>(delems...))...); |
196 | 199 | } |
197 | 200 |
|
| 201 | + /** Element access using a list of DiscreteVector |
| 202 | + * @param dvects discrete vectors |
| 203 | + * @return reference to this element |
| 204 | + */ |
| 205 | + template < |
| 206 | + class... DVects, |
| 207 | + std::enable_if_t<detail::all_of_v<is_discrete_vector_v<DVects>...>, int> = 0, |
| 208 | + std::enable_if_t<sizeof...(DVects) != 0, int> = 0> |
| 209 | + element_type const& operator()(DVects const&... dvects) const noexcept |
| 210 | + { |
| 211 | + static_assert( |
| 212 | + sizeof...(DDims) == (0 + ... + DVects::size()), |
| 213 | + "Invalid number of dimensions"); |
| 214 | + discrete_element_type const delem |
| 215 | + = this->m_domain.front() + discrete_vector_type(dvects...); |
| 216 | + return DDC_MDSPAN_ACCESS_OP(this->m_internal_mdspan, uid<DDims>(delem)...); |
| 217 | + } |
| 218 | + |
198 | 219 | /** Element access using a list of DiscreteElement |
199 | 220 | * @param delems discrete coordinates |
200 | 221 | * @return reference to this element |
201 | 222 | */ |
202 | | - template <class... DElems> |
| 223 | + template < |
| 224 | + class... DElems, |
| 225 | + std::enable_if_t<detail::all_of_v<is_discrete_element_v<DElems>...>, int> = 0> |
203 | 226 | element_type& operator()(DElems const&... delems) noexcept |
204 | 227 | { |
205 | 228 | static_assert( |
206 | 229 | sizeof...(DDims) == (0 + ... + DElems::size()), |
207 | 230 | "Invalid number of dimensions"); |
208 | 231 | static_assert((is_discrete_element_v<DElems> && ...), "Expected DiscreteElements"); |
209 | | - assert(((DiscreteElement<DDims>(take<DDims>(delems...)) >= front<DDims>(this->m_domain)) |
210 | | - && ...)); |
211 | | - assert(((DiscreteElement<DDims>(take<DDims>(delems...)) <= back<DDims>(this->m_domain)) |
212 | | - && ...)); |
| 232 | + assert(this->m_domain.contains(delems...)); |
213 | 233 | return DDC_MDSPAN_ACCESS_OP(this->m_internal_mdspan, uid<DDims>(take<DDims>(delems...))...); |
214 | 234 | } |
215 | 235 |
|
| 236 | + /** Element access using a list of DiscreteVector |
| 237 | + * @param dvects discrete vectors |
| 238 | + * @return reference to this element |
| 239 | + */ |
| 240 | + template < |
| 241 | + class... DVects, |
| 242 | + std::enable_if_t<detail::all_of_v<is_discrete_vector_v<DVects>...>, int> = 0, |
| 243 | + std::enable_if_t<sizeof...(DVects) != 0, int> = 0> |
| 244 | + element_type& operator()(DVects const&... dvects) noexcept |
| 245 | + { |
| 246 | + static_assert( |
| 247 | + sizeof...(DDims) == (0 + ... + DVects::size()), |
| 248 | + "Invalid number of dimensions"); |
| 249 | + discrete_element_type const delem |
| 250 | + = this->m_domain.front() + discrete_vector_type(dvects...); |
| 251 | + return DDC_MDSPAN_ACCESS_OP(this->m_internal_mdspan, uid<DDims>(delem)...); |
| 252 | + } |
| 253 | + |
216 | 254 | /** Returns the label of the Chunk |
217 | 255 | * @return c-string |
218 | 256 | */ |
@@ -333,6 +371,8 @@ class Chunk : public ChunkCommon<ElementType, SupportType, Kokkos::layout_right> |
333 | 371 |
|
334 | 372 | using discrete_element_type = typename base_type::discrete_element_type; |
335 | 373 |
|
| 374 | + using discrete_vector_type = typename base_type::discrete_vector_type; |
| 375 | + |
336 | 376 | using extents_type = typename base_type::extents_type; |
337 | 377 |
|
338 | 378 | using layout_type = typename base_type::layout_type; |
@@ -442,36 +482,74 @@ class Chunk : public ChunkCommon<ElementType, SupportType, Kokkos::layout_right> |
442 | 482 | * @param delems discrete coordinates |
443 | 483 | * @return const-reference to this element |
444 | 484 | */ |
445 | | - template <class... DElems> |
| 485 | + template < |
| 486 | + class... DElems, |
| 487 | + std::enable_if_t<detail::all_of_v<is_discrete_element_v<DElems>...>, int> = 0> |
446 | 488 | element_type const& operator()(DElems const&... delems) const noexcept |
447 | 489 | { |
448 | 490 | static_assert( |
449 | 491 | SupportType::rank() == (0 + ... + DElems::size()), |
450 | 492 | "Invalid number of dimensions"); |
451 | | - static_assert((is_discrete_element_v<DElems> && ...), "Expected DiscreteElements"); |
452 | 493 | assert(this->m_domain.contains(delems...)); |
453 | 494 | return DDC_MDSPAN_ACCESS_OP( |
454 | 495 | this->m_allocation_mdspan, |
455 | 496 | detail::array(this->m_domain.distance_from_front(delems...))); |
456 | 497 | } |
457 | 498 |
|
| 499 | + /** Element access using a list of DiscreteVector |
| 500 | + * @param dvects discrete vectors |
| 501 | + * @return reference to this element |
| 502 | + */ |
| 503 | + template < |
| 504 | + class... DVects, |
| 505 | + std::enable_if_t<detail::all_of_v<is_discrete_vector_v<DVects>...>, int> = 0, |
| 506 | + std::enable_if_t<sizeof...(DVects) != 0, int> = 0> |
| 507 | + element_type const& operator()(DVects const&... dvects) const noexcept |
| 508 | + { |
| 509 | + static_assert( |
| 510 | + SupportType::rank() == (0 + ... + DVects::size()), |
| 511 | + "Invalid number of dimensions"); |
| 512 | + return DDC_MDSPAN_ACCESS_OP( |
| 513 | + this->m_allocation_mdspan, |
| 514 | + detail::array(discrete_vector_type(dvects...))); |
| 515 | + } |
| 516 | + |
458 | 517 | /** Element access using a list of DiscreteElement |
459 | 518 | * @param delems discrete coordinates |
460 | 519 | * @return reference to this element |
461 | 520 | */ |
462 | | - template <class... DElems> |
| 521 | + template < |
| 522 | + class... DElems, |
| 523 | + std::enable_if_t<detail::all_of_v<is_discrete_element_v<DElems>...>, int> = 0> |
463 | 524 | element_type& operator()(DElems const&... delems) noexcept |
464 | 525 | { |
465 | 526 | static_assert( |
466 | 527 | SupportType::rank() == (0 + ... + DElems::size()), |
467 | 528 | "Invalid number of dimensions"); |
468 | | - static_assert((is_discrete_element_v<DElems> && ...), "Expected DiscreteElements"); |
469 | 529 | assert(this->m_domain.contains(delems...)); |
470 | 530 | return DDC_MDSPAN_ACCESS_OP( |
471 | 531 | this->m_allocation_mdspan, |
472 | 532 | detail::array(this->m_domain.distance_from_front(delems...))); |
473 | 533 | } |
474 | 534 |
|
| 535 | + /** Element access using a list of DiscreteVector |
| 536 | + * @param dvects discrete vectors |
| 537 | + * @return reference to this element |
| 538 | + */ |
| 539 | + template < |
| 540 | + class... DVects, |
| 541 | + std::enable_if_t<detail::all_of_v<is_discrete_vector_v<DVects>...>, int> = 0, |
| 542 | + std::enable_if_t<sizeof...(DVects) != 0, int> = 0> |
| 543 | + element_type& operator()(DVects const&... dvects) noexcept |
| 544 | + { |
| 545 | + static_assert( |
| 546 | + SupportType::rank() == (0 + ... + DVects::size()), |
| 547 | + "Invalid number of dimensions"); |
| 548 | + return DDC_MDSPAN_ACCESS_OP( |
| 549 | + this->m_allocation_mdspan, |
| 550 | + detail::array(discrete_vector_type(dvects...))); |
| 551 | + } |
| 552 | + |
475 | 553 | /** Returns the label of the Chunk |
476 | 554 | * @return c-string |
477 | 555 | */ |
|
0 commit comments