77 template<
typename MatrixType>
78 using isVector =
typename std::conditional<MatrixType::ColsAtCompileTime == 1, std::true_type, std::false_type>::type;
83 template<
typename MatrixType>
84 using isMatrix =
typename std::conditional<MatrixType::ColsAtCompileTime != 1, std::true_type, std::false_type>::type;
97 template<
typename... Args>
98 static typename std::tuple_element<N, std::tuple<Args...>>::type
get(Args &&... args)
99 {
return std::get<N>(std::forward_as_tuple(args...)); }
108 template<
typename... Args>
149 template<
typename T,
typename... Args>
167 template<
typename MatrixType,
bool Cache>
179 template<
typename MatrixType>
186 const MatrixType &
cache(
const T & M)
188 using ConstType = decltype(std::declval<Eigen::Ref<const Eigen::MatrixXd>>() * Eigen::VectorXd::Constant(1, 1));
189 if constexpr(std::is_same_v<const T, ConstType>)
196 cache_ = M.lhs().rowwise().sum();
197 cache_ *= M.rhs().functor().m_other;
201 cache_.noalias() = M;
206 MatrixType &
cache() {
return cache_; }
207 const MatrixType &
cache()
const {
return cache_; }
216 template<
typename MatrixType, AssignType A, WeightMult W, MatrixMult M, Source F>
223 template<
typename MatrixType, WeightMult W>
226 template<
typename MatrixType, WeightMult W>
233 template<
typename MatrixType, AssignType A, WeightMult W>
240 template<
typename MatrixType, AssignType A, WeightMult W, MatrixMult M, Source F>
248 template<
typename MatrixType, AssignType A>
251 template<
typename MatrixType, AssignType A>
256 template<AssignType A>
264 template<
typename T,
typename U>
266 { out.noalias() = in; }
270 { out.setConstant(in); }
277 template<
typename T,
typename U>
279 { out.noalias() += in; }
283 { out.array() += in; }
290 template<
typename T,
typename U>
292 { out.noalias() -= in; }
296 { out.array() -= in; }
303 template<
typename T,
typename U>
305 { out.array() = out.array().min(in.array()); }
309 { out.array() = out.array().min(in); }
316 template<
typename T,
typename U>
318 { out.array() = out.array().max(in.array()); }
322 { out.array() = out.array().max(in); }
326 template<WeightMult W>
335 static const bool useArg =
false;
349 static const bool useArg =
false;
355 template<
typename Derived>
356 decltype(-std::declval<Eigen::MatrixBase<Derived>>()) applyWeightMult(const
Eigen::MatrixBase<Derived> & M)
360 #if EIGEN_VERSION_AT_LEAST(3, 2, 90)
361 template<
typename Lhs,
typename Rhs,
int Option>
362 decltype(-(std::declval<Lhs>().lazyProduct(std::declval<Rhs>()))) applyWeightMult(
363 const
Eigen::Product<Lhs, Rhs, Option> &
P)
364 {
return -(
P.lhs().lazyProduct(
P.rhs())); }
366 template<
typename Derived,
typename Lhs,
typename Rhs>
367 decltype((-std::declval<Lhs>())
368 * std::declval<Rhs>()) applyWeightMult(const
Eigen::ProductBase<Derived, Lhs, Rhs> &
P)
369 {
return (-
P.lhs()) *
P.rhs(); }
381 decltype(
double() * std::declval<T>()) applyWeightMult(const T & M)
384 #if EIGEN_VERSION_AT_LEAST(3, 2, 90)
385 template<
typename Lhs,
typename Rhs,
int Option>
386 decltype(
double() * (std::declval<Lhs>().lazyProduct(std::declval<Rhs>()))) applyWeightMult(
387 const
Eigen::Product<Lhs, Rhs, Option> &
P)
388 {
return s_ * (
P.lhs().lazyProduct(
P.rhs())); }
403 using ReturnType = decltype(std::declval<Eigen::Ref<const Eigen::VectorXd>>().asDiagonal() * std::declval<T>());
406 {
return d_.asDiagonal() * M; }
409 decltype(
double() * std::declval<Eigen::Ref<const Eigen::VectorXd>>()) applyWeightMult(const
double & d)
413 Eigen::Ref<const Eigen::VectorXd> d_;
417 template<
typename MatrixType, MatrixMult M>
422 template<
typename MatrixType>
434 template<
typename MatrixType>
442 using PreType = decltype(std::declval<Eigen::Ref<const Eigen::MatrixXd>>() * std::declval<T>());
445 using PostType = decltype(std::declval<T>() * std::declval<Eigen::Ref<const Eigen::MatrixXd>>());
447 using ConstType = decltype(std::declval<Eigen::Ref<const Eigen::MatrixXd>>() * Eigen::VectorXd::Constant(1, 1));
457 template<
typename U = MatrixType>
459 {
return M_ * Eigen::VectorXd::Constant(M_.cols(), d); }
465 const auto p = applyMatrixMult(M);
466 using ConstType = decltype(std::declval<Eigen::Ref<const Eigen::MatrixXd>>() * Eigen::VectorXd::Constant(1, 1));
467 if constexpr(std::is_same_v<decltype(p),
ConstType>)
474 cache = p.lhs().rowwise().sum();
475 cache *= p.rhs().functor().m_other;
484 Eigen::Ref<const Eigen::MatrixXd> M_;
488 template<
typename MatrixType>
496 decltype(std::declval<Eigen::Ref<const Eigen::MatrixXd>>().diagonal().cwiseInverse().asDiagonal());
499 using PreType = decltype(std::declval<InvDiagType>() * std::declval<T>());
502 using PostType = decltype(std::declval<T>() * std::declval<InvDiagType>());
504 using ConstType = decltype(std::declval<InvDiagType>() * Eigen::VectorXd::Constant(1, 1));
508 {
return M_.diagonal().cwiseInverse().asDiagonal() * M; }
512 {
return M * M_.diagonal().cwiseInverse().asDiagonal(); }
514 template<
typename U = MatrixType>
516 {
return M_.diagonal().cwiseInverse().asDiagonal() * Eigen::VectorXd::Constant(M_.cols(), d); }
521 { cache.noalias() = applyMatrixMult(M); }
524 Eigen::Ref<const Eigen::MatrixXd> M_;
528 template<
typename MatrixType>
532 MatrixMultBase(
void (*mult)(Eigen::Ref<MatrixType> out,
const Eigen::Ref<const MatrixType> & in)) : mult_(mult) {}
539 void (*mult_)(Eigen::Ref<MatrixType> out,
const Eigen::Ref<const MatrixType> & in);
543 template<
typename MatrixType, Source F>
547 using SourceType =
typename std::conditional<F == CONSTANT, double, Eigen::Ref<const MatrixType>>::type;
565 template<
typename MatrixType>
590 template<
typename MatrixType, AssignType A, WeightMult W, MatrixMult M, Source F = EXTERNAL>
592 use_assign_cache<MatrixType, A, W, M, F>::value
593 || use_product_cache<MatrixType, A, W, M, F>::value>,
608 using WParse =
typename std::
610 using MParse =
typename std::
622 template<
typename... Args>
624 :
CBase(
to),
WBase(WParse::get(std::forward<Args>(args)...)),
MBase(MParse::get(std::forward<Args>(args)...)),
625 SBase(SParse::get(std::forward<Args>(args)...)), to_(
to)
629 template<
typename U = MatrixType>
630 typename std::enable_if<!use_product_cache<U, A, W, M, F>::value>::type
run()
635 this->assign(to_, this->
cache(this->applyWeightMult(this->applyMatrixMult(this->
from()))));
638 template<
typename U = MatrixType>
641 this->applyMatrixMultCached(this->
cache(), this->
from());
642 this->assign(to_, this->applyWeightMult(this->
cache()));
645 template<
typename U = MatrixType>
648 this->applyMatrixMultCached(this->
cache(), this->
from());
649 this->
cache() = this->applyWeightMult(this->
cache());
650 this->assign(to_, this->
cache());
653 void to(
const Eigen::Ref<MatrixType> &
to)
657 new(&to_) Eigen::Ref<MatrixType>(
to);
663 Eigen::Ref<MatrixType> to_;
665 template<
typename MatrixType_>
670 template<
typename MatrixType, AssignType A, WeightMult W, MatrixMult M>
681 void from(
const Eigen::Ref<const MatrixType> &) { }
682 void to(
const Eigen::Ref<MatrixType> &
to)
686 new(&to_) Eigen::Ref<MatrixType>(
to);
690 Eigen::Ref<MatrixType> to_;
692 template<
typename MatrixType_>
697 template<
typename MatrixType, WeightMult W, MatrixMult M>
707 void run() { to_.setZero(); }
708 void from(
const Eigen::Ref<const MatrixType> &) { }
709 void to(
const Eigen::Ref<MatrixType> &
to)
713 new(&to_) Eigen::Ref<MatrixType>(
to);
717 Eigen::Ref<MatrixType> to_;
719 template<
typename MatrixType_>
724 template<
typename MatrixType, WeightMult W, MatrixMult M>
734 void run() { to_.array() = to_.array().min(
static_cast<typename MatrixType::Scalar
>(0)); }
735 void from(
const Eigen::Ref<const MatrixType> &) { }
736 void to(
const Eigen::Ref<MatrixType> &
to) {
new(&to_) Eigen::Ref<MatrixType>(
to); }
739 Eigen::Ref<MatrixType> to_;
741 template<
typename MatrixType_>
746 template<
typename MatrixType, WeightMult W, MatrixMult M>
756 void run() { to_.array() = to_.array().max(
static_cast<typename MatrixType::Scalar
>(0)); }
757 void from(
const Eigen::Ref<const MatrixType> &) { }
758 void to(
const Eigen::Ref<MatrixType> &
to) {
new(&to_) Eigen::Ref<MatrixType>(
to); }
761 Eigen::Ref<MatrixType> to_;
763 template<
typename MatrixType_>
Definition: CompiledAssignment.h:151
static constexpr int count
Definition: CompiledAssignment.h:153
void assign(U &out, const T &in)
Definition: CompiledAssignment.h:278
void assign(U &out, double in)
Definition: CompiledAssignment.h:282
void assign(U &out, const T &in)
Definition: CompiledAssignment.h:265
void assign(U &out, double in)
Definition: CompiledAssignment.h:269
void assign(U &out, const T &in)
Definition: CompiledAssignment.h:317
void assign(U &out, double in)
Definition: CompiledAssignment.h:321
void assign(U &out, double in)
Definition: CompiledAssignment.h:308
void assign(U &out, const T &in)
Definition: CompiledAssignment.h:304
void assign(U &out, const T &in)
Definition: CompiledAssignment.h:291
void assign(U &out, double in)
Definition: CompiledAssignment.h:295
Definition: CompiledAssignment.h:258
const MatrixType & cache(const T &M)
Definition: CompiledAssignment.h:186
CachedResult(const Eigen::Ref< MatrixType > &to)
Definition: CompiledAssignment.h:183
MatrixType & cache()
Definition: CompiledAssignment.h:206
const MatrixType & cache() const
Definition: CompiledAssignment.h:207
Definition: CompiledAssignment.h:169
const T & cache(const T &M)
Definition: CompiledAssignment.h:174
CachedResult(const Eigen::Ref< MatrixType > &)
Definition: CompiledAssignment.h:171
Definition: CompiledAssignmentWrapper.h:30
Eigen::Ref< const MatrixType > SourceType
Definition: CompiledAssignment.h:674
void from(const Eigen::Ref< const MatrixType > &)
Definition: CompiledAssignment.h:681
void to(const Eigen::Ref< MatrixType > &to)
Definition: CompiledAssignment.h:682
void run()
Definition: CompiledAssignment.h:680
void from(const Eigen::Ref< const MatrixType > &)
Definition: CompiledAssignment.h:708
void run()
Definition: CompiledAssignment.h:707
void to(const Eigen::Ref< MatrixType > &to)
Definition: CompiledAssignment.h:709
Eigen::Ref< const MatrixType > SourceType
Definition: CompiledAssignment.h:701
void run()
Definition: CompiledAssignment.h:756
Eigen::Ref< const MatrixType > SourceType
Definition: CompiledAssignment.h:750
void from(const Eigen::Ref< const MatrixType > &)
Definition: CompiledAssignment.h:757
void to(const Eigen::Ref< MatrixType > &to)
Definition: CompiledAssignment.h:758
void run()
Definition: CompiledAssignment.h:734
void to(const Eigen::Ref< MatrixType > &to)
Definition: CompiledAssignment.h:736
Eigen::Ref< const MatrixType > SourceType
Definition: CompiledAssignment.h:728
void from(const Eigen::Ref< const MatrixType > &)
Definition: CompiledAssignment.h:735
Definition: CompiledAssignment.h:598
std::enable_if< use_product_cache< U, A, W, M, F >::value &&!use_assign_cache< U, A, W, M, F >::value >::type run()
Definition: CompiledAssignment.h:639
std::enable_if<!use_product_cache< U, A, W, M, F >::value >::type run()
Definition: CompiledAssignment.h:630
void to(const Eigen::Ref< MatrixType > &to)
Definition: CompiledAssignment.h:653
std::enable_if< use_product_cache< U, A, W, M, F >::value &&use_assign_cache< U, A, W, M, F >::value >::type run()
Definition: CompiledAssignment.h:646
MatrixMultBase(void(*mult)(Eigen::Ref< MatrixType > out, const Eigen::Ref< const MatrixType > &in))
Definition: CompiledAssignment.h:532
void applyMatrixMultCached(MatrixType &cache, const T &M)
Definition: CompiledAssignment.h:535
std::enable_if<!isVector< MatrixType >::value, PostType< T > >::type applyMatrixMult(const T &M)
Definition: CompiledAssignment.h:454
decltype(std::declval< Eigen::Ref< const Eigen::MatrixXd > >() *Eigen::VectorXd::Constant(1, 1)) ConstType
Definition: CompiledAssignment.h:447
std::enable_if< isVector< MatrixType >::value, PreType< T > >::type applyMatrixMult(const T &M)
Definition: CompiledAssignment.h:450
std::enable_if< isVector< U >::value, ConstType >::type applyMatrixMult(const double &d)
Definition: CompiledAssignment.h:458
MatrixMultBase(const Eigen::Ref< const Eigen::MatrixXd > &M)
Definition: CompiledAssignment.h:438
void applyMatrixMultCached(MatrixType &cache, const T &M)
Definition: CompiledAssignment.h:463
decltype(std::declval< T >() *std::declval< Eigen::Ref< const Eigen::MatrixXd > >()) PostType
Definition: CompiledAssignment.h:445
decltype(std::declval< Eigen::Ref< const Eigen::MatrixXd > >() *std::declval< T >()) PreType
Definition: CompiledAssignment.h:442
MatrixMultBase(NoArg)
Definition: CompiledAssignment.h:426
const T & applyMatrixMult(const T &M)
Definition: CompiledAssignment.h:429
decltype(std::declval< InvDiagType >() *std::declval< T >()) PreType
Definition: CompiledAssignment.h:499
std::enable_if< isVector< U >::value, ConstType >::type applyMatrixMult(const double &d)
Definition: CompiledAssignment.h:515
decltype(std::declval< InvDiagType >() *Eigen::VectorXd::Constant(1, 1)) ConstType
Definition: CompiledAssignment.h:504
MatrixMultBase(const Eigen::Ref< const Eigen::MatrixXd > &M)
Definition: CompiledAssignment.h:492
void applyMatrixMultCached(MatrixType &cache, const T &M)
Definition: CompiledAssignment.h:520
std::enable_if<!isVector< MatrixType >::value, PostType< T > >::type applyMatrixMult(const T &M)
Definition: CompiledAssignment.h:511
decltype(std::declval< T >() *std::declval< InvDiagType >()) PostType
Definition: CompiledAssignment.h:502
decltype(std::declval< Eigen::Ref< const Eigen::MatrixXd > >().diagonal().cwiseInverse().asDiagonal()) InvDiagType
Definition: CompiledAssignment.h:496
std::enable_if< isVector< MatrixType >::value, PreType< T > >::type applyMatrixMult(const T &M)
Definition: CompiledAssignment.h:507
Definition: CompiledAssignment.h:419
Definition: CompiledAssignment.h:88
Definition: CompiledAssignment.h:95
static std::tuple_element< N, std::tuple< Args... > >::type get(Args &&... args)
Definition: CompiledAssignment.h:98
Definition: CompiledAssignment.h:121
Definition: CompiledAssignment.h:106
static NoArg get(Args &&...)
Definition: CompiledAssignment.h:109
Definition: CompiledAssignment.h:545
const SourceType & from() const
Definition: CompiledAssignment.h:551
SourceBase(const SourceType &from)
Definition: CompiledAssignment.h:549
void from(const SourceType &from)
Definition: CompiledAssignment.h:553
typename std::conditional< F==CONSTANT, double, Eigen::Ref< const MatrixType > >::type SourceType
Definition: CompiledAssignment.h:547
WeightMultBase(const Eigen::Ref< const Eigen::VectorXd > &d)
Definition: CompiledAssignment.h:400
ReturnType< T > applyWeightMult(const T &M)
Definition: CompiledAssignment.h:405
decltype(std::declval< Eigen::Ref< const Eigen::VectorXd > >().asDiagonal() *std::declval< T >()) ReturnType
Definition: CompiledAssignment.h:403
double applyWeightMult(const double &M)
Definition: CompiledAssignment.h:353
WeightMultBase(NoArg)
Definition: CompiledAssignment.h:351
WeightMultBase(NoArg)
Definition: CompiledAssignment.h:337
const T & applyWeightMult(const T &M)
Definition: CompiledAssignment.h:340
WeightMultBase(const double &s)
Definition: CompiledAssignment.h:378
Definition: CompiledAssignment.h:328
Definition: CompiledAssignment.h:144
Definition: CompiledAssignment.h:218
Definition: CompiledAssignment.h:242
#define TVM_TEMPORARY_ALLOW_EIGEN_MALLOC(x)
Definition: memoryChecks.h:85
Definition: AffineExprDetail.h:95
typename std::conditional< MatrixType::ColsAtCompileTime==1, std::true_type, std::false_type >::type isVector
Definition: CompiledAssignment.h:78
Source
Definition: CompiledAssignment.h:65
@ ZERO
Definition: CompiledAssignment.h:69
@ CONSTANT
Definition: CompiledAssignment.h:71
@ EXTERNAL
Definition: CompiledAssignment.h:67
WeightMult
Definition: CompiledAssignment.h:34
@ NONE
Definition: CompiledAssignment.h:35
@ SCALAR
Definition: CompiledAssignment.h:37
@ DIAGONAL
Definition: CompiledAssignment.h:38
@ MINUS
Definition: CompiledAssignment.h:36
AssignType
Definition: CompiledAssignment.h:22
@ ADD
Definition: CompiledAssignment.h:24
@ MAX
Definition: CompiledAssignment.h:27
@ MIN
Definition: CompiledAssignment.h:26
@ SUB
Definition: CompiledAssignment.h:25
@ COPY
Definition: CompiledAssignment.h:23
decltype(hasNoArgCtorDummy(T(NoArg()))) hasNoArgCtor_(int)
typename std::conditional< MatrixType::ColsAtCompileTime !=1, std::true_type, std::false_type >::type isMatrix
Definition: CompiledAssignment.h:84
MatrixMult
Definition: CompiledAssignment.h:45
@ CUSTOM
Definition: CompiledAssignment.h:53
@ IDENTITY
Definition: CompiledAssignment.h:47
@ GENERAL
Definition: CompiledAssignment.h:49
@ INVERSE_DIAGONAL
Definition: CompiledAssignment.h:51
std::true_type hasNoArgCtorDummy(const T &)
Proportional P
Definition: Proportional.h:92