cMHN
1.2
C++ library for learning MHNs with pRC
Loading...
Searching...
No Matches
pRC
prc
core
tensor
views
chip.hpp
Go to the documentation of this file.
1
// SPDX-License-Identifier: BSD-2-Clause
2
3
#ifndef pRC_CORE_TENSOR_VIEWS_CHIP_H
4
#define pRC_CORE_TENSOR_VIEWS_CHIP_H
5
6
#include <
prc/core/basic/sequence.hpp
>
7
#include <
prc/core/functors/subscript.hpp
>
8
#include <
prc/core/log/log.hpp
>
9
#include <
prc/core/tensor/declarations.hpp
>
10
11
namespace
pRC::TensorViews
12
{
13
template
<
class
T,
class
N, Index D,
class
V>
14
requires
IsTensorView<V>
15
class
Chip
16
:
public
Conditional
<IsAssignable<V>,
17
Assignable<T, N, Chip<T, N, D, V>>, View<T, N, Chip<T, N, D, V>>>
18
{
19
private
:
20
using
Base
=
Conditional<IsAssignable<V>
,
Assignable<T, N, Chip>
,
21
View<T, N, Chip>
>;
22
23
public
:
24
template
<
class
X>
25
requires
IsSame<V, RemoveReference<X>
>
26
Chip
(X &&a,
Index
const
index)
27
: mA(forward<X>(a))
28
, mIndex(index)
29
{
30
if
constexpr
(
cDebugLevel
>=
DebugLevel::Low
)
31
{
32
if
(!(mIndex < V::size(
D
)))
33
{
34
Logging::error
(
"Chip index out of range."
);
35
}
36
}
37
}
38
39
using
Base::operator=;
40
41
template
<IsConvertible<Index>... Is>
42
requires
(
sizeof
...(Is) == Base::Dimension)
43
constexpr
decltype
(
auto
)
operator
()(Is
const
... indices)
44
{
45
return
this->call(indices...);
46
}
47
48
template
<IsConvertible<Index>... Is>
49
requires
(
sizeof
...(Is) == Base::Dimension)
50
constexpr
decltype
(
auto
)
operator
()(Is
const
... indices)
const
51
{
52
return
this->call(indices...);
53
}
54
55
constexpr
decltype
(
auto
)
operator
()(
56
typename
Base::Subscripts
const
&subscripts)
57
{
58
return
operator()
(subscripts,
makeRange<Index, 0, D>
(),
59
makeRange<Index, D, Base::Dimension>
());
60
}
61
62
constexpr
decltype
(
auto
)
operator
()(
63
typename
Base::Subscripts
const
&subscripts)
const
64
{
65
return
operator()
(subscripts,
makeRange<Index, 0, D>
(),
66
makeRange<Index, D, Base::Dimension>
());
67
}
68
69
constexpr
decltype
(
auto
)
operator
[](
Index
const
index)
70
requires
IsSubscriptable<V>
&& (
D
== 0 ||
D
== Base::Dimension)
71
{
72
if
constexpr
(
D
== 0)
73
{
74
return
mA[V::size(0) * index + mIndex];
75
}
76
else
77
{
78
return
mA[Base::size() * mIndex + index];
79
}
80
}
81
82
constexpr
decltype
(
auto
)
operator
[](
Index
const
index)
const
83
requires
IsSubscriptable<V>
&& (
D
== 0 ||
D
== Base::Dimension)
84
{
85
if
constexpr
(
D
== 0)
86
{
87
return
mA[V::size(0) * index + mIndex];
88
}
89
else
90
{
91
return
mA[Base::size() * mIndex + index];
92
}
93
}
94
95
private
:
96
template
<
Index
... Ss,
Index
... Es>
97
constexpr
decltype
(
auto
)
operator
()(
98
typename
Base::Subscripts
const
&subscripts,
99
Sequence
<
Index
, Ss...>
const
,
Sequence
<
Index
, Es...>
const
)
100
{
101
return
mA(subscripts[Ss]..., mIndex, subscripts[Es]...);
102
}
103
104
template
<
Index
... Ss,
Index
... Es>
105
constexpr
decltype
(
auto
)
operator
()(
106
typename
Base::Subscripts
const
&subscripts,
107
Sequence
<
Index
, Ss...>
const
,
Sequence
<
Index
, Es...>
const
)
const
108
{
109
return
mA(subscripts[Ss]..., mIndex, subscripts[Es]...);
110
}
111
112
private
:
113
V mA;
114
Index
const
mIndex;
115
};
116
}
117
#endif
// pRC_CORE_TENSOR_VIEWS_CHIP_H
D
pRC::Size const D
Definition
CalculatePThetaTests.cpp:9
Base
Definition
gtest_unittest.cc:5120
pRC::Sequence
Definition
sequence.hpp:29
pRC::TensorViews::Assignable
Definition
assignable.hpp:21
pRC::TensorViews::Chip
Definition
chip.hpp:18
pRC::TensorViews::Chip::Chip
Chip(X &&a, Index const index)
Definition
chip.hpp:26
pRC::TensorViews::Chip::operator()
constexpr decltype(auto) operator()(Is const ... indices)
Definition
chip.hpp:43
pRC::TensorViews::View
Definition
declarations.hpp:20
pRC::IsSame
Definition
concepts.hpp:28
pRC::IsSubscriptable
Definition
subscript.hpp:21
declarations.hpp
log.hpp
pRC::Logging::error
static void error(Xs &&...args)
Definition
log.hpp:14
pRC::TensorViews
Definition
declarations.hpp:18
pRC::DebugLevel::Low
@ Low
pRC::Index
Size Index
Definition
basics.hpp:32
pRC::makeRange
static constexpr auto makeRange()
Definition
sequence.hpp:421
pRC::cDebugLevel
constexpr auto cDebugLevel
Definition
config.hpp:48
pRC::Conditional
std::conditional_t< B, T, F > Conditional
Definition
basics.hpp:56
sequence.hpp
subscript.hpp
Generated by
1.11.0