lines 6-220 of file: cppad_lib/code_gen_fun.cpp {xrst_begin code_gen_fun} {xrst_spell cg jrcv } Generate Source Code and Compile an AD Function ############################################### Syntax ****** # ``include `` 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* ) swap ==== *fun_name* . ``swap`` ( *other_fun* ) function ======== *y* = *fun_name* ( *x* ) jacobian ======== *J* = *fun_name* . ``jacobian`` ( *x* ) sparse_jacobian =============== *Jrcv* = *fun_name* . ``sparse_jacobian`` ( *x* ) Prototype ********* Constructors ============ {xrst_literal // BEGIN_CTOR_VOID // END_CTOR_VOID } {xrst_literal // BEGIN_CTOR_FILE_NAME // END_CTOR_FILE_NAME } {xrst_literal // BEGIN_CTOR_CG_FUN // END_CTOR_CG_FUN } Operations ========== {xrst_literal // BEGIN_SWAP_OTHER_FUN // END_SWAP_OTHER_FUN } {xrst_literal // BEGIN_FUN_NAME_X // END_FUN_NAME_X } {xrst_literal // BEGIN_JACOBIAN // END_JACOBIAN } {xrst_literal // BEGIN_SPARSE_JACOBIAN // END_SPARSE_JACOBIAN } CppAD::cg::CG ********************* 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: .. csv-table:: :widths: auto cppadcg_det_minor.cpp,:ref:`cppadcg_det_minor.cpp-title` cppadcg_sparse_jacobian.cpp,:ref:`cppadcg_sparse_jacobian.cpp-title` fun_name ******** This is the name of the ``code_gen_fun`` object. other_fun ********* This is the name of another ``code_gen_fun`` object. 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 :math:`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 :math:`f'(x)` will be enabled. The possible choices for *eval_jac* are: .. csv-table:: :widths: auto *eval_jac*,Available Jacobian ``code_gen_fun::none_enum``,none ``code_gen_fun::dense_enum``,*fun_name* . ``jacobian`` The default value for *eval_jac* is none. swap **** This exchanges the library in *fun_name* with the library in *other_fun* . x * is a vector of size *n* specifying the argument value at which the function will be evaluated. y * This return value has size *m* and is the value of :math:`f(x)`. jacobian ******** J = This return value has size *m* * *n* and is the value of the Jacobian :math:`f'(x)` where .. math:: J[ i \cdot n + j ] = ( \partial f_i / \partial x_j ) (x) Speed ===== The speed test :ref:`cppadcg_det_minor.cpp-name` has the option to pass the determinant function, or the Jacobian of the determinant function, to CppADCodeGen (for the same eventual calculation); see :ref:`cppadcg_det_minor.cpp@PASS_JACOBIAN_TO_CODE_GEN` . This test indicates that both methods have similar setup and derivative calculation times. sparse_jacobian *************** Jrcv **** This return value is a :ref:`sparse_rcv-name` sparse matrix representation of the Jacobian. Speed ===== The speed test :ref:`cppadcg_sparse_jacobian.cpp-name` has the option to pass a function (:ref:`sparse_jac_fun-name` ) or it's Jacobian to CppADCodeGen (for the same eventual calculation); see :ref:`cppadcg_sparse_jacobian.cpp@PASS_SPARSE_JACOBIAN_TO_CODE_GEN` . THis test indicates that both methods have similar setup and derivative calculation times. {xrst_toc_hidden example/code_gen_fun/function.cpp example/code_gen_fun/file.cpp example/code_gen_fun/jacobian.cpp example/code_gen_fun/jac_as_fun.cpp example/code_gen_fun/sparse_jacobian.cpp example/code_gen_fun/sparse_jac_as_fun.cpp } Examples ******** .. csv-table:: :widths: auto code_gen_fun_function.cpp,:ref:`code_gen_fun_function.cpp-title` code_gen_fun_file.cpp,:ref:`code_gen_fun_file.cpp-title` code_gen_fun_jacobian.cpp,:ref:`code_gen_fun_jacobian.cpp-title` code_gen_fun_jac_as_fun.cpp,:ref:`code_gen_fun_jac_as_fun.cpp-title` code_gen_fun_sparse_jacobian.cpp,:ref:`code_gen_fun_sparse_jacobian.cpp-title` code_gen_fun_sparse_jac_as_fun.cpp,:ref:`code_gen_fun_sparse_jac_as_fun.cpp-title` Implementation ************** see :ref:`code_gen_fun.hpp-name` and :ref:`code_gen_fun.cpp-name` {xrst_end code_gen_fun}