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 767 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 MX & jac (casadi_int oind, casadi_int iind) const
 
const MX & hess (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< MX > arg
 
std::vector< MX > res
 
std::vector< MX > jac_res
 
std::vector< MX > adj1_arg
 
std::vector< MX > adj1_res
 
std::vector< MX > hess_res
 

Member Function Documentation

◆ calc_grad()

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

Definition at line 2760 of file dae_builder_internal.cpp.

2760  {
2761  // Consistency checks
2762  for (casadi_int i = 0; i < this->f.n_in(); ++i) {
2763  casadi_assert(this->f.size_in(i) == this->arg.at(i).size(), "Call input not provided");
2764  }
2765  casadi_assert(this->adj1_arg.size() == this->res.size(), "Input 'lam_vdef' not provided");
2766  for (casadi_int i = 0; i < this->f.n_out(); ++i) {
2767  casadi_assert(this->f.size_out(i) == this->res.at(i).size(), "Call output not provided");
2768  casadi_assert(this->adj1_arg.at(i).size() == this->res.at(i).size(),
2769  "Call adjoint seed not provided");
2770  }
2771  // We should make use of the Jacobian blocks here, if available
2772  if (!this->jac_res.empty())
2773  casadi_warning("Jacobian blocks currently not reused for gradient calculation");
2774  // Get/generate the (cached) adjoint function
2775  // casadi_message("Retrieving the gradient of " + str(this->f));
2776  this->adj1_f = this->f.reverse(1);
2777  // casadi_message("Retrieving the gradient of " + str(this->f) + " done");
2778  // Input expressions for the call to adj1_f
2779  std::vector<MX> call_in = this->arg;
2780  call_in.insert(call_in.end(), this->res.begin(), this->res.end());
2781  call_in.insert(call_in.end(), this->adj1_arg.begin(), this->adj1_arg.end());
2782  // Create expressions for adjoint sweep and save to struct
2783  this->adj1_res = this->adj1_f(call_in);
2784 }
Function reverse(casadi_int nadj) const
Get a function computing nadj reverse (adjoint) directional derivatives.
Definition: function.cpp:1332
std::pair< casadi_int, casadi_int > size_out(casadi_int ind) const
Get the shape of an output: rows, columns or both.
Definition: function.cpp:999
casadi_int n_out() const
Get the number of function outputs.
Definition: function.cpp:975
casadi_int n_in() const
Get the number of function inputs.
Definition: function.cpp:971
std::pair< casadi_int, casadi_int > size_in(casadi_int ind) const
Get the shape of an input: rows, columns or both.
Definition: function.cpp:995

◆ calc_hess()

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

Definition at line 2786 of file dae_builder_internal.cpp.

2786  {
2787  // Calculate gradient, if needed
2788  if (this->adj1_f.is_null()) calc_grad();
2789  // Get/generate the (cached) Hessian function
2790  // casadi_message("Retrieving the Hessian of " + str(this->f));
2791  this->H = this->adj1_f.jacobian();
2792  // casadi_message("Retrieving the Hessian of " + str(this->f) + " done");
2793  // Input expressions for the call to H
2794  std::vector<MX> call_in = this->arg;
2795  call_in.insert(call_in.end(), this->res.begin(), this->res.end());
2796  call_in.insert(call_in.end(), this->adj1_arg.begin(), this->adj1_arg.end());
2797  call_in.insert(call_in.end(), this->adj1_res.begin(), this->adj1_res.end());
2798  // Create expressions for Hessian blocks and save to struct
2799  this->hess_res = this->H(call_in);
2800 }
Function jacobian() const
Get a function computing all Jacobian blocks at once.
Definition: function.cpp:1068
bool is_null() const
Is a null pointer?

◆ calc_jac()

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

Definition at line 2741 of file dae_builder_internal.cpp.

2741  {
2742  // Consistency checks
2743  for (casadi_int i = 0; i < this->f.n_in(); ++i) {
2744  casadi_assert(this->f.size_in(i) == this->arg.at(i).size(), "Call input not provided");
2745  }
2746  for (casadi_int i = 0; i < this->f.n_out(); ++i) {
2747  casadi_assert(this->f.size_out(i) == this->res.at(i).size(), "Call output not provided");
2748  }
2749  // Get/generate the (cached) Jacobian function
2750  // casadi_message("Retrieving the Jacobian of " + str(this->f));
2751  this->J = this->f.jacobian();
2752  // casadi_message("Retrieving the Jacobian of " + str(this->f) + " done");
2753  // Input expressions for the call to J
2754  std::vector<MX> call_in = this->arg;
2755  call_in.insert(call_in.end(), this->res.begin(), this->res.end());
2756  // Create expressions for Jacobian blocks and save to struct
2757  this->jac_res = this->J(call_in);
2758 }

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

2809  {
2810  // Flat index
2811  casadi_int ind = iind1 + iind1 * this->adj1_arg.size();
2812  // Return reference
2813  return this->hess_res.at(ind);
2814 }

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

◆ jac()

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

Definition at line 2802 of file dae_builder_internal.cpp.

2802  {
2803  // Flat index
2804  casadi_int ind = iind + oind * this->arg.size();
2805  // Return reference
2806  return this->jac_res.at(ind);
2807 }

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

Member Data Documentation

◆ adj1_arg

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

Definition at line 779 of file dae_builder_internal.hpp.

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

◆ adj1_f

Function casadi::DaeBuilderInternal::CallIO::adj1_f

Definition at line 769 of file dae_builder_internal.hpp.

◆ adj1_res

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

Definition at line 781 of file dae_builder_internal.hpp.

◆ arg

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

Definition at line 773 of file dae_builder_internal.hpp.

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

◆ f

Function casadi::DaeBuilderInternal::CallIO::f

Definition at line 769 of file dae_builder_internal.hpp.

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

◆ H

Function casadi::DaeBuilderInternal::CallIO::H

Definition at line 769 of file dae_builder_internal.hpp.

◆ hess_res

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

Definition at line 783 of file dae_builder_internal.hpp.

◆ J

Function casadi::DaeBuilderInternal::CallIO::J

Definition at line 769 of file dae_builder_internal.hpp.

Referenced by calc_jac().

◆ jac_res

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

Definition at line 777 of file dae_builder_internal.hpp.

Referenced by calc_jac().

◆ res

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

Definition at line 775 of file dae_builder_internal.hpp.

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

◆ v

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

Definition at line 771 of file dae_builder_internal.hpp.

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

◆ vdef

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

Definition at line 771 of file dae_builder_internal.hpp.

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


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