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

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

◆ calc_hess()

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

Definition at line 2783 of file dae_builder_internal.cpp.

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

◆ calc_jac()

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

Definition at line 2738 of file dae_builder_internal.cpp.

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

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

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

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

◆ jac()

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

Definition at line 2799 of file dae_builder_internal.cpp.

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

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: