7 #include <boost/variant.hpp>
10 #include <boost/test/unit_test.hpp>
11 #include <boost/utility/binary.hpp>
13 BOOST_AUTO_TEST_SUITE(BOOST_TEST_MODULE)
27 Eigen::Matrix<casadi::SX, 3, 3>
A,
B;
28 Eigen::Matrix<casadi::SX, 3, 1>
a,
b;
29 Eigen::Matrix<casadi::SX, 3, 1>
c =
A *
a -
B.transpose() *
b;
33 template<
typename Scalar,
typename T1,
typename T2,
typename T3,
typename T4>
34 Eigen::Matrix<Scalar, Eigen::Dynamic, 1>
eigenFun(
35 Eigen::MatrixBase<T1>
const &
A,
36 Eigen::MatrixBase<T2>
const &
a,
37 Eigen::MatrixBase<T3>
const & B,
38 Eigen::MatrixBase<T4>
const &
b)
40 Eigen::Matrix<Scalar, Eigen::Dynamic, 1>
c(4);
41 c.segment(1, 3) =
A *
a.segment(1, 3) -
B.transpose() *
b;
54 Eigen::Matrix<casadi::SX, 3, 3>
A,
B;
55 Eigen::Matrix<casadi::SX, -1, 1>
a(4),
c(4);
56 Eigen::Matrix<casadi::SX, 3, 1>
b;
63 A(
i, j) = 10. *
static_cast<double>(
i) +
static_cast<double>(j);
64 B(
i, j) = -10. *
static_cast<double>(
i) -
static_cast<double>(j);
73 c = eigenFun<casadi::SX>(
A,
a,
B,
b);
76 casadi::SX cs_c = casadi::SX(casadi::Sparsity::dense(
c.rows(), 1));
80 std::cout <<
"c = " << cs_c << std::endl;
83 casadi::SX dc_da =
jacobian(cs_c, cs_a);
86 std::cout <<
"dc/da = " << dc_da << std::endl;
89 casadi::Function
fun(
"fun", casadi::SXVector{cs_a, cs_b}, casadi::SXVector{cs_c, dc_da});
90 std::cout <<
"fun = " <<
fun << std::endl;
93 casadi::DMVector
res =
94 fun(casadi::DMVector{std::vector<double>{1., 2., 3., 4.}, std::vector<double>{-1., -2., -3.}});
95 std::cout <<
"fun(a, b)=" <<
res << std::endl;
103 cs_y(0) = cs_x(0) + cs_x(1) + cs_x(2);
106 std::cout <<
"y = " << cs_y << std::endl;
109 casadi::SX dy_dx =
jacobian(cs_x, cs_x);
112 std::cout <<
"dy/dx = " << dy_dx << std::endl;
118 Eigen::Matrix<casadi::SX, 3, 4> eig_mat;
121 std::cout << eig_mat << std::endl;
126 Eigen::Matrix<casadi::SX, 3, 4> eig_mat;
132 std::cout << cs_mat << std::endl;
139 casadi::Function
fun(
"fun", casadi::SXVector{
x,
y}, casadi::SXVector{
x +
y});
141 casadi::CodeGenerator gen(
"module");
144 std::cout << gen.dump();
157 BOOST_AUTO_TEST_SUITE_END()