cMHN 1.1
C++ library for learning MHNs with pRC
Loading...
Searching...
No Matches
norm.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_TENSOR_TRAIN_COMMON_FUNCTIONS_NORM_H
4#define pRC_TENSOR_TRAIN_COMMON_FUNCTIONS_NORM_H
5
12
13namespace pRC
14{
15 template<Index P = 2, Index Q = P, class X, class R = RemoveReference<X>,
16 If<Any<TensorTrain::IsTensorish<R>, TensorTrain::IsOperatorish<R>>> = 0,
17 If<IsSatisfied<(P == 2 && Q == 2)>> = 0>
18 static inline constexpr auto norm(X &&a)
19 {
21
22 return exp(expand(
24 [&a](auto const... seq)
25 {
26 return RecursiveLambda(
27 []<class XA, class XB>(auto const &self, XA &&a, XB &&b,
28 auto &&...cores) -> T
29 {
30 auto const [nrm, q, r] =
31 orthogonalize<Position::Left>(forward<XA>(a));
32
33 if(nrm <= identity<T>(
35 {
36 return zero();
37 }
38
39 Tensor const next = contract<1, 0>(r, forward<XB>(b));
40
41 if constexpr(sizeof...(cores) == 0)
42 {
43 return log(nrm) + log(norm(next));
44 }
45 else
46 {
47 return log(nrm) +
48 self(next, forward<decltype(cores)>(cores)...);
49 }
50 })(forward<X>(a).template core<seq>()...);
51 }));
52 }
53}
54#endif // pRC_TENSOR_TRAIN_COMMON_FUNCTIONS_NORM_H
Definition tensor.hpp:28
Definition cholesky.hpp:18
static constexpr auto makeConstantSequence()
Definition sequence.hpp:402
Size Index
Definition type_traits.hpp:21
static constexpr auto exp(Complex< T > const &a)
Definition exp.hpp:12
std::remove_reference_t< T > RemoveReference
Definition type_traits.hpp:56
static constexpr auto zero()
Definition zero.hpp:12
RecursiveLambda(X &&) -> RecursiveLambda< RemoveReference< X > >
static constexpr auto makeSeries()
Definition sequence.hpp:351
static constexpr auto log(Complex< T > const &a)
Definition log.hpp:11
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)
Definition sequence.hpp:344
Definition limits.hpp:13