Loading [MathJax]/extensions/tex2jax.js
Tatooine
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages Concepts
tensor_slice.h
Go to the documentation of this file.
1#ifndef TATOOINE_TENSOR_SLICE_H
2#define TATOOINE_TENSOR_SLICE_H
3//==============================================================================
6//==============================================================================
7namespace tatooine {
8//==============================================================================
9template <typename Tensor, arithmetic_or_complex ValueType, std::size_t FixedDim,
10 std::size_t... Dims>
12 : base_tensor<tensor_slice<Tensor, ValueType, FixedDim, Dims...>, ValueType,
13 Dims...> {
15 using this_type = tensor_slice<Tensor, ValueType, FixedDim, Dims...>;
16 using parent_type = base_tensor<this_type, ValueType, Dims...>;
17 using typename parent_type::value_type;
18
19 using parent_type::operator=;
20 //template <static_tensor Other>
21 //requires (same_dimensions<this_type, Other>()) &&
22 // (convertible_to<value_type<std::decay_t<Other>>, value_type>)
23 //auto operator=(Other&& other) -> tensor_slice& {
24 // parent_type::operator=(std::forward<Other>(other));
25 // return *this;
26 //}
27
30
31 //============================================================================
32 private:
34 std::size_t m_fixed_index;
35
36 //============================================================================
37 public:
38 constexpr tensor_slice(Tensor* tensor, std::size_t fixed_index)
39 : m_tensor{tensor}, m_fixed_index{fixed_index} {}
40
41 //----------------------------------------------------------------------------
42 constexpr auto at(integral auto const... is) const -> decltype(auto) {
43 if constexpr (FixedDim == 0) {
44 return m_tensor->at(m_fixed_index, is...);
45
46 } else if constexpr (FixedDim == rank()) {
47 return m_tensor->at(is..., m_fixed_index);
48
49 } else {
50 auto at_ = [this](const auto... is) -> decltype(auto) {
51 return m_tensor->at(is...);
52 };
53 return invoke_unpacked(at_,
54 unpack(variadic::extract<0, FixedDim>(
55 static_cast<std::size_t>(is)...)),
57 unpack(variadic::extract<FixedDim, rank()>(
58 static_cast<std::size_t>(is)...)));
59 };
60 }
61 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
62 constexpr auto at(integral auto const... is)
63 -> decltype(auto)
64 requires is_non_const<Tensor> {
65 if constexpr (FixedDim == 0) {
66 return m_tensor->at(m_fixed_index, is...);
67
68 } else if constexpr (FixedDim == rank()) {
69 return m_tensor->at(is..., m_fixed_index);
70
71 } else {
72 auto at_ = [this](const auto... is) -> decltype(auto) {
73 return m_tensor->at(is...);
74 };
75 return invoke_unpacked(at_,
76 unpack(variadic::extract<0, FixedDim>(
77 static_cast<std::size_t>(is)...)),
79 unpack(variadic::extract<FixedDim, rank()>(
80 static_cast<std::size_t>(is)...)));
81 };
82 }
83};
84//==============================================================================
85} // namespace tatooine
86//==============================================================================
87#endif
Definition: concepts.h:21
constexpr auto extract(T &&t, Ts &&... ts)
Extracts variadic data into an array in the Range of Begin and End.
Definition: variadic_helpers.h:172
Definition: algorithm.h:6
tensor< real_number, Dimensions... > Tensor
Definition: tensor.h:184
constexpr decltype(auto) invoke_unpacked(F &&f)
All arguments are bound -> just call f.
Definition: invoke_unpacked.h:15
Definition: base_tensor.h:23
static auto constexpr rank()
Definition: base_tensor.h:41
ValueType value_type
Definition: base_tensor.h:24
static auto constexpr num_components()
Definition: base_tensor.h:43
Definition: tensor_slice.h:13
static auto constexpr rank()
Definition: base_tensor.h:41
constexpr auto at(integral auto const ... is) const -> decltype(auto)
Definition: tensor_slice.h:42
Tensor * m_tensor
Definition: tensor_slice.h:33
std::size_t m_fixed_index
Definition: tensor_slice.h:34
constexpr auto at(integral auto const ... is) -> decltype(auto)
Definition: tensor_slice.h:62
constexpr tensor_slice(Tensor *tensor, std::size_t fixed_index)
Definition: tensor_slice.h:38
tensor_slice< Tensor, ValueType, FixedDim, Dims... > this_type
Definition: tensor_slice.h:15
auto constexpr at(integral auto const ... is) -> decltype(auto)
Definition: tensor.h:38
Definition: invoke_unpacked.h:11