cMHN 1.1
C++ library for learning MHNs with pRC
Loading...
Searching...
No Matches
chip.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_CORE_TENSOR_FUNCTIONS_CHIP_H
4#define pRC_CORE_TENSOR_FUNCTIONS_CHIP_H
5
8
9namespace pRC
10{
11 template<Index... Ds>
12 struct Chip;
13
14 template<Index... Ds, class X, class... Is, class R = RemoveReference<X>,
17 If<IsSatisfied<(sizeof...(Is) == sizeof...(Ds))>> = 0,
18 If<True<decltype(chip<Ds...>(
19 makeSeries<Index, typename R::Dimension{}>()))>> = 0>
20 static inline constexpr auto chip(X &&a, Is const... indices)
21 {
22 if constexpr(sizeof...(Ds) == 0)
23 {
24 return view(forward<X>(a));
25 }
26 else if constexpr(sizeof...(Ds) == 1)
27 {
29 constexpr auto D = Sequence<Index, Ds...>::value(0);
30 return TensorViews::Chip<typename R::Type,
31 decltype(chip<D>(typename R::Sizes())), D, V>(
32 view(forward<X>(a)), indices...);
33 }
34 else
35 {
36 return expand(
37 makeRange<Index, 1, sizeof...(Ds)>(),
38 [&a](auto const indices, auto const... seq)
39 {
40 using S = Sequence<Index, Ds...>;
41 return chip<((S::value(seq) < S::value(0))
42 ? S::value(seq)
43 : S::value(seq) - 1)...>(
44 chip<S::value(0)>(a, indices[0]), indices[seq]...);
45 },
46 Indices<sizeof...(Ds)>(indices...));
47 }
48 }
49
50 template<Index... Ds, class X, class... Is, class R = RemoveReference<X>,
52 If<IsInvocable<Chip<Ds...>, X &, Is...>> = 0>
53 static inline constexpr auto chip(X &&a, Is const... indices)
54 {
55 return eval(chip<Ds...>(a, indices...));
56 }
57}
58#endif // pRC_CORE_TENSOR_FUNCTIONS_CHIP_H
pRC::Size const D
Definition CalculatePThetaTests.cpp:9
Definition indices.hpp:15
Definition sequence.hpp:34
static constexpr auto value(Index const index)
Definition sequence.hpp:39
Definition chip.hpp:17
TN::Subscripts S
Definition externs_nonTT.hpp:9
Definition cholesky.hpp:18
static constexpr X eval(X &&a)
Definition eval.hpp:11
static constexpr auto makeConstantSequence()
Definition sequence.hpp:402
Size Index
Definition type_traits.hpp:21
static constexpr X view(X &&a)
Definition view.hpp:12
std::enable_if_t< B{}, int > If
Definition type_traits.hpp:68
Constant< Bool, B > IsSatisfied
Definition type_traits.hpp:71
static constexpr auto makeRange()
Definition sequence.hpp:379
static constexpr auto makeSeries()
Definition sequence.hpp:351
static constexpr auto chip(Sequence< T, Is... > const)
Definition sequence.hpp:551
static constexpr decltype(auto) expand(Sequence< T, Seq... > const, F &&f, Xs &&...args)
Definition sequence.hpp:344
std::is_invocable< F, Args... > IsInvocable
Definition type_traits.hpp:134