8#include <similie/misc/binomial_coefficient.hpp>
9#include <similie/misc/portable_stl.hpp>
11#include "tensor_impl.hpp"
29 ddc::DiscreteElement<
TensorIndex...>(ddc::DiscreteElement<TensorIndex>(0)...),
31 ddc::DiscreteVector<TensorIndex>(TensorIndex::size())...));
34 KOKKOS_FUNCTION
static constexpr std::size_t
rank()
36 if constexpr (
sizeof...(TensorIndex) == 0) {
39 return (TensorIndex::rank() + ...);
43 KOKKOS_FUNCTION
static constexpr std::size_t
size()
45 if constexpr (
rank() == 0) {
48 return (TensorIndex::size() + ...);
52 KOKKOS_FUNCTION
static constexpr std::size_t
mem_size()
54 if constexpr (
rank() == 0) {
58 ddc::type_seq_element_t<0, ddc::detail::TypeSeq<TensorIndex...>>
::mem_size(),
65 if constexpr (
rank() <= 1) {
72 KOKKOS_FUNCTION
static constexpr std::size_t
mem_id(
73 std::array<std::size_t,
rank()>
const natural_ids)
75 std::array<std::size_t,
rank()> sorted_ids(natural_ids);
76 misc::detail::sort(sorted_ids.begin(), sorted_ids.end());
79 + (sorted_ids[ddc::type_seq_rank_v<
82 == TensorIndex::mem_size() -
rank()
83 + ddc::type_seq_rank_v<
88 TensorIndex::mem_size()
89 - sorted_ids[ddc::type_seq_rank_v<
91 ddc::detail::TypeSeq<TensorIndex...>>]
94 - ddc::type_seq_rank_v<
96 ddc::detail::TypeSeq<TensorIndex...>>)))
101 static constexpr bool permutation_parity(std::array<std::size_t,
rank()> ids)
104 for (std::size_t i = 0; i <
rank(); i++)
105 for (std::size_t j = i + 1; j <
rank(); j++)
113 std::array<std::size_t,
rank()>
const natural_ids)
115 if constexpr (
rank() <= 1) {
116 return mem_id(natural_ids);
118 if (std::all_of(natural_ids.begin(), natural_ids.end(), [&](
const std::size_t
id) {
119 return id == *natural_ids.begin();
122 }
else if (!permutation_parity(natural_ids)) {
123 return 1 +
mem_id(natural_ids);
132 if constexpr (
rank() <= 1) {
138 return std::numeric_limits<std::size_t>::max();
143 template <
class Tensor,
class Elem,
class Id,
class FunctorType>
145 const FunctorType& access,
149 if constexpr (
rank() <= 1) {
150 return access(tensor, elem);
152 if (elem.template uid<Id>() == 0) {
154 }
else if (elem.template uid<Id>() <
access_size()) {
155 return access(tensor, elem);
157 return -access(tensor, elem);
162 KOKKOS_FUNCTION
static constexpr std::array<std::size_t,
rank()>
166 if constexpr (
rank() == 0) {
167 return std::array<std::size_t,
rank()> {};
169 std::array<std::size_t,
rank()> ids;
172 std::size_t r =
rank();
173 for (std::size_t i = 0; i <
rank(); ++i) {
175 for (std::size_t j = 0; j < d; ++j) {
176 const std::size_t subtriangle_size
178 if (triangle_size - subtriangle_size >
mem_id) {
179 ids[i] = ddc::type_seq_element_t<0, ddc::detail::TypeSeq<
TensorIndex...>>
::
197struct ToTensorAntisymmetricIndex;
199template <tensor::TensorNatIndex Index>
200 requires(Index::rank() == 0)
201struct ToTensorAntisymmetricIndex<Index>
203 using type = TensorAntisymmetricIndex<>;
206template <tensor::TensorNatIndex Index>
207 requires(Index::rank() > 0)
208struct ToTensorAntisymmetricIndex<Index>
210 using type = TensorAntisymmetricIndex<Index>;
213template <tensor::TensorNatIndex... Index>
214struct ToTensorAntisymmetricIndex<TensorAntisymmetricIndex<Index...>>
216 using type = TensorAntisymmetricIndex<Index...>;
constexpr std::size_t binomial_coefficient(std::size_t n, std::size_t k) noexcept
typename detail::ToTensorAntisymmetricIndex< T >::type to_tensor_antisymmetric_index_t
Tensor(ddc::Chunk< ElementType, SupportType, Allocator >) -> Tensor< ElementType, SupportType, Kokkos::layout_right, typename Allocator::memory_space >
The top-level namespace of SimiLie.
static KOKKOS_FUNCTION constexpr std::size_t access_size()
static KOKKOS_FUNCTION constexpr std::size_t mem_size()
static KOKKOS_FUNCTION constexpr std::size_t access_id(std::array< std::size_t, rank()> const natural_ids)
static KOKKOS_FUNCTION constexpr Tensor::element_type process_access(const FunctorType &access, Tensor tensor, Elem elem)
static KOKKOS_FUNCTION constexpr std::size_t rank()
static constexpr bool is_explicitely_stored_tensor
static KOKKOS_FUNCTION constexpr std::size_t mem_id(std::array< std::size_t, rank()> const natural_ids)
ddc::DiscreteDomain< TensorIndex... > subindices_domain_t
static KOKKOS_FUNCTION constexpr std::size_t access_id_to_mem_id(std::size_t access_id)
static constexpr bool is_tensor_index
static KOKKOS_FUNCTION constexpr std::size_t size()
static KOKKOS_FUNCTION constexpr std::array< std::size_t, rank()> mem_id_to_canonical_natural_ids(std::size_t mem_id)
static KOKKOS_FUNCTION constexpr subindices_domain_t subindices_domain()