\(\newcommand{\W}[1]{ \; #1 \; }\) \(\newcommand{\R}[1]{ {\rm #1} }\) \(\newcommand{\B}[1]{ {\bf #1} }\) \(\newcommand{\D}[2]{ \frac{\partial #1}{\partial #2} }\) \(\newcommand{\DD}[3]{ \frac{\partial^2 #1}{\partial #2 \partial #3} }\) \(\newcommand{\Dpow}[2]{ \frac{\partial^{#1}}{\partial {#2}^{#1}} }\) \(\newcommand{\dpow}[2]{ \frac{ {\rm d}^{#1}}{{\rm d}\, {#2}^{#1}} }\)
code_gen_fun¶
Generate Source Code and Compile an AD Function¶
Syntax¶
#
include <cppad/example/code_gen_fun.hpp>
Constructors¶
code_gen_fun
fun_name ()code_gen_fun
fun_name ( file_name )code_gen_fun
fun_name ( file_name , cg_fun )code_gen_fun
fun_name ( file_name , cg_fun , eval_jac )sparse_jacobian¶
Jrcv = fun_name . sparse_jacobian
( x )
Prototype¶
Constructors¶
code_gen_fun::code_gen_fun(void)
code_gen_fun::code_gen_fun(const std::string& file_name )
code_gen_fun::code_gen_fun(
const std::string& file_name ,
CppAD::ADFun< CppAD::cg::CG<double> >& cg_fun ,
evaluation_enum eval_jac )
Operations¶
void code_gen_fun::swap(code_gen_fun& other_fun)
CppAD::vector<double>
code_gen_fun::operator()(const CppAD::vector<double>& x)
CppAD::vector<double>
code_gen_fun::jacobian(const CppAD::vector<double>& x)
CppAD::sparse_rcv< CppAD::vector<size_t>, CppAD::vector<double> >
code_gen_fun::sparse_jacobian(const CppAD::vector<double>& x)
CppAD::cg::CG<double>¶
This is the CppAD Base type for the function cg_fun . It is defined by CppADCodeGen. and used to convert the cg_fun function object to source code, compile the source code, and then link the corresponding function evaluation
y =
cg_fun.Forward
(0, x )
Speed¶
The conversion to source and linking is expected to take a significant amount of time and the evaluation of the function is expected to be much faster; see the following speed tests:
cppadcg_det_minor.cpp |
|
cppadcg_sparse_jacobian.cpp |
file_name¶
This is the absolute or relative path for the file that contains the dynamic library. It does not include the files extension at the end that is used for dynamic libraries on this system. If cg_fun is not present in the constructor, it must have been present in a previous constructor with the same file_name .
cg_fun¶
This is a CppAD function object that corresponds to a function \(f : \B{R}^n \rightarrow \B{R}^m\). If this arguments is present in the constructor, a new dynamic library is created.
eval_jac¶
If this argument is present in the constructor, it determines which type of Jacobian \(f'(x)\) will be enabled. The possible choices for eval_jac are:
eval_jac |
Available Jacobian |
|
none |
|
fun_name . |
The default value for eval_jac is none.
jacobian¶
J¶
This return value has size m * n and is the value of the Jacobian \(f'(x)\) where
Speed¶
The speed test cppadcg_det_minor.cpp has the option to pass the determinant function, or the Jacobian of the determinant function, to CppADCodeGen (for the same eventual calculation); see PASS_JACOBIAN_TO_CODE_GEN . This test indicates that both methods have similar setup and derivative calculation times.
Jrcv¶
This return value is a sparse_rcv sparse matrix representation of the Jacobian.
Speed¶
The speed test cppadcg_sparse_jacobian.cpp has the option to pass a function (sparse_jac_fun ) or it’s Jacobian to CppADCodeGen (for the same eventual calculation); see PASS_SPARSE_JACOBIAN_TO_CODE_GEN . THis test indicates that both methods have similar setup and derivative calculation times.
Examples¶
code_gen_fun_function.cpp |
|
code_gen_fun_file.cpp |
File Store and Retrieve a Code Gen Function: Example and Test |
code_gen_fun_jacobian.cpp |
|
code_gen_fun_jac_as_fun.cpp |
|
code_gen_fun_sparse_jacobian.cpp |
Evaluate Sparse Jacobian of a Code Gen Function: Example and Test |
code_gen_fun_sparse_jac_as_fun.cpp |