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 745 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 2324 of file dae_builder_internal.cpp.

2324  {
2325  // Consistency checks
2326  for (casadi_int i = 0; i < this->f.n_in(); ++i) {
2327  casadi_assert(this->f.size_in(i) == this->arg.at(i).size(), "Call input not provided");
2328  }
2329  casadi_assert(this->adj1_arg.size() == this->res.size(), "Input 'lam_vdef' not provided");
2330  for (casadi_int i = 0; i < this->f.n_out(); ++i) {
2331  casadi_assert(this->f.size_out(i) == this->res.at(i).size(), "Call output not provided");
2332  casadi_assert(this->adj1_arg.at(i).size() == this->res.at(i).size(),
2333  "Call adjoint seed not provided");
2334  }
2335  // We should make use of the Jacobian blocks here, if available
2336  if (!this->jac_res.empty())
2337  casadi_warning("Jacobian blocks currently not reused for gradient calculation");
2338  // Get/generate the (cached) adjoint function
2339  // casadi_message("Retrieving the gradient of " + str(this->f));
2340  this->adj1_f = this->f.reverse(1);
2341  // casadi_message("Retrieving the gradient of " + str(this->f) + " done");
2342  // Input expressions for the call to adj1_f
2343  std::vector<MX> call_in = this->arg;
2344  call_in.insert(call_in.end(), this->res.begin(), this->res.end());
2345  call_in.insert(call_in.end(), this->adj1_arg.begin(), this->adj1_arg.end());
2346  // Create expressions for adjoint sweep and save to struct
2347  this->adj1_res = this->adj1_f(call_in);
2348 }
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 2350 of file dae_builder_internal.cpp.

2350  {
2351  // Calculate gradient, if needed
2352  if (this->adj1_f.is_null()) calc_grad();
2353  // Get/generate the (cached) Hessian function
2354  // casadi_message("Retrieving the Hessian of " + str(this->f));
2355  this->H = this->adj1_f.jacobian();
2356  // casadi_message("Retrieving the Hessian of " + str(this->f) + " done");
2357  // Input expressions for the call to H
2358  std::vector<MX> call_in = this->arg;
2359  call_in.insert(call_in.end(), this->res.begin(), this->res.end());
2360  call_in.insert(call_in.end(), this->adj1_arg.begin(), this->adj1_arg.end());
2361  call_in.insert(call_in.end(), this->adj1_res.begin(), this->adj1_res.end());
2362  // Create expressions for Hessian blocks and save to struct
2363  this->hess_res = this->H(call_in);
2364 }
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 2305 of file dae_builder_internal.cpp.

2305  {
2306  // Consistency checks
2307  for (casadi_int i = 0; i < this->f.n_in(); ++i) {
2308  casadi_assert(this->f.size_in(i) == this->arg.at(i).size(), "Call input not provided");
2309  }
2310  for (casadi_int i = 0; i < this->f.n_out(); ++i) {
2311  casadi_assert(this->f.size_out(i) == this->res.at(i).size(), "Call output not provided");
2312  }
2313  // Get/generate the (cached) Jacobian function
2314  // casadi_message("Retrieving the Jacobian of " + str(this->f));
2315  this->J = this->f.jacobian();
2316  // casadi_message("Retrieving the Jacobian of " + str(this->f) + " done");
2317  // Input expressions for the call to J
2318  std::vector<MX> call_in = this->arg;
2319  call_in.insert(call_in.end(), this->res.begin(), this->res.end());
2320  // Create expressions for Jacobian blocks and save to struct
2321  this->jac_res = this->J(call_in);
2322 }

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 2373 of file dae_builder_internal.cpp.

2373  {
2374  // Flat index
2375  casadi_int ind = iind1 + iind1 * this->adj1_arg.size();
2376  // Return reference
2377  return this->hess_res.at(ind);
2378 }

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

◆ jac()

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

Definition at line 2366 of file dae_builder_internal.cpp.

2366  {
2367  // Flat index
2368  casadi_int ind = iind + oind * this->arg.size();
2369  // Return reference
2370  return this->jac_res.at(ind);
2371 }

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

Member Data Documentation

◆ adj1_arg

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

Definition at line 757 of file dae_builder_internal.hpp.

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

◆ adj1_f

Function casadi::DaeBuilderInternal::CallIO::adj1_f

Definition at line 747 of file dae_builder_internal.hpp.

◆ adj1_res

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

Definition at line 759 of file dae_builder_internal.hpp.

◆ arg

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

Definition at line 751 of file dae_builder_internal.hpp.

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

◆ f

Function casadi::DaeBuilderInternal::CallIO::f

Definition at line 747 of file dae_builder_internal.hpp.

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

◆ H

Function casadi::DaeBuilderInternal::CallIO::H

Definition at line 747 of file dae_builder_internal.hpp.

◆ hess_res

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

Definition at line 761 of file dae_builder_internal.hpp.

◆ J

Function casadi::DaeBuilderInternal::CallIO::J

Definition at line 747 of file dae_builder_internal.hpp.

Referenced by calc_jac().

◆ jac_res

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

Definition at line 755 of file dae_builder_internal.hpp.

Referenced by calc_jac().

◆ res

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

Definition at line 753 of file dae_builder_internal.hpp.

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

◆ v

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

Definition at line 749 of file dae_builder_internal.hpp.

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

◆ vdef

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

Definition at line 749 of file dae_builder_internal.hpp.

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


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