I would like to run the same code both:
- with as inputs MX variables, so that it's differentiable;
- with as inputs just constants.
I'll give a small toy example:
fromcasadiimport*t=MX("t",1)deff(tin):out=MX.zeros(2)out[0]=tin+2out[1]=tin-2returnoutprintf(t)#MX variable as input>>mapping(dense2-by-1matrix,dependencies:[[0,0],(t+2),(t-2)],nonzeros:[0(1),0(2),])printf(5)#constant (i.e., non-casadi variable) as input>>mapping(dense2-by-1matrix,dependencies:[[0,0],7,3],nonzeros:[0(1),0(2),])outfun=MXFunction([],[f(5)])outfun.init()outfun.evaluate()printoutfun.output()>>[7,3]
The second mapping doesn't contain any variables anymore, so is it possible to just convert this MX to a constant array, without all the hassle of creating a function without inputs, initiating it, evaluating it and outputting it?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello! Sorry for not answering earlier. I missed this post. The MX class currently does not support constant folding. The behavior that you are requestion does indeed make sense, and we are working towards having both constant folding and more simplications for the MX type.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello all,
I would like to run the same code both:
- with as inputs MX variables, so that it's differentiable;
- with as inputs just constants.
I'll give a small toy example:
The second mapping doesn't contain any variables anymore, so is it possible to just convert this MX to a constant array, without all the hassle of creating a function without inputs, initiating it, evaluating it and outputting it?
Hello! Sorry for not answering earlier. I missed this post. The MX class currently does not support constant folding. The behavior that you are requestion does indeed make sense, and we are working towards having both constant folding and more simplications for the MX type.
There is a ticket for this by the way: https://sourceforge.net/apps/trac/casadi/ticket/172