SimiLie
Loading...
Searching...
No Matches
scaling_tensor.hpp
1// SPDX-FileCopyrightText: 2026 Baptiste Legouix
2// SPDX-License-Identifier: AGPL-3.0-or-later
3// AI-GENERATED
4
5#pragma once
6
7#include <ddc/ddc.hpp>
8
9#include <similie/tensor/tensor_impl.hpp>
10
11namespace sil {
12
13namespace tensor {
14
22template <TensorNatIndex... TensorIndex>
24{
25 static_assert(
26 ((TensorIndex::size()
27 == ddc::type_seq_element_t<0, ddc::TypeSeq<TensorIndex...>>::size())
28 && ...));
29
30 static constexpr bool is_tensor_index = true;
31 static constexpr bool is_explicitely_stored_tensor = true;
32
33 using subindices_domain_t = ddc::DiscreteDomain<TensorIndex...>;
34
35 KOKKOS_FUNCTION static constexpr subindices_domain_t subindices_domain()
36 {
37 return ddc::DiscreteDomain<TensorIndex...>(
38 ddc::DiscreteElement<TensorIndex...>(ddc::DiscreteElement<TensorIndex>(0)...),
39 ddc::DiscreteVector<TensorIndex...>(
40 ddc::DiscreteVector<TensorIndex>(TensorIndex::size())...));
41 }
42
43 static constexpr std::size_t rank()
44 {
45 return (TensorIndex::rank() + ...);
46 }
47
48 static constexpr std::size_t size()
49 {
50 return (TensorIndex::size() * ...);
51 }
52
53 static constexpr std::size_t mem_size()
54 {
55 return 1;
56 }
57
58 static constexpr std::size_t access_size()
59 {
60 return 1 + mem_size();
61 }
62
63 KOKKOS_FUNCTION static constexpr std::size_t mem_id(
64 std::array<std::size_t, sizeof...(TensorIndex)> const& natural_ids)
65 {
66 assert(std::all_of(natural_ids.begin(), natural_ids.end(), [&](const std::size_t id) {
67 return id == *natural_ids.begin();
68 }));
69 return 0;
70 }
71
72 KOKKOS_FUNCTION static constexpr std::size_t access_id(
73 std::array<std::size_t, sizeof...(TensorIndex)> const& natural_ids)
74 {
75 if (!std::all_of(natural_ids.begin(), natural_ids.end(), [&](const std::size_t id) {
76 return id == *natural_ids.begin();
77 })) {
78 return 0;
79 } else {
80 return 1 + mem_id(natural_ids);
81 }
82 }
83
84 KOKKOS_FUNCTION static constexpr std::size_t access_id_to_mem_id(std::size_t access_id)
85 {
86 assert(access_id != 0 && "There is no mem_id associated to access_id=0");
87 return access_id - 1;
88 }
89
90 template <class Tensor, class Elem, class Id, class FunctorType>
91 KOKKOS_FUNCTION static constexpr Tensor::element_type process_access(
92 const FunctorType& access,
93 Tensor const& tensor,
94 Elem const& elem)
95 {
96 if (elem.template uid<Id>() == 0) {
97 return 0.;
98 } else {
99 return access(tensor, elem);
100 }
101 }
102
103 KOKKOS_FUNCTION static constexpr std::array<std::size_t, rank()>
105 {
106 assert(mem_id < mem_size());
107 std::array<std::size_t, rank()> ids;
108 std::fill(ids.begin(), ids.end(), 0);
109 return ids;
110 }
111};
112
113static_assert(TensorIndexConcept<TensorScalingIndex<TensorNaturalIndex<detail::DimensionConcept>>>);
114
115} // namespace tensor
116
117} // namespace sil
The top-level namespace of SimiLie.
Definition csr.hpp:15
Store a scalar multiple of the identity using one coefficient.
static constexpr bool is_tensor_index
static constexpr std::size_t size()
static constexpr std::size_t rank()
static KOKKOS_FUNCTION constexpr std::size_t access_id_to_mem_id(std::size_t access_id)
static constexpr bool is_explicitely_stored_tensor
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 access_id(std::array< std::size_t, sizeof...(TensorIndex)> const &natural_ids)
static KOKKOS_FUNCTION constexpr Tensor::element_type process_access(const FunctorType &access, Tensor const &tensor, Elem const &elem)
static constexpr std::size_t mem_size()
static constexpr std::size_t access_size()
static KOKKOS_FUNCTION constexpr subindices_domain_t subindices_domain()
static KOKKOS_FUNCTION constexpr std::size_t mem_id(std::array< std::size_t, sizeof...(TensorIndex)> const &natural_ids)
ddc::DiscreteDomain< TensorIndex... > subindices_domain_t