cMHN 1.2
C++ library for learning MHNs with pRC
Loading...
Searching...
No Matches
stride.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_CORE_TENSOR_VIEWS_STRIDE_H
4#define pRC_CORE_TENSOR_VIEWS_STRIDE_H
5
10
11namespace pRC::TensorViews
12{
13 template<class T, class N, class S, class V>
14 class Stride;
15
16 template<class T, class N, Size... Ss, class V>
17 requires IsTensorView<V>
18 class Stride<T, N, Sizes<Ss...>, V>
19 : public Conditional<IsAssignable<V>,
20 Assignable<T, N, Stride<T, N, Sizes<Ss...>, V>>,
21 View<T, N, Stride<T, N, Sizes<Ss...>, V>>>
22 {
23 private:
26
27 public:
28 template<class X>
30 Stride(X &&a, Subscripts<Ss...> const &offsets)
31 : mA(forward<X>(a))
32 , mOffsets(offsets)
33 {
34 if constexpr(cDebugLevel >= DebugLevel::Low)
35 {
36 if(mOffsets.isOutOfRange())
37 {
38 Logging::error("Stride offset indices out of range.");
39 }
40 }
41 }
42
43 using Base::operator=;
44
45 template<IsConvertible<Index>... Is>
46 requires(sizeof...(Is) == Base::Dimension)
47 constexpr decltype(auto) operator()(Is const... indices)
48 {
49 return this->call(indices...);
50 }
51
52 template<IsConvertible<Index>... Is>
53 requires(sizeof...(Is) == Base::Dimension)
54 constexpr decltype(auto) operator()(Is const... indices) const
55 {
56 return this->call(indices...);
57 }
58
59 constexpr decltype(auto) operator()(
60 typename Base::Subscripts const &subscripts)
61 {
63 [this, &subscripts](auto const... seq) -> decltype(auto)
64 {
65 return mA((subscripts[seq] * Ss + mOffsets[seq])...);
66 });
67 }
68
69 constexpr decltype(auto) operator()(
70 typename Base::Subscripts const &subscripts) const
71 {
73 [this, &subscripts](auto const... seq) -> decltype(auto)
74 {
75 return mA((subscripts[seq] * Ss + mOffsets[seq])...);
76 });
77 }
78
79 constexpr decltype(auto) operator[](Index const index) = delete;
80 constexpr decltype(auto) operator[](Index const index) const = delete;
81
82 private:
83 V mA;
84 Subscripts<Ss...> const mOffsets;
85 };
86}
87#endif // pRC_CORE_TENSOR_VIEWS_STRIDE_H
Definition gtest_unittest.cc:5120
Definition value.hpp:12
Definition sequence.hpp:29
Definition subscripts.hpp:21
Definition assignable.hpp:21
Stride(X &&a, Subscripts< Ss... > const &offsets)
Definition stride.hpp:30
Definition stride.hpp:14
Definition declarations.hpp:20
Definition concepts.hpp:28
Definition declarations.hpp:36
pRC::Float<> T
Definition externs_nonTT.hpp:1
static void error(Xs &&...args)
Definition log.hpp:14
Definition declarations.hpp:18
Size Index
Definition basics.hpp:32
std::size_t Size
Definition basics.hpp:31
static constexpr auto makeSeries()
Definition sequence.hpp:390
constexpr auto cDebugLevel
Definition config.hpp:48
std::conditional_t< B, T, F > Conditional
Definition basics.hpp:56
static constexpr decltype(auto) expand(Sequence< T, Seq... > const, F &&f, Xs &&...args)
Definition sequence.hpp:383