TVM  0.9.4
ProtoTask.h
Go to the documentation of this file.
1 
3 #pragma once
4 
5 #include <tvm/api.h>
6 
7 #include <tvm/utils/AffineExpr.h>
9 
10 namespace tvm
11 {
12 
13 namespace utils
14 {
15 
16 template<constraint::Type T, typename FunT>
17 class ProtoTaskCommon;
18 
20 template<constraint::Type T>
22 
24 template<constraint::Type T>
26 
27 template<constraint::Type T, typename FunT>
29 {
30 public:
31  ProtoTaskCommon(FunT f, const internal::RHS & rhs) : f_(f), rhs_(rhs)
32  {
33  if(rhs.type_ == internal::RHSType::Vector && f->rSize() != rhs.v_.size())
34  {
35  throw std::runtime_error("The vector you provided has not the correct size.");
36  }
37  }
38 
39  template<typename FunU>
41  {}
42 
43  FunT f_;
45 };
46 
47 template<typename FunT>
48 class ProtoTaskCommon<constraint::Type::DOUBLE_SIDED, FunT>
49 {
50 public:
51  ProtoTaskCommon(FunT f, const internal::RHS & l, const internal::RHS & u) : f_(f), l_(l), u_(u)
52  {
53  if(l.type_ == internal::RHSType::Vector && f->rSize() != l.v_.size())
54  {
55  throw std::runtime_error("The lower bound vector you provided has not the correct size.");
56  }
57  if(u.type_ == internal::RHSType::Vector && f->rSize() != u.v_.size())
58  {
59  throw std::runtime_error("The upper bound vector you provided has not the correct size.");
60  }
61  }
62 
63  template<typename FunU>
65  {}
66 
70 };
71 
76 template<typename T, typename IfNotLinearFunction, typename IfLinearFunction>
77 using ProtoChoice =
78  typename std::enable_if<std::is_base_of<tvm::function::abstract::Function, T>::value,
79  typename std::conditional<std::is_base_of<tvm::function::abstract::LinearFunction, T>::value,
80  IfLinearFunction,
81  IfNotLinearFunction>::type>::type;
82 
86 template<typename T>
88 
92 template<typename T>
94 
98 template<typename T>
100 
104 template<typename T>
106 
107 } // namespace utils
108 
109 } // namespace tvm
110 
121 // clang-format off
122 template<typename F>
123 inline tvm::utils::ProtoTaskEQRet<F> operator==(std::shared_ptr<F> f, const tvm::utils::internal::RHS& rhs) { return { f, rhs }; }
124 template<typename F>
125 inline tvm::utils::ProtoTaskEQRet<F> operator==(const tvm::utils::internal::RHS& rhs, std::shared_ptr<F> f) { return { f, rhs }; }
126 template<typename F>
127 inline tvm::utils::ProtoTaskGTRet<F> operator>=(std::shared_ptr<F> f, const tvm::utils::internal::RHS& rhs) { return { f, rhs }; }
128 template<typename F>
129 inline tvm::utils::ProtoTaskLTRet<F> operator>=(const tvm::utils::internal::RHS& rhs, std::shared_ptr<F> f) { return { f, rhs }; }
130 template<typename F>
131 inline tvm::utils::ProtoTaskLTRet<F> operator<=(std::shared_ptr<F> f, const tvm::utils::internal::RHS& rhs) { return { f, rhs }; }
132 template<typename F>
133 inline tvm::utils::ProtoTaskGTRet<F> operator<=(const tvm::utils::internal::RHS& rhs, std::shared_ptr<F> f) { return { f, rhs }; }
134 
135 inline tvm::utils::ProtoTaskDS operator>=(const tvm::utils::ProtoTaskLT& ptl, const tvm::utils::internal::RHS& rhs) { return { ptl.f_, rhs, ptl.rhs_ }; }
136 inline tvm::utils::ProtoTaskDS operator<=(const tvm::utils::ProtoTaskGT& ptg, const tvm::utils::internal::RHS& rhs) { return { ptg.f_, ptg.rhs_, rhs }; }
137 inline tvm::utils::LinearProtoTaskDS operator>=(const tvm::utils::LinearProtoTaskLT& ptl, const tvm::utils::internal::RHS& rhs) { return { ptl.f_, rhs, ptl.rhs_ }; }
138 inline tvm::utils::LinearProtoTaskDS operator<=(const tvm::utils::LinearProtoTaskGT& ptg, const tvm::utils::internal::RHS& rhs) { return { ptg.f_, ptg.rhs_, rhs }; }
139 // clang-format on
142 #define TVM_ID(x) std::make_shared<tvm::function::IdentityFunction>(x)
152 // clang-format off
159 // clang-format on
161 #undef TVM_ID
162 
163 #define TVM_LIN(x) std::make_shared<tvm::function::BasicLinearFunction>(x)
164 
176 // clang-format off
177 template<typename Derived>
179 template<typename Derived>
181 template<typename Derived>
183 template<typename Derived>
185 template<typename Derived>
187 template<typename Derived>
189 
190 template<typename CstDerived, typename... Derived>
192 template<typename CstDerived, typename... Derived>
194 template<typename CstDerived, typename... Derived>
196 template<typename CstDerived, typename... Derived>
198 template<typename CstDerived, typename... Derived>
200 template<typename CstDerived, typename... Derived>
202 // clang-format on
204 #undef TVM_LIN
#define TVM_LIN(x)
Definition: ProtoTask.h:163
tvm::utils::ProtoTaskEQRet< F > operator==(std::shared_ptr< F > f, const tvm::utils::internal::RHS &rhs)
Definition: ProtoTask.h:123
tvm::utils::ProtoTaskGTRet< F > operator>=(std::shared_ptr< F > f, const tvm::utils::internal::RHS &rhs)
Definition: ProtoTask.h:127
tvm::utils::ProtoTaskLTRet< F > operator<=(std::shared_ptr< F > f, const tvm::utils::internal::RHS &rhs)
Definition: ProtoTask.h:131
#define TVM_ID(x)
Definition: ProtoTask.h:142
Definition: AffineExpr.h:71
Definition: AffineExpr.h:26
ProtoTaskCommon(FunT f, const internal::RHS &l, const internal::RHS &u)
Definition: ProtoTask.h:51
ProtoTaskCommon(const ProtoTaskCommon< constraint::Type::DOUBLE_SIDED, FunU > &pt)
Definition: ProtoTask.h:64
Definition: ProtoTask.h:29
FunT f_
Definition: ProtoTask.h:43
internal::RHS rhs_
Definition: ProtoTask.h:44
ProtoTaskCommon(FunT f, const internal::RHS &rhs)
Definition: ProtoTask.h:31
ProtoTaskCommon(const ProtoTaskCommon< T, FunU > &pt)
Definition: ProtoTask.h:40
Definition: ProtoTaskDetails.h:38
Eigen::VectorXd v_
Definition: ProtoTaskDetails.h:48
RHSType type_
Definition: ProtoTaskDetails.h:46
typename std::enable_if< std::is_base_of< tvm::function::abstract::Function, T >::value, typename std::conditional< std::is_base_of< tvm::function::abstract::LinearFunction, T >::value, IfLinearFunction, IfNotLinearFunction >::type >::type ProtoChoice
Definition: ProtoTask.h:81
ProtoChoice< T, tvm::utils::ProtoTaskDS, tvm::utils::LinearProtoTaskDS > ProtoTaskDSRet
Definition: ProtoTask.h:105
ProtoChoice< T, tvm::utils::ProtoTaskLT, tvm::utils::LinearProtoTaskLT > ProtoTaskLTRet
Definition: ProtoTask.h:93
ProtoChoice< T, tvm::utils::ProtoTaskEQ, tvm::utils::LinearProtoTaskEQ > ProtoTaskEQRet
Definition: ProtoTask.h:87
ProtoChoice< T, tvm::utils::ProtoTaskGT, tvm::utils::LinearProtoTaskGT > ProtoTaskGTRet
Definition: ProtoTask.h:99
Definition: Clock.h:12
std::shared_ptr< Variable > VariablePtr
Definition: defs.h:65
std::shared_ptr< function::abstract::Function > FunctionPtr
Definition: defs.h:57