1#ifndef TATOOINE_EINSTEIN_NOTATION_CONTRACTED_STATIC_TENSOR_H
2#define TATOOINE_EINSTEIN_NOTATION_CONTRACTED_STATIC_TENSOR_H
8template <
typename... IndexedTensors>
11 common_type<
typename IndexedTensors::tensor_type::value_type...>;
13 template <std::
size_t I>
20 static auto constexpr rank() {
return free_indices::size; }
23 static auto constexpr size() {
24 auto s = std::size_t{};
27 if constexpr (IndexedTensors::template contains<E>()) {
28 s = IndexedTensors::template size<E>();
41 template <std::
size_t I>
45 template <std::
size_t I>
49 constexpr auto num_tensors() {
return sizeof...(IndexedTensors); }
51 template <std::size_t... ContractedIndexSequence,
52 std::size_t... ContractedTensorsSequence>
53 requires free_indices::empty
55 std::index_sequence<ContractedIndexSequence...> ,
56 std::index_sequence<ContractedTensorsSequence...> )
const {
57 using map_t = std::map<std::size_t, std::size_t>;
63 auto const contracted_indices_map = map_t{map_t::value_type{
64 contracted_indices::template at<ContractedIndexSequence>::get(),
65 ContractedIndexSequence,
67 auto const tensor_index_maps = std::tuple{IndexedTensors::index_map()...};
69 std::tuple{std::array<std::size_t, IndexedTensors::rank()>{}...};
76 auto const contracted_index_array =
81 std::get<ContractedTensorsSequence>(index_arrays);
82 auto const& tensor_index_map =
83 std::get<ContractedTensorsSequence>(tensor_index_maps);
84 auto index_arr_it =
begin(index_array);
85 auto tensor_index_map_it =
begin(tensor_index_map);
87 for (; tensor_index_map_it !=
end(tensor_index_map);
88 ++tensor_index_map_it, ++index_arr_it) {
89 if (contracted_indices_map.contains(*tensor_index_map_it)) {
91 contracted_index_array[contracted_indices_map.at(
92 *tensor_index_map_it)];
99 acc += (at<ContractedTensorsSequence>().tensor()(std::get<ContractedTensorsSequence>(index_arrays)) * ...);
101 size<
typename contracted_indices::template
at<
102 ContractedIndexSequence>>()...);
107 if constexpr (free_indices::empty) {
108 return to_scalar(std::make_index_sequence<contracted_indices::size>{},
109 std::make_index_sequence<
sizeof...(IndexedTensors)>{});
typename type_list_at_impl< TypeList, I >::type type_list_at
Access to the Ith element of TypeList.
Definition: type_list.h:56
Definition: added_contracted_dynamic_tensor.h:4
static auto constexpr s
Definition: index.h:23
typename contracted_indices_aux< indexed_tensors_to_index_list< Indices... > >::type contracted_indices
Definition: type_traits.h:90
typename free_indices_aux< indexed_tensors_to_index_list< Indices... > >::type free_indices
Definition: type_traits.h:59
typename common_type_impl< Ts... >::type common_type
Definition: common_type.h:23
auto begin(Range &&range)
Definition: iterator_facade.h:318
auto end(Range &&range)
Definition: iterator_facade.h:322
constexpr auto for_loop(Iteration &&iteration, execution_policy::sequential_t, Ranges(&&... ranges)[2]) -> void
Use this function for creating a sequential nested loop.
Definition: for_loop.h:336
Definition: contracted_static_tensor.h:9
auto at() const
Definition: contracted_static_tensor.h:42
type_list_at< indices_per_tensor, I > indices_of_tensor
Definition: contracted_static_tensor.h:14
tatooine::einstein_notation::free_indices< IndexedTensors... > free_indices
Definition: contracted_static_tensor.h:16
auto at()
Definition: contracted_static_tensor.h:46
static auto constexpr size()
Definition: contracted_static_tensor.h:23
common_type< typename IndexedTensors::tensor_type::value_type... > value_type
Definition: contracted_static_tensor.h:11
contracted_static_tensor(IndexedTensors... tensors)
Definition: contracted_static_tensor.h:39
constexpr auto num_tensors()
Definition: contracted_static_tensor.h:49
std::tuple< IndexedTensors... > m_tensors
Definition: contracted_static_tensor.h:36
::empty auto to_scalar(std::index_sequence< ContractedIndexSequence... >, std::index_sequence< ContractedTensorsSequence... >) const
Definition: contracted_static_tensor.h:54
static auto constexpr rank()
Definition: contracted_static_tensor.h:20
tatooine::einstein_notation::contracted_indices< IndexedTensors... > contracted_indices
Definition: contracted_static_tensor.h:18
An empty struct that holds types.
Definition: type_list.h:248