pRC
multi-purpose Tensor Train library for C++
Loading...
Searching...
No Matches
orthogonalize.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_TENSOR_TRAIN_ALGORITHMS_ORTHOGONALIZE_H
4#define pRC_TENSOR_TRAIN_ALGORITHMS_ORTHOGONALIZE_H
5
12
13namespace pRC
14{
15 template<Position P, class X, class R = RemoveReference<X>,
16 If<IsTensorish<R>> = 0, If<IsFloat<typename R::Value>> = 0,
17 If<IsSatisfied<(P == Position::Left || P == Position::Right)>> = 0>
18 static inline constexpr auto orthogonalize(X &&a)
19 {
20 if constexpr(P == Position::Left)
21 {
22 return expand(makeSeries<Index, typename R::Dimension() - 1>(),
23 [&](auto const... seq)
24 {
25 auto const [q, r] = qr(folding<P>(forward<X>(a)));
26 Tensor const lambda = norm(r);
27
28 return tuple(lambda,
29 eval(reshape<R::size(seq)...,
30 RemoveReference<decltype(q)>::size(1)>(q)),
31 eval(r / lambda));
32 });
33 }
34 else
35 {
36 return expand(makeRange<Index, 1, typename R::Dimension{}>(),
37 [&](auto const... seq)
38 {
39 auto const [l, q] = lq(folding<P>(forward<X>(a)));
40 Tensor const lambda = norm(l);
41
42 return tuple(lambda, eval(l / lambda),
43 eval(reshape<RemoveReference<decltype(q)>::size(0),
44 R::size(seq)...>(q)));
45 });
46 }
47 }
48}
49#endif // pRC_TENSOR_TRAIN_ALGORITHMS_ORTHOGONALIZE_H
Class storing tensors.
Definition tensor.hpp:44
Definition cholesky.hpp:18
static constexpr X eval(X &&a)
Definition eval.hpp:11
static constexpr auto orthogonalize(X &&a)
Definition orthogonalize.hpp:18
std::remove_reference_t< T > RemoveReference
Definition type_traits.hpp:56
static constexpr auto lq(X &&input)
Definition lq.hpp:15
static constexpr auto qr(X &&input)
Definition qr.hpp:24
static constexpr auto makeRange()
Definition sequence.hpp:389
static constexpr auto makeSeries()
Definition sequence.hpp:361
static constexpr Conditional< IsSatisfied< C >, RemoveConstReference< X >, X > copy(X &&a)
Definition copy.hpp:13
static constexpr auto reshape(X &&a)
Reshapes a Tensor.
Definition reshape.hpp:29
static constexpr auto norm(Complex< T > const &a)
Definition norm.hpp:11
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