8#include <similie/misc/binomial_coefficient.hpp>
9#include <similie/misc/portable_stl.hpp>
10#include <similie/tensor/tensor_impl.hpp>
17template <TensorNatIndex... TensorIndex>
20 static_assert(((TensorIndex::rank() == 1) && ...));
30 ddc::DiscreteElement<
TensorIndex...>(ddc::DiscreteElement<TensorIndex>(0)...),
32 ddc::DiscreteVector<TensorIndex>(TensorIndex::size())...));
35 static constexpr std::size_t
rank()
37 if constexpr (
sizeof...(TensorIndex) == 0) {
40 return (TensorIndex::rank() + ...);
44 static constexpr std::size_t
size()
46 if constexpr (
rank() == 0) {
49 return (TensorIndex::size() * ...);
56 std::array<std::size_t,
sizeof...(TensorIndex)>
const sizes {TensorIndex::size()...};
57 for (std::size_t i = 1; i < sizes.size(); ++i) {
58 if (sizes[i] != sizes[0]) {
64 if constexpr (
rank() == 0) {
68 ddc::type_seq_element_t<0, ddc::TypeSeq<TensorIndex...>>
::mem_size(),
75 if constexpr (
rank() <= 1) {
82 KOKKOS_FUNCTION
static constexpr std::size_t
mem_id(
83 std::array<std::size_t,
rank()>
const& natural_ids)
85 std::array<std::size_t,
rank()> sorted_ids(natural_ids);
86 misc::detail::sort(sorted_ids.begin(), sorted_ids.end());
87 for (std::size_t i = 1; i <
rank(); ++i) {
88 assert(sorted_ids[i - 1] != sorted_ids[i]);
93 == TensorIndex::mem_size() -
rank()
94 + ddc::type_seq_rank_v<
99 TensorIndex::mem_size()
100 - sorted_ids[ddc::type_seq_rank_v<
102 ddc::TypeSeq<TensorIndex...>>]
105 - ddc::type_seq_rank_v<
107 ddc::TypeSeq<TensorIndex...>>)))
112 KOKKOS_FUNCTION
static constexpr bool permutation_parity(
113 std::array<std::size_t,
rank()>
const& ids)
116 for (std::size_t i = 0; i <
rank(); i++)
117 for (std::size_t j = i + 1; j <
rank(); j++)
125 std::array<std::size_t,
rank()>
const& natural_ids)
127 if constexpr (
rank() <= 1) {
128 return mem_id(natural_ids);
130 for (std::size_t i = 0; i <
rank(); ++i) {
131 for (std::size_t j = i + 1; j <
rank(); ++j) {
132 if (natural_ids[i] == natural_ids[j]) {
137 if (!permutation_parity(natural_ids)) {
138 return 1 +
mem_id(natural_ids);
147 if constexpr (
rank() <= 1) {
153 return std::numeric_limits<std::size_t>::max();
158 template <
class Tensor,
class Elem,
class Id,
class FunctorType>
160 const FunctorType& access,
164 if constexpr (
rank() <= 1) {
165 return access(tensor, elem);
167 if (elem.template uid<Id>() == 0) {
169 }
else if (elem.template uid<Id>() <=
mem_size()) {
170 return access(tensor, elem);
172 return -access(tensor, elem);
177 KOKKOS_FUNCTION
static constexpr std::array<std::size_t,
rank()>
181 if constexpr (
rank() == 0) {
182 return std::array<std::size_t,
rank()> {};
184 std::array<std::size_t,
rank()> ids;
186 std::size_t r =
rank();
187 for (std::size_t i = 0; i <
rank(); ++i) {
189 for (std::size_t j = 0; j < d; ++j) {
190 const std::size_t subtriangle_size
192 if (triangle_size - subtriangle_size >
mem_id) {
193 ids[i] = ddc::type_seq_element_t<0, ddc::TypeSeq<
TensorIndex...>>
::
209 TensorIndexConcept<TensorAntisymmetricIndex<TensorNaturalIndex<detail::DimensionConcept>>>);
214struct ToTensorAntisymmetricIndex;
216template <tensor::TensorNatIndex Index>
217 requires(Index::rank() == 0)
218struct ToTensorAntisymmetricIndex<Index>
220 using type = TensorAntisymmetricIndex<>;
223template <tensor::TensorNatIndex Index>
224 requires(Index::rank() > 0)
225struct ToTensorAntisymmetricIndex<Index>
227 using type = TensorAntisymmetricIndex<Index>;
230template <tensor::TensorNatIndex... Index>
231struct ToTensorAntisymmetricIndex<TensorAntisymmetricIndex<Index...>>
233 using type = TensorAntisymmetricIndex<Index...>;
KOKKOS_FUNCTION 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
The top-level namespace of SimiLie.
static constexpr std::size_t access_size()
static constexpr std::size_t mem_size()
static constexpr bool is_explicitely_stored_tensor
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 constexpr std::size_t rank()
static KOKKOS_FUNCTION constexpr Tensor::element_type process_access(const FunctorType &access, Tensor const &tensor, Elem const &elem)
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 std::size_t mem_id(std::array< std::size_t, rank()> const &natural_ids)
static constexpr std::size_t size()
static KOKKOS_FUNCTION constexpr subindices_domain_t subindices_domain()
static KOKKOS_FUNCTION constexpr std::size_t access_id(std::array< std::size_t, rank()> const &natural_ids)