26 #ifndef CASADI_KRON_HPP
27 #define CASADI_KRON_HPP
29 #include "mx_node.hpp"
49 class CASADI_EXPORT Kron :
public MXNode {
53 static MX create(
const MX& a,
const MX& b);
56 Kron(
const MX& a,
const MX& b);
62 virtual void eval_kernel(
const double** arg,
double** res)
const;
63 virtual void eval_kernel(
const SXElem** arg, SXElem** res)
const;
67 int eval_gen(
const T** arg, T** res, casadi_int* iw, T* w)
const {
68 eval_kernel(arg, res);
75 int eval(
const double** arg,
double** res, casadi_int* iw,
double* w)
const override {
76 return eval_gen<double>(arg, res, iw, w);
82 int eval_sx(
const SXElem** arg, SXElem** res, casadi_int* iw, SXElem* w)
const override {
83 return eval_gen<SXElem>(arg, res, iw, w);
89 void eval_mx(
const std::vector<MX>& arg, std::vector<MX>& res,
90 const std::vector<bool>& unique={})
const override;
95 int sp_forward(
const bvec_t** arg, bvec_t** res, casadi_int* iw, bvec_t* w)
const override;
100 int sp_reverse(bvec_t** arg, bvec_t** res, casadi_int* iw, bvec_t* w)
const override;
105 void ad_forward(
const std::vector<std::vector<MX> >& fseed,
106 std::vector<std::vector<MX> >& fsens)
const override;
111 void ad_reverse(
const std::vector<std::vector<MX> >& aseed,
112 std::vector<std::vector<MX> >& asens)
const override;
117 void generate(CodeGenerator& g,
118 const std::vector<casadi_int>& arg,
119 const std::vector<casadi_int>& res,
120 const std::vector<bool>& arg_is_ref,
121 std::vector<bool>& res_is_ref)
const override;
126 std::string disp(
const std::vector<std::string>& arg)
const override;
131 casadi_int op()
const override {
return OP_KRON;}
136 void serialize_type(SerializingStream& s)
const override;
141 static MXNode* deserialize(DeserializingStream& s);
148 explicit Kron(DeserializingStream& s) : MXNode(s) {}
155 class CASADI_EXPORT DenseKron :
public Kron {
157 static MXNode* try_create(
const MX& a,
const MX& b);
159 DenseKron(
const MX& a,
const MX& b) : Kron(a, b) {}
160 ~DenseKron()
override {}
162 void eval_kernel(
const double** arg,
double** res)
const override;
163 void eval_kernel(
const SXElem** arg, SXElem** res)
const override;
165 void generate(CodeGenerator& g,
166 const std::vector<casadi_int>& arg,
167 const std::vector<casadi_int>& res,
168 const std::vector<bool>& arg_is_ref,
169 std::vector<bool>& res_is_ref)
const override;
171 void serialize_type(SerializingStream& s)
const override;
172 explicit DenseKron(DeserializingStream& s) : Kron(s) {}
179 class CASADI_EXPORT DenseSparseKron :
public Kron {
181 static MXNode* try_create(
const MX& a,
const MX& b);
183 DenseSparseKron(
const MX& a,
const MX& b) : Kron(a, b) {}
184 ~DenseSparseKron()
override {}
186 void eval_kernel(
const double** arg,
double** res)
const override;
187 void eval_kernel(
const SXElem** arg, SXElem** res)
const override;
189 void generate(CodeGenerator& g,
190 const std::vector<casadi_int>& arg,
191 const std::vector<casadi_int>& res,
192 const std::vector<bool>& arg_is_ref,
193 std::vector<bool>& res_is_ref)
const override;
195 void serialize_type(SerializingStream& s)
const override;
196 explicit DenseSparseKron(DeserializingStream& s) : Kron(s) {}
203 class CASADI_EXPORT SparseDenseKron :
public Kron {
205 static MXNode* try_create(
const MX& a,
const MX& b);
207 SparseDenseKron(
const MX& a,
const MX& b) : Kron(a, b) {}
208 ~SparseDenseKron()
override {}
210 void eval_kernel(
const double** arg,
double** res)
const override;
211 void eval_kernel(
const SXElem** arg, SXElem** res)
const override;
213 void generate(CodeGenerator& g,
214 const std::vector<casadi_int>& arg,
215 const std::vector<casadi_int>& res,
216 const std::vector<bool>& arg_is_ref,
217 std::vector<bool>& res_is_ref)
const override;
219 void serialize_type(SerializingStream& s)
const override;
220 explicit SparseDenseKron(DeserializingStream& s) : Kron(s) {}
241 class CASADI_EXPORT KronContract :
public MXNode {
245 static MX create(
const MX& m,
const MX& x,
bool inner);
248 KronContract(
const MX& m,
const MX& x,
bool inner);
251 ~KronContract()
override {}
255 virtual void eval_kernel(
const double** arg,
double** res,
double* w)
const;
256 virtual void eval_kernel(
const SXElem** arg, SXElem** res, SXElem* w)
const;
260 int eval_gen(
const T** arg, T** res, casadi_int* iw, T* w)
const {
261 eval_kernel(arg, res, w);
268 int eval(
const double** arg,
double** res, casadi_int* iw,
double* w)
const override {
269 return eval_gen<double>(arg, res, iw, w);
275 int eval_sx(
const SXElem** arg, SXElem** res, casadi_int* iw, SXElem* w)
const override {
276 return eval_gen<SXElem>(arg, res, iw, w);
282 void eval_mx(
const std::vector<MX>& arg, std::vector<MX>& res,
283 const std::vector<bool>& unique={})
const override;
288 int sp_forward(
const bvec_t** arg, bvec_t** res, casadi_int* iw, bvec_t* w)
const override;
293 int sp_reverse(bvec_t** arg, bvec_t** res, casadi_int* iw, bvec_t* w)
const override;
298 void ad_forward(
const std::vector<std::vector<MX> >& fseed,
299 std::vector<std::vector<MX> >& fsens)
const override;
304 void ad_reverse(
const std::vector<std::vector<MX> >& aseed,
305 std::vector<std::vector<MX> >& asens)
const override;
310 size_t sz_w()
const override;
315 void generate(CodeGenerator& g,
316 const std::vector<casadi_int>& arg,
317 const std::vector<casadi_int>& res,
318 const std::vector<bool>& arg_is_ref,
319 std::vector<bool>& res_is_ref)
const override;
324 std::string disp(
const std::vector<std::string>& arg)
const override;
329 casadi_int op()
const override {
return OP_KRON_CONTRACT;}
334 void serialize_body(SerializingStream& s)
const override;
339 void serialize_type(SerializingStream& s)
const override;
344 static MXNode* deserialize(DeserializingStream& s);
354 explicit KronContract(DeserializingStream& s);
361 class CASADI_EXPORT DenseKronContract :
public KronContract {
363 static MXNode* try_create(
const MX& m,
const MX& x,
bool inner);
365 DenseKronContract(
const MX& m,
const MX& x,
bool inner) : KronContract(m, x, inner) {}
366 ~DenseKronContract()
override {}
368 void eval_kernel(
const double** arg,
double** res,
double* w)
const override;
369 void eval_kernel(
const SXElem** arg, SXElem** res, SXElem* w)
const override;
374 void generate(CodeGenerator& g,
375 const std::vector<casadi_int>& arg,
376 const std::vector<casadi_int>& res,
377 const std::vector<bool>& arg_is_ref,
378 std::vector<bool>& res_is_ref)
const override;
380 void serialize_type(SerializingStream& s)
const override;
381 explicit DenseKronContract(DeserializingStream& s) : KronContract(s) {}
388 class CASADI_EXPORT DenseSparseKronContract :
public KronContract {
390 static MXNode* try_create(
const MX& m,
const MX& x,
bool inner);
392 DenseSparseKronContract(
const MX& m,
const MX& x,
bool inner) : KronContract(m, x, inner) {}
393 ~DenseSparseKronContract()
override {}
395 void eval_kernel(
const double** arg,
double** res,
double* w)
const override;
396 void eval_kernel(
const SXElem** arg, SXElem** res, SXElem* w)
const override;
400 void generate(CodeGenerator& g,
401 const std::vector<casadi_int>& arg,
402 const std::vector<casadi_int>& res,
403 const std::vector<bool>& arg_is_ref,
404 std::vector<bool>& res_is_ref)
const override;
406 void serialize_type(SerializingStream& s)
const override;
407 explicit DenseSparseKronContract(DeserializingStream& s) : KronContract(s) {}
414 class CASADI_EXPORT SparseDenseKronContract :
public KronContract {
416 static MXNode* try_create(
const MX& m,
const MX& x,
bool inner);
418 SparseDenseKronContract(
const MX& m,
const MX& x,
bool inner) : KronContract(m, x, inner) {}
419 ~SparseDenseKronContract()
override {}
421 void eval_kernel(
const double** arg,
double** res,
double* w)
const override;
422 void eval_kernel(
const SXElem** arg, SXElem** res, SXElem* w)
const override;
426 void generate(CodeGenerator& g,
427 const std::vector<casadi_int>& arg,
428 const std::vector<casadi_int>& res,
429 const std::vector<bool>& arg_is_ref,
430 std::vector<bool>& res_is_ref)
const override;
432 void serialize_type(SerializingStream& s)
const override;
433 explicit SparseDenseKronContract(DeserializingStream& s) : KronContract(s) {}