List of all members | Public Member Functions | Public Attributes
casadi::DaeBuilderInternal::CallIO Struct Reference

Helper class, represents inputs and outputs for a function call node. More...

#include <dae_builder_internal.hpp>

Detailed Description

Definition at line 741 of file dae_builder_internal.hpp.

Collaboration diagram for casadi::DaeBuilderInternal::CallIO:
Collaboration graph
[legend]

Public Member Functions

void calc_jac ()
 
void calc_grad ()
 
void calc_hess ()
 
const MXjac (casadi_int oind, casadi_int iind) const
 
const MXhess (casadi_int iind1, casadi_int iind2) const
 

Public Attributes

Function f
 
Function adj1_f
 
Function J
 
Function H
 
std::vector< size_t > v
 
std::vector< size_t > vdef
 
std::vector< MXarg
 
std::vector< MXres
 
std::vector< MXjac_res
 
std::vector< MXadj1_arg
 
std::vector< MXadj1_res
 
std::vector< MXhess_res
 

Member Function Documentation

◆ calc_grad()

void casadi::DaeBuilderInternal::CallIO::calc_grad ( )

Definition at line 2340 of file dae_builder_internal.cpp.

2340  {
2341  // Consistency checks
2342  for (casadi_int i = 0; i < this->f.n_in(); ++i) {
2343  casadi_assert(this->f.size_in(i) == this->arg.at(i).size(), "Call input not provided");
2344  }
2345  casadi_assert(this->adj1_arg.size() == this->res.size(), "Input 'lam_vdef' not provided");
2346  for (casadi_int i = 0; i < this->f.n_out(); ++i) {
2347  casadi_assert(this->f.size_out(i) == this->res.at(i).size(), "Call output not provided");
2348  casadi_assert(this->adj1_arg.at(i).size() == this->res.at(i).size(),
2349  "Call adjoint seed not provided");
2350  }
2351  // We should make use of the Jacobian blocks here, if available
2352  if (!this->jac_res.empty())
2353  casadi_warning("Jacobian blocks currently not reused for gradient calculation");
2354  // Get/generate the (cached) adjoint function
2355  // casadi_message("Retrieving the gradient of " + str(this->f));
2356  this->adj1_f = this->f.reverse(1);
2357  // casadi_message("Retrieving the gradient of " + str(this->f) + " done");
2358  // Input expressions for the call to adj1_f
2359  std::vector<MX> call_in = this->arg;
2360  call_in.insert(call_in.end(), this->res.begin(), this->res.end());
2361  call_in.insert(call_in.end(), this->adj1_arg.begin(), this->adj1_arg.end());
2362  // Create expressions for adjoint sweep and save to struct
2363  this->adj1_res = this->adj1_f(call_in);
2364 }
Function reverse(casadi_int nadj) const
Get a function that calculates nadj adjoint derivatives.
Definition: function.cpp:1143
std::pair< casadi_int, casadi_int > size_out(casadi_int ind) const
Get output dimension.
Definition: function.cpp:847
casadi_int n_out() const
Get the number of function outputs.
Definition: function.cpp:823
casadi_int n_in() const
Get the number of function inputs.
Definition: function.cpp:819
std::pair< casadi_int, casadi_int > size_in(casadi_int ind) const
Get input dimension.
Definition: function.cpp:843

◆ calc_hess()

void casadi::DaeBuilderInternal::CallIO::calc_hess ( )

Definition at line 2366 of file dae_builder_internal.cpp.

2366  {
2367  // Calculate gradient, if needed
2368  if (this->adj1_f.is_null()) calc_grad();
2369  // Get/generate the (cached) Hessian function
2370  // casadi_message("Retrieving the Hessian of " + str(this->f));
2371  this->H = this->adj1_f.jacobian();
2372  // casadi_message("Retrieving the Hessian of " + str(this->f) + " done");
2373  // Input expressions for the call to H
2374  std::vector<MX> call_in = this->arg;
2375  call_in.insert(call_in.end(), this->res.begin(), this->res.end());
2376  call_in.insert(call_in.end(), this->adj1_arg.begin(), this->adj1_arg.end());
2377  call_in.insert(call_in.end(), this->adj1_res.begin(), this->adj1_res.end());
2378  // Create expressions for Hessian blocks and save to struct
2379  this->hess_res = this->H(call_in);
2380 }
Function jacobian() const
Calculate all Jacobian blocks.
Definition: function.cpp:916
bool is_null() const
Is a null pointer?

◆ calc_jac()

