TVM  0.9.4
AffineExprOperators.h
Go to the documentation of this file.
1 
3 #pragma once
4 
5 #include <tvm/utils/AffineExpr.h>
6 
7 namespace tvm
8 {
9 
10 namespace utils
11 {
12 
14 template<typename Derived>
16 {
17  return tvm::utils::LinearExpr<std::remove_const_t<decltype(-std::declval<Derived>())>>(-lin.matrix(), lin.variable());
18 }
19 
21 template<typename CstDerived, typename... Derived>
23 {
25  aff.linear(), std::make_index_sequence<sizeof...(Derived)>{}));
26 }
27 
31 template<typename MultDerived, typename CstDerived, typename... Derived>
32 inline auto operator*(const MultDerived & m, const tvm::utils::AffineExpr<CstDerived, Derived...> & aff)
33 {
35  m, aff.linear(), std::make_index_sequence<sizeof...(Derived)>{}));
36 }
37 
39 template<typename Derived, typename CstDerived>
41  const Eigen::MatrixBase<CstDerived> & cst)
42 { return {cst, lin}; }
43 
45 template<typename Derived, typename CstDerived>
46 inline tvm::utils::AffineExpr<CstDerived, Derived> operator+(const Eigen::MatrixBase<CstDerived> & cst,
48 { return {cst, lin}; }
49 
51 template<typename LhsDerived, typename RhsDerived>
55 { return {lhs, rhs}; }
56 
58 template<typename RhsDerived, typename CstDerived, typename... LhsDerived>
59 inline tvm::utils::AffineExpr<CstDerived, LhsDerived..., RhsDerived> operator+(
62 { return {lhs.constant(), std::tuple_cat(lhs.linear(), std::forward_as_tuple(rhs))}; }
63 
65 template<typename LhsDerived, typename CstDerived, typename... RhsDerived>
66 inline tvm::utils::AffineExpr<CstDerived, LhsDerived, RhsDerived...> operator+(
69 { return {rhs.constant(), std::tuple_cat(std::forward_as_tuple(lhs), rhs.linear())}; }
70 
72 template<typename RhsDerived, typename CstDerived, typename... LhsDerived>
74  operator+(const tvm::utils::AffineExpr<CstDerived, LhsDerived...> & lhs, const Eigen::MatrixBase<RhsDerived> & rhs)
75 { return {lhs.constant() + rhs, lhs.linear()}; }
76 
78 template<typename LhsDerived, typename CstDerived, typename... RhsDerived>
80  operator+(const Eigen::MatrixBase<LhsDerived> & lhs, const tvm::utils::AffineExpr<CstDerived, RhsDerived...> & rhs)
81 { return {lhs + rhs.constant(), rhs.linear()}; }
82 
84 template<typename LCstDerived, typename RCstDerived, typename... LhsDerived, typename... RhsDerived>
85 inline tvm::utils::
86  AffineExpr<tvm::utils::internal::AddConstantsRetType<LCstDerived, RCstDerived>, LhsDerived..., RhsDerived...>
89 { return {lhs.constant() + rhs.constant(), std::tuple_cat(lhs.linear(), rhs.linear())}; }
90 
92 template<typename MultType, typename Derived>
93 inline auto operator*(const MultType & m, const tvm::utils::LinearExpr<Derived> & lin)
94 {
96  lin.variable());
97 }
98 
100 template<typename Derived,
101  typename SubType,
102  typename tvm::internal::
103  enable_for_templated_t<SubType, Eigen::MatrixBase, tvm::utils::LinearExpr, tvm::utils::AffineExpr> = 0>
104 inline auto operator-(const tvm::utils::LinearExpr<Derived> & lin, const SubType & rhs)
105 { return lin + -rhs; }
106 
108 template<typename CstDerived,
109  typename SubType,
110  typename... Derived,
111  typename tvm::internal::
112  enable_for_templated_t<SubType, Eigen::MatrixBase, tvm::utils::LinearExpr, tvm::utils::AffineExpr> = 0>
113 inline auto operator-(const tvm::utils::AffineExpr<CstDerived, Derived...> & aff, const SubType & rhs)
114 { return aff + -rhs; }
115 
116 } // namespace utils
117 
119 template<typename Derived>
120 inline tvm::utils::LinearExpr<Derived> operator*(const Eigen::MatrixBase<Derived> & matrix, const tvm::VariablePtr & v)
121 { return {matrix, v}; }
122 
125 { return v; }
126 
129 {
130  assert(s != 0);
131  return {s, v};
132 }
133 
135 inline auto operator+(const tvm::VariablePtr & u, const tvm::VariablePtr & v)
136 {
139 }
140 
142 template<typename AddType,
143  typename tvm::internal::
144  enable_for_templated_t<AddType, Eigen::MatrixBase, tvm::utils::LinearExpr, tvm::utils::AffineExpr> = 0>
145 inline auto operator+(const AddType & a, const tvm::VariablePtr & v)
147 
149 template<typename AddType,
150  typename tvm::internal::
151  enable_for_templated_t<AddType, Eigen::MatrixBase, tvm::utils::LinearExpr, tvm::utils::AffineExpr> = 0>
152 inline auto operator+(const tvm::VariablePtr & v, const AddType & a)
154 
156 inline auto operator-(const tvm::VariablePtr & u, const tvm::VariablePtr & v)
157 {
160 }
161 
163 template<typename SubType,
164  typename tvm::internal::
165  enable_for_templated_t<SubType, Eigen::MatrixBase, tvm::utils::LinearExpr, tvm::utils::AffineExpr> = 0>
166 inline auto operator-(const SubType & a, const tvm::VariablePtr & v)
168 
170 template<typename SubType,
171  typename tvm::internal::
172  enable_for_templated_t<SubType, Eigen::MatrixBase, tvm::utils::LinearExpr, tvm::utils::AffineExpr> = 0>
173 inline auto operator-(const tvm::VariablePtr & v, const SubType & a)
175 
176 } // namespace tvm
Definition: AffineExpr.h:71
const CstDerived & constant() const
Definition: AffineExpr.h:98
const std::tuple< LinearExpr< Derived >... > & linear() const
Definition: AffineExpr.h:97
Definition: AffineExpr.h:26
const VariablePtr & variable() const
Definition: AffineExpr.h:49
const Derived & matrix() const
Definition: AffineExpr.h:48
auto tuplePremult(const MultType &m, const Tuple &tuple, std::index_sequence< Indices... >)
Definition: AffineExprDetail.h:88
auto tupleUnaryMinus(const Tuple &tuple, std::index_sequence< Indices... >)
Definition: AffineExprDetail.h:81
auto operator-(const tvm::utils::LinearExpr< Derived > &lin)
Definition: AffineExprOperators.h:15
AffineExpr< CstDerived, Derived... > make_AffineExpr(const CstDerived &constant, const std::tuple< LinearExpr< Derived >... > &linear)
Definition: AffineExpr.h:118
tvm::utils::AffineExpr< CstDerived, Derived > operator+(const tvm::utils::LinearExpr< Derived > &lin, const Eigen::MatrixBase< CstDerived > &cst)
Definition: AffineExprOperators.h:40
auto operator*(const MultDerived &m, const tvm::utils::AffineExpr< CstDerived, Derived... > &aff)
Definition: AffineExprOperators.h:32
Definition: Clock.h:12
std::shared_ptr< Variable > VariablePtr
Definition: defs.h:65
tvm::utils::LinearExpr< tvm::utils::internal::MinusIdentityType > operator-(const tvm::VariablePtr &v)
Definition: AffineExprOperators.h:124
tvm::utils::LinearExpr< Derived > operator*(const Eigen::MatrixBase< Derived > &matrix, const tvm::VariablePtr &v)
Definition: AffineExprOperators.h:120
auto operator+(const tvm::VariablePtr &u, const tvm::VariablePtr &v)
Definition: AffineExprOperators.h:135