8#include <similie/tensor/tensor_impl.hpp>
16template <
class IndexToRelabelize, TensorIndex OldIndex, TensorIndex NewIndex>
17struct RelabelizeIndex;
19template <
class IndexToRelabelize, TensorIndex OldIndex, TensorIndex NewIndex>
20 requires(!TensorIndex<IndexToRelabelize> || TensorNatIndex<IndexToRelabelize>)
21struct RelabelizeIndex<IndexToRelabelize, OldIndex, NewIndex>
24 conditional_t<std::is_same_v<IndexToRelabelize, OldIndex>, NewIndex, IndexToRelabelize>;
28 template <
class...>
class IndexToRelabelizeType,
32struct RelabelizeIndex<IndexToRelabelizeType<Arg...>, OldIndex, NewIndex>
34 using type = std::conditional_t<
35 std::is_same_v<IndexToRelabelizeType<Arg...>, OldIndex>,
37 IndexToRelabelizeType<typename RelabelizeIndex<Arg, OldIndex, NewIndex>::type...>>;
40template <
class T,
class OldIndex,
class NewIndex>
41struct RelabelizeIndexInType;
43template <
template <
class...>
class T,
class... DDim,
class OldIndex,
class NewIndex>
44struct RelabelizeIndexInType<T<DDim...>, OldIndex, NewIndex>
46 using type = T<typename RelabelizeIndex<DDim, OldIndex, NewIndex>::type...>;
51template <
class T, TensorIndex OldIndex, TensorIndex NewIndex>
56template <
class OldIndex,
class NewIndex>
57struct RelabelizeIndexIn
59 template <
class... DDim>
60 KOKKOS_FUNCTION
static constexpr auto operator()(ddc::DiscreteElement<DDim...> elem)
62 return ddc::DiscreteElement<
63 typename detail::RelabelizeIndex<DDim, OldIndex, NewIndex>::type...>(
64 elem.template uid<DDim>()...);
67 template <
class... DDim>
68 KOKKOS_FUNCTION
static constexpr auto operator()(ddc::DiscreteVector<DDim...> vect)
70 return ddc::DiscreteVector<
71 typename detail::RelabelizeIndex<DDim, OldIndex, NewIndex>::type...>(
72 static_cast<std::size_t
>(vect.template get<DDim>())...);
75 template <
class... DDim>
76 KOKKOS_FUNCTION
static constexpr auto operator()(ddc::DiscreteDomain<DDim...>
const& dom)
86template <
class OldIndex,
class NewIndex,
class T>
89 return detail::RelabelizeIndexIn<OldIndex, NewIndex>::operator()(t);
93template <
class TensorType,
class OldIndex,
class NewIndex>
94struct RelabelizeIndexOfType;
101 class LayoutStridedPolicy,
103struct RelabelizeIndexOfType<
104 Tensor<ElementType, Dom, LayoutStridedPolicy, MemorySpace>,
110 typename RelabelizeIndexInType<Dom, OldIndex, NewIndex>::type,
117template <misc::Specialization<Tensor> TensorType, TensorIndex OldIndex, TensorIndex NewIndex>
125 class LayoutStridedPolicy,
128 Tensor<ElementType, ddc::DiscreteDomain<DDim...>, LayoutStridedPolicy, MemorySpace>,
132 Tensor<ElementType, ddc::DiscreteDomain<DDim...>, LayoutStridedPolicy, MemorySpace>
const&
136 Tensor<ElementType, ddc::DiscreteDomain<DDim...>, LayoutStridedPolicy, MemorySpace>,
139 old_tensor.allocation_mdspan(),
140 typename detail::RelabelizeIndexInType<
141 ddc::DiscreteDomain<DDim...>,
144 type(ddc::DiscreteDomain<
145 typename detail::RelabelizeIndex<DDim, OldIndex, NewIndex>::type>(
146 ddc::DiscreteElement<
147 typename detail::RelabelizeIndex<DDim, OldIndex, NewIndex>::
148 type>(old_tensor.domain().front().template uid<DDim>()),
150 typename detail::RelabelizeIndex<DDim, OldIndex, NewIndex>::
151 type>(
static_cast<std::size_t
>(
152 old_tensor.template extent<DDim>())))...));
156template <
class IndexToRelabelize,
class OldIndices,
class NewIndices>
157struct RelabelizeIndices;
159template <
class IndexToRelabelize>
160struct RelabelizeIndices<IndexToRelabelize,
ddc::TypeSeq<>, ddc::TypeSeq<>>
162 using type = IndexToRelabelize;
166 class IndexToRelabelize,
168 class... TailOldIndex,
170 class... TailNewIndex>
171struct RelabelizeIndices<
173 ddc::TypeSeq<HeadOldIndex, TailOldIndex...>,
174 ddc::TypeSeq<HeadNewIndex, TailNewIndex...>>
176 static_assert(
sizeof...(TailOldIndex) ==
sizeof...(TailNewIndex));
177 using type = std::conditional_t<
178 (
sizeof...(TailOldIndex) > 0),
179 typename RelabelizeIndices<
180 typename RelabelizeIndex<IndexToRelabelize, HeadOldIndex, HeadNewIndex>::type,
181 ddc::TypeSeq<TailOldIndex...>,
182 ddc::TypeSeq<TailNewIndex...>>::type,
183 typename RelabelizeIndex<IndexToRelabelize, HeadOldIndex, HeadNewIndex>::type>;
186template <
class T,
class OldIndices,
class NewIndices>
187struct RelabelizeIndicesInType;
190struct RelabelizeIndicesInType<T,
ddc::TypeSeq<>, ddc::TypeSeq<>>
198 class... TailOldIndex,
200 class... TailNewIndex>
201struct RelabelizeIndicesInType<
203 ddc::TypeSeq<HeadOldIndex, TailOldIndex...>,
204 ddc::TypeSeq<HeadNewIndex, TailNewIndex...>>
206 static_assert(
sizeof...(TailOldIndex) ==
sizeof...(TailNewIndex));
207 using type =
typename RelabelizeIndicesInType<
209 ddc::TypeSeq<TailOldIndex...>,
210 ddc::TypeSeq<TailNewIndex...>>::type;
215template <
class T,
class OldIndices,
class NewIndices>
217 typename detail::RelabelizeIndicesInType<T, OldIndices, NewIndices>::type;
221template <
class OldIndices,
class NewIndices, std::
size_t I = 0>
222struct RelabelizeIndicesIn
224 template <
class... DDim>
225 KOKKOS_FUNCTION
static constexpr auto operator()(ddc::DiscreteElement<DDim...> elem)
227 if constexpr (I != ddc::type_seq_size_v<OldIndices>) {
228 return RelabelizeIndicesIn<OldIndices, NewIndices, I + 1>::operator()(
230 ddc::type_seq_element_t<I, OldIndices>,
231 ddc::type_seq_element_t<I, NewIndices>>(elem));
237 template <
class... DDim>
238 KOKKOS_FUNCTION
static constexpr auto operator()(ddc::DiscreteVector<DDim...> vect)
240 if constexpr (I != ddc::type_seq_size_v<OldIndices>) {
241 return RelabelizeIndicesIn<OldIndices, NewIndices, I + 1>::operator()(
243 ddc::type_seq_element_t<I, OldIndices>,
244 ddc::type_seq_element_t<I, NewIndices>>(vect));
250 template <
class... DDim>
251 KOKKOS_FUNCTION
static constexpr auto operator()(ddc::DiscreteDomain<DDim...>
const& dom)
253 if constexpr (I != ddc::type_seq_size_v<OldIndices>) {
254 return RelabelizeIndicesIn<OldIndices, NewIndices, I + 1>::operator()(
256 ddc::type_seq_element_t<I, OldIndices>,
257 ddc::type_seq_element_t<I, NewIndices>>(dom));
266template <
class OldIndices,
class NewIndices,
class T>
270 static_assert(ddc::type_seq_size_v<OldIndices> == ddc::type_seq_size_v<NewIndices>);
271 return detail::RelabelizeIndicesIn<OldIndices, NewIndices>::operator()(t);
276template <
class TensorType,
class OldIndex,
class NewIndex>
277struct RelabelizeIndicesOfType;
284 class LayoutStridedPolicy,
286struct RelabelizeIndicesOfType<
287 Tensor<ElementType, Dom, LayoutStridedPolicy, MemorySpace>,
291 static_assert(ddc::type_seq_size_v<OldIndices> == ddc::type_seq_size_v<NewIndices>);
294 typename RelabelizeIndicesInType<Dom, OldIndices, NewIndices>::type,
305 class LayoutStridedPolicy,
307KOKKOS_FUNCTION
constexpr auto RelabelizeIndicesOf(
308 Tensor<ElementType, ddc::DiscreteDomain<DDim...>, LayoutStridedPolicy, MemorySpace>
const&
311 static_assert(ddc::type_seq_size_v<OldIndices> == ddc::type_seq_size_v<NewIndices>);
312 if constexpr (I != ddc::type_seq_size_v<OldIndices>) {
313 return RelabelizeIndicesOf<
314 ddc::type_seq_replace_t<
316 ddc::TypeSeq<ddc::type_seq_element_t<I, OldIndices>>,
317 ddc::TypeSeq<ddc::type_seq_element_t<I, NewIndices>>>,
321 ddc::DiscreteDomain<DDim...>,
324 ddc::type_seq_element_t<I, OldIndices>,
325 ddc::type_seq_element_t<I, NewIndices>>(
326 old_tensor.allocation_mdspan(),
327 typename detail::RelabelizeIndexInType<
328 ddc::DiscreteDomain<DDim...>,
329 ddc::type_seq_element_t<I, OldIndices>,
330 ddc::type_seq_element_t<I, NewIndices>>::
331 type(ddc::DiscreteDomain<
typename detail::RelabelizeIndex<
333 ddc::type_seq_element_t<I, OldIndices>,
334 ddc::type_seq_element_t<I, NewIndices>>::type>(
335 ddc::DiscreteElement<
typename detail::RelabelizeIndex<
337 ddc::type_seq_element_t<I, OldIndices>,
338 ddc::type_seq_element_t<I, NewIndices>>::type>(
339 old_tensor.domain().front().template uid<DDim>()),
340 ddc::DiscreteVector<
typename detail::RelabelizeIndex<
342 ddc::type_seq_element_t<I, OldIndices>,
343 ddc::type_seq_element_t<I, NewIndices>>::type>(
344 static_cast<std::size_t
>(
345 old_tensor.template extent<DDim>())))...)));
354 misc::Specialization<Tensor> TensorType,
355 misc::Specialization<ddc::TypeSeq> OldIndices,
356 misc::Specialization<ddc::TypeSeq> NewIndices>
358 = detail::RelabelizeIndicesOfType<TensorType, OldIndices, NewIndices>::type;
367 static_assert(ddc::type_seq_size_v<OldIndices> == ddc::type_seq_size_v<NewIndices>);
368 return detail::RelabelizeIndicesOf<OldIndices, NewIndices, 0>(tensor);
Tensor(ddc::Chunk< ElementType, SupportType, Allocator >) -> Tensor< ElementType, SupportType, Kokkos::layout_right, typename Allocator::memory_space >
detail::RelabelizeIndicesOfType< TensorType, OldIndices, NewIndices >::type relabelize_indices_of_t
KOKKOS_FUNCTION constexpr relabelize_indices_in_t< T, OldIndices, NewIndices > relabelize_indices_in(T t)
detail::RelabelizeIndexInType< T, OldIndex, NewIndex >::type relabelize_index_in_t
detail::RelabelizeIndexOfType< TensorType, OldIndex, NewIndex >::type relabelize_index_of_t
KOKKOS_FUNCTION constexpr relabelize_index_of_t< Tensor< ElementType, ddc::DiscreteDomain< DDim... >, LayoutStridedPolicy, MemorySpace >, OldIndex, NewIndex > relabelize_index_of(Tensor< ElementType, ddc::DiscreteDomain< DDim... >, LayoutStridedPolicy, MemorySpace > const &old_tensor)
KOKKOS_FUNCTION constexpr relabelize_indices_of_t< Tensor, OldIndices, NewIndices > relabelize_indices_of(Tensor const &tensor)
KOKKOS_FUNCTION constexpr relabelize_index_in_t< T, OldIndex, NewIndex > relabelize_index_in(T t)
typename detail::RelabelizeIndicesInType< T, OldIndices, NewIndices >::type relabelize_indices_in_t
The top-level namespace of SimiLie.