cMHN 1.1
C++ library for learning MHNs with pRC
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{
14 template<class XA, class XB, class RA = RemoveReference<XA>,
15 class RB = RemoveReference<XB>, If<IsTensorish<RA>> = 0,
16 If<IsInvocable<View, XA>> = 0, If<IsTensorish<RB>> = 0,
17 If<IsInvocable<View, XB>> = 0,
18 If<IsSame<typename RA::Dimension, typename RB::Dimension>> = 0,
19 class EA = ResultOf<XA, typename RA::Subscripts>,
20 class EB = ResultOf<XB, typename RB::Subscripts>,
21 If<IsInvocable<Mul, EA, EB>> = 0>
22 static inline constexpr auto kroneckerProduct(XA &&a, XB &&b)
23 {
24 return expand(makeSeries<Index, typename RA::Dimension{}>(),
25 [&a, &b](auto const... seq)
26 {
27 return hadamardProduct(
28 inflate<RB::size(seq)...>(forward<XA>(a)),
29 broadcast<RA::size(seq)...>(forward<XB>(b)));
30 });
31 }
32
33 template<class XA, class XB, class RA = RemoveReference<XA>,
34 class RB = RemoveReference<XB>, If<IsTensorish<RA>> = 0,
35 If<IsTensorish<RB>> = 0,
36 If<Not<All<IsInvocable<View, XA>, IsInvocable<View, XB>>>> = 0,
37 If<IsInvocable<KroneckerProduct, XA &, XB &>> = 0>
38 static inline constexpr auto kroneckerProduct(XA &&a, XB &&b)
39 {
40 return eval(kroneckerProduct(a, b));
41 }
42}
43#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 makeConstantSequence()
Definition sequence.hpp:402
Size Index
Definition type_traits.hpp:21
static constexpr auto inflate(X &&a)
Definition inflate.hpp:17
static constexpr auto hadamardProduct(XA &&a, XB &&b)
Definition hadamard_product.hpp:15
static constexpr auto broadcast(X &&a)
Definition broadcast.hpp:17
static constexpr auto kroneckerProduct(XA &&a, XB &&b)
Definition kronecker_product.hpp:22
static constexpr auto makeSeries()
Definition sequence.hpp:351
static constexpr decltype(auto) expand(Sequence< T, Seq... > const, F &&f, Xs &&...args)
Definition sequence.hpp:344