About DM

348 views
Skip to first unread message

José María García Pérez

unread,
Jun 23, 2021, 6:39:45 AM6/23/21
to CasADi
I am new to Casadi. I am trying to wrap a few things for the Nim programming  language.

I have started with the first example from the web but I am sttruggling with the last line (I understand just a little bit of C++):
// Evaluate numerically
std::vector<DM> grad_y_num = f(DM({1,2,3,4,5}));

From what I have seen:
typedef Matrix<double> DM;

What are the types above?:
1. DM({1,2,3,4,5}): the input is vector<double>? and the output just DM?
2. Why the outcome is std::vector<DM>?

Could you help me to point out the relevant constructors in the headers?

Then I can ask for help in the Nim forum for Nim's particularities.

Kind regards,
José M.

José María García Pérez

unread,
Jun 24, 2021, 4:56:02 AM6/24/21
to CasADi
 I managed to compile the first example. Now I am trying to print the results.

I am trying to wrap `print_operator`. Is this the right function to wrap in order to get a string representation of DM content?

José María García Pérez

unread,
Jun 24, 2021, 6:07:46 AM6/24/21
to CasADi
I finally gain access to DM using `get_elements`.
Message has been deleted

joaosa...@gmail.com

unread,
Jul 6, 2021, 9:39:45 AM7/6/21
to CasADi
Not sure if it is what you are looking for, but I also had some doubts on how to use Functions.
Defining one (lets say sum two symbolic vectors)
//Defining the function

const auto &v_1 = casadi::SX::sym("x1",5,1)
const auto &v_2 = casadi::SX::sym("x2",5,1)
const SX &sum = v_1 + v_2;
auto f_ = Function("f"{v_1v_2}{sum});
// Using it
auto v1_dm = DM({1,2,3,4,5});
auto v2_dm = DM({5,4,3,2,1});
const auto &result = f_(std::vector<casadi::DM>{{v1_dm}{v2_dm}});
result[0]
Reply all
Reply to author
Forward
0 new messages