pRC
multi-purpose Tensor Train library for C++
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
25 template<Index... Ds, class X, class... Is, class R = RemoveReference<X>,
28 If<IsSatisfied<(sizeof...(Is) == sizeof...(Ds))>> = 0,
29 If<True<decltype(chip<Ds...>(
30 makeSeries<Index, typename R::Dimension{}>()))>> = 0>
31 static inline constexpr auto chip(X &&a, Is const... indices)
32 {
33 if constexpr(sizeof...(Ds) == 0)
34 {
35 return view(forward<X>(a));
36 }
37 else if constexpr(sizeof...(Ds) == 1)
38 {
40 constexpr auto D = Sequence<Index, Ds...>::value(0);
41 return TensorViews::Chip<typename R::Type,
42 decltype(chip<D>(typename R::Sizes())), D, V>(
43 view(forward<X>(a)), indices...);
44 }
45 else
46 {
47 return expand(
48 makeRange<Index, 1, sizeof...(Ds)>(),
49 [&a](auto const indices, auto const... seq)
50 {
51 using S = Sequence<Index, Ds...>;
52 return chip<((S::value(seq) < S::value(0))
53 ? S::value(seq)
54 : S::value(seq) - 1)...>(
55 chip<S::value(0)>(a, indices[0]), indices[seq]...);
56 },
57 Indices<sizeof...(Ds)>(indices...));
58 }
59 }
60
75 template<Index... Ds, class X, class... Is, class R = RemoveReference<X>,
77 If<IsInvocable<Chip<Ds...>, X &, Is...>> = 0>
78 static inline constexpr auto chip(X &&a, Is const... indices)
79 {
80 return eval(chip<Ds...>(a, indices...));
81 }
82}
83#endif // pRC_CORE_TENSOR_FUNCTIONS_CHIP_H
Definition indices.hpp:15
Definition sequence.hpp:34
static constexpr auto value(Index const index)
Definition sequence.hpp:39
Definition chip.hpp:17
Definition cholesky.hpp:18
static constexpr X eval(X &&a)
Definition eval.hpp:11
static constexpr X view(X &&a)
Returns a TensorView obtained from a TensorView.
Definition view.hpp:22
std::enable_if_t< B{}, int > If
Definition type_traits.hpp:68
std::is_invocable< F, Args... > IsInvocable
Definition type_traits.hpp:134
static constexpr auto makeRange()
Definition sequence.hpp:389
static constexpr auto makeSeries()
Definition sequence.hpp:361
Constant< Bool, B > IsSatisfied
Definition type_traits.hpp:71
static constexpr Conditional< IsSatisfied< C >, RemoveConstReference< X >, X > copy(X &&a)
Definition copy.hpp:13
static constexpr auto chip(Sequence< T, Is... > const)
Definition sequence.hpp:561
static constexpr decltype(auto) expand(Sequence< T, Seq... > const, F &&f, Xs &&...args)
forwards the values in a pRC::Sequence to a function as parameters
Definition sequence.hpp:354
Size Index
Definition type_traits.hpp:21