pRC
multi-purpose Tensor Train library for C++
Loading...
Searching...
No Matches
kronecker_product.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-2-Clause
2
3#ifndef pRC_CORE_TENSOR_FUNCTIONS_KRONECKER_PRODUCT_H
4#define pRC_CORE_TENSOR_FUNCTIONS_KRONECKER_PRODUCT_H
5
11
12namespace pRC
13{
27 template<class XA, class XB, class RA = RemoveReference<XA>,
28 class RB = RemoveReference<XB>, If<IsTensorish<RA>> = 0,
29 If<IsInvocable<View, XA>> = 0, If<IsTensorish<RB>> = 0,
30 If<IsInvocable<View, XB>> = 0,
31 If<IsSame<typename RA::Dimension, typename RB::Dimension>> = 0,
32 class EA = ResultOf<XA, typename RA::Subscripts>,
33 class EB = ResultOf<XB, typename RB::Subscripts>,
34 If<IsInvocable<Mul, EA, EB>> = 0>
35 static inline constexpr auto kroneckerProduct(XA &&a, XB &&b)
36 {
37 return expand(makeSeries<Index, typename RA::Dimension{}>(),
38 [&a, &b](auto const... seq)
39 {
40 return hadamardProduct(
41 inflate<RB::size(seq)...>(forward<XA>(a)),
42 broadcast<RA::size(seq)...>(forward<XB>(b)));
43 });
44 }
45
62 template<class XA, class XB, class RA = RemoveReference<XA>,
63 class RB = RemoveReference<XB>, If<IsTensorish<RA>> = 0,
64 If<IsTensorish<RB>> = 0,
65 If<Not<All<IsInvocable<View, XA>, IsInvocable<View, XB>>>> = 0,
66 If<IsInvocable<KroneckerProduct, XA &, XB &>> = 0>
67 static inline constexpr auto kroneckerProduct(XA &&a, XB &&b)
68 {
69 return eval(kroneckerProduct(a, b));
70 }
71}
72#endif // pRC_CORE_TENSOR_FUNCTIONS_KRONECKER_PRODUCT_H
Definition cholesky.hpp:18
static constexpr X eval(X &&a)
Definition eval.hpp:11
static constexpr auto inflate(X &&a)
Inflates the sizes of a Tensor by repeating its values.
Definition inflate.hpp:26
static constexpr auto hadamardProduct(XA &&a, XB &&b)
Calculates the Hadamard product of two Tensors.
Definition hadamard_product.hpp:28
static constexpr auto broadcast(X &&a)
Broadcasts a Tensor into one whose mode sizes are a multiple of the mode sizes of the original Tensor...
Definition broadcast.hpp:30
static constexpr auto kroneckerProduct(XA &&a, XB &&b)
Calculates the Kronecker product of two Tensors.
Definition kronecker_product.hpp:35
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 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