void casadi::DaeBuilderInternal::CallIO::calc_jac ( )

Definition at line 2321 of file dae_builder_internal.cpp.

2321  {
2322  // Consistency checks
2323  for (casadi_int i = 0; i < this->f.n_in(); ++i) {
2324  casadi_assert(this->f.size_in(i) == this->arg.at(i).size(), "Call input not provided");
2325  }
2326  for (casadi_int i = 0; i < this->f.n_out(); ++i) {
2327  casadi_assert(this->f.size_out(i) == this->res.at(i).size(), "Call output not provided");
2328  }
2329  // Get/generate the (cached) Jacobian function
2330  // casadi_message("Retrieving the Jacobian of " + str(this->f));
2331  this->J = this->f.jacobian();
2332  // casadi_message("Retrieving the Jacobian of " + str(this->f) + " done");
2333  // Input expressions for the call to J
2334  std::vector<MX> call_in = this->arg;
2335  call_in.insert(call_in.end(), this->res.begin(), this->res.end());
2336  // Create expressions for Jacobian blocks and save to struct
2337  this->jac_res = this->J(call_in);
2338 }

References arg, f, J, jac_res, casadi::Function::jacobian(), casadi::Function::n_in(), casadi::Function::n_out(), casadi::Function::size_in(), and casadi::Function::size_out().

◆ hess()

const MX & casadi::DaeBuilderInternal::CallIO::hess ( casadi_int  iind1,
casadi_int  iind2 
) const

Definition at line 2389 of file dae_builder_internal.cpp.

2389  {
2390  // Flat index
2391  casadi_int ind = iind1 + iind1 * this->adj1_arg.size();
2392  // Return reference
2393  return this->hess_res.at(ind);
2394 }

References casadi::GenericMatrix< MatType >::size().

◆ jac()

const MX & casadi::DaeBuilderInternal::CallIO::jac ( casadi_int  oind,
casadi_int  iind 
) const

Definition at line 2382 of file dae_builder_internal.cpp.

2382  {
2383  // Flat index
2384  casadi_int ind = iind + oind * this->arg.size();
2385  // Return reference
2386  return this->jac_res.at(ind);
2387 }

References casadi::GenericMatrix< MatType >::size().

Member Data Documentation

◆ adj1_arg

std::vector<MX> casadi::DaeBuilderInternal::CallIO::adj1_arg

Definition at line 753 of file dae_builder_internal.hpp.

Referenced by casadi::DaeBuilderInternal::create().

◆ adj1_f

Function casadi::DaeBuilderInternal::CallIO::adj1_f

Definition at line 743 of file dae_builder_internal.hpp.

◆ adj1_res

std::vector<MX> casadi::DaeBuilderInternal::CallIO::adj1_res

Definition at line 755 of file dae_builder_internal.hpp.

◆ arg

std::vector<MX> casadi::DaeBuilderInternal::CallIO::arg

Definition at line 747 of file dae_builder_internal.hpp.

Referenced by calc_jac(), and casadi::DaeBuilderInternal::create().

◆ f

Function casadi::DaeBuilderInternal::CallIO::f

Definition at line 743 of file dae_builder_internal.hpp.

Referenced by calc_jac(), and casadi::DaeBuilderInternal::create().

◆ H

Function casadi::DaeBuilderInternal::CallIO::H

Definition at line 743 of file dae_builder_internal.hpp.

◆ hess_res

std::vector<MX> casadi::DaeBuilderInternal::CallIO::hess_res

Definition at line 757 of file dae_builder_internal.hpp.

◆ J

Function casadi::DaeBuilderInternal::CallIO::J

Definition at line 743 of file dae_builder_internal.hpp.

Referenced by calc_jac().

◆ jac_res

std::vector<MX> casadi::DaeBuilderInternal::CallIO::jac_res

Definition at line 751 of file dae_builder_internal.hpp.

Referenced by calc_jac().

◆ res

std::vector<MX> casadi::DaeBuilderInternal::CallIO::res

Definition at line 749 of file dae_builder_internal.hpp.

Referenced by casadi::DaeBuilderInternal::create().

◆ v

std::vector<size_t> casadi::DaeBuilderInternal::CallIO::v

Definition at line 745 of file dae_builder_internal.hpp.

Referenced by casadi::DaeBuilderInternal::create().

◆ vdef

std::vector<size_t> casadi::DaeBuilderInternal::CallIO::vdef

Definition at line 745 of file dae_builder_internal.hpp.

Referenced by casadi::DaeBuilderInternal::create().


The documentation for this struct was generated from the following files: