Changeset 3719


Ignore:
Timestamp:
Sep 2, 2015 2:41:58 PM (4 years ago)
Author:
bradbell
Message:

merge to branch: trunk
from repository: https://github.com/coin-or/CppAD
start hash code: 1095c07be7b4d841ad1769e702319420f834e572
end hash code: a110d7f6ee5cb9393a4c96e7a94de14ced36aeb1

commit a110d7f6ee5cb9393a4c96e7a94de14ced36aeb1
Author: Brad Bell <bradbell@…>
Date: Wed Sep 2 10:58:01 2015 -0700

Some cleanup of the doxygen documentation for these routines.

commit f0ce1f816df76df62aacce28c69d4a6dfe9e54de
Author: Brad Bell <bradbell@…>
Date: Wed Sep 2 09:58:54 2015 -0700

Remove invisible white space.

commit 6593f4e9b53a217e8e51279fe3466bc7da1d2418
Author: Brad Bell <bradbell@…>
Date: Wed Sep 2 09:58:25 2015 -0700

Test and fix dependency calculations for VecAD operations.

commit 95ff3da3edd81dabfcfc052d8aa96ef85943420e
Author: Brad Bell <bradbell@…>
Date: Wed Sep 2 07:01:39 2015 -0700

More mention of fact that checkpointing can make recording faster.

commit 3e37eb15e489060e603264f2129b884eb98b91b3
Author: Brad Bell <bradbell@…>
Date: Wed Sep 2 06:18:47 2015 -0700

Test and fix dependency calculations for discrete functions.


for_jac_sweep.hpp: fix missing clear for sign funciton.
advec_depend.sh: need to fix dependency for VecAD operations.
template.sh: add ok to bug template.

Location:
trunk
Files:
1 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/bug/template.sh

    r3670 r3719  
    1717# include <cppad/cppad.hpp>
    1818int main(void)
    19 {       // C++ source code
     19{       bool ok = true;
    2020        using std::cout;
    21 
     21        //
    2222        cout << "1. copy template.sh to <name>.sh\n";
    2323        cout << "2. Edit <name>.sh replacing description and C++ source code\n";
    2424        cout << "3. Run ./<name>.sh\n";
    2525        cout << "where <name> is a name that describes the bug\n";
    26 
    27         return 0;
     26        //
     27        if( ok )
     28                return 0;
     29        return 1;
    2830}
    2931EOF
  • trunk/cppad/local/checkpoint.hpp

    r3717 r3719  
    4040
    4141$section Checkpointing Functions$$
    42 $index function, checkpoint$$
    43 $index checkpoint, function$$
    4442
    4543$head Syntax$$
     
    5250
    5351$head Purpose$$
     52
     53$subhead Reduce Memory$$
    5454You can reduce the size of the tape and memory required for AD by
    5555checkpointing functions of the form $latex y = f(x)$$ where
    5656$latex f : B^n \rightarrow B^m$$.
    57 It may also reduce the time to make a recording at different
    58 independent variable values.
    59 (The checkpoint recording can not depend on independent variables but the
    60 recording that uses it may.)
     57The $cref/operation sequence/glossary/Operation/Sequence/$$
     58representing $latex f(x)$$ cannot depend on the value of $latex x$$.
     59
     60$subhead Faster Recording$$
     61It may also reduce the time to make a recording the same function
     62for different values of the independent variable.
     63Note that the operation sequence for a recording that uses $latex f(x)$$
     64may depend on its independent variables.
    6165
    6266$head Method$$
  • trunk/cppad/local/for_jac_sweep.hpp

    r3718 r3719  
    343343                        case DisOp:
    344344                        CPPAD_ASSERT_NARG_NRES(op, 2, 1);
    345                         var_sparsity.clear(i_var);
     345                        // derivative is identically zero but dependency is not
     346                        if( dependency ) forward_sparse_jacobian_unary_op(
     347                                i_var, arg[1], var_sparsity
     348                        );
     349                        else
     350                                var_sparsity.clear(i_var);
    346351                        break;
    347352                        // -------------------------------------------------
     
    413418                        case LdpOp:
    414419                        forward_sparse_load_op(
     420                                dependency,
    415421                                op,
    416422                                i_var,
     
    426432                        case LdvOp:
    427433                        forward_sparse_load_op(
     434                                dependency,
    428435                                op,
    429436                                i_var,
     
    526533                                i_var, arg[0], var_sparsity
    527534                        );
     535                        else
     536                                var_sparsity.clear(i_var);
    528537                        break;
    529538                        // -------------------------------------------------
     
    557566                        case StppOp:
    558567                        CPPAD_ASSERT_NARG_NRES(op, 3, 0);
    559                         // storing a parameter does not affect vector sparsity
     568                        // if both arguments are parameters does not affect sparsity
     569                        // or dependency
    560570                        break;
    561571                        // -------------------------------------------------
     
    563573                        case StpvOp:
    564574                        forward_sparse_store_op(
     575                                dependency,
    565576                                op,
    566577                                arg,
     
    575586                        case StvpOp:
    576587                        CPPAD_ASSERT_NARG_NRES(op, 3, 0);
    577                         // storing a parameter does not affect vector sparsity
     588                        forward_sparse_store_op(
     589                                dependency,
     590                                op,
     591                                arg,
     592                                num_vecad_ind,
     593                                vecad_ind.data(),
     594                                var_sparsity,
     595                                vecad_sparsity
     596                        );
    578597                        break;
    579598                        // -------------------------------------------------
     
    581600                        case StvvOp:
    582601                        forward_sparse_store_op(
     602                                dependency,
    583603                                op,
    584604                                arg,
  • trunk/cppad/local/load_op.hpp

    r3623 r3719  
    77
    88CppAD is distributed under multiple licenses. This distribution is under
    9 the terms of the 
     9the terms of the
    1010                    Eclipse Public License Version 1.0.
    1111
     
    2020Setting a variable so that it corresponds to current value of a VecAD element.
    2121*/
    22 
    23 /*!
    24 Shared documentation for zero order forward mode implementation of
     22/*
     23==============================================================================
     24<!-- define preamble -->
     25The C++ source code corresponding to this operation is
     26\verbatim
     27        v[x] = y
     28\endverbatim
     29where v is a VecAD<Base> vector, x is an AD<Base> object,
     30and y is AD<Base> or Base objects.
     31We define the index corresponding to v[x] by
     32\verbatim
     33        i_v_x = index_by_ind[ arg[0] + i_vec ]
     34\endverbatim
     35where i_vec is defined under the heading arg[1] below:
     36<!-- end preamble -->
     37==============================================================================
     38*/
     39/*!
     40Shared documentation for zero order forward mode implementation of
    2541op = LdpOp or LdvOp (not called).
    2642
     43<!-- replace preamble -->
    2744The C++ source code corresponding to this operation is
    2845\verbatim
    29         z = v[x]
    30 \endverbatim
    31 where v is a VecAD<Base> vector and x is an AD<Base> index.
     46        v[x] = y
     47\endverbatim
     48where v is a VecAD<Base> vector, x is an AD<Base> object,
     49and y is AD<Base> or Base objects.
    3250We define the index corresponding to v[x] by
    3351\verbatim
     
    3553\endverbatim
    3654where i_vec is defined under the heading arg[1] below:
     55<!-- end preamble -->
    3756
    3857\tparam Base
     
    5069\n
    5170arg[0]
    52 is the offset of this VecAD vector relative to the beginning 
     71is the offset of this VecAD vector relative to the beginning
    5372of the isvar_by_ind and index)_by_ind arrays.
    5473\n
    55 \n 
    56 arg[1] 
     74\n
     75arg[1]
    5776\n
    5877If this is the LdpOp operation (if x is a parameter),
     
    6180        i_vec = arg[1]
    6281\endverbatim
    63 If this is the LdvOp operation (if x is a variable), 
     82If this is the LdvOp operation (if x is a variable),
    6483i_vec is defined by
    6584\verbatim
     
    101120
    102121\param index_by_ind
    103 <code>index_by_ind[ arg[0] - 1 ]</code> 
     122<code>index_by_ind[ arg[0] - 1 ]</code>
    104123is the number of elements in the user vector containing this element.
    105 <code>index_by_ind[ arg[0] + i_vec ]</code> is the variable or 
     124<code>index_by_ind[ arg[0] + i_vec ]</code> is the variable or
    106125parameter index for this element,
    107126This array has size play->num_vec_ind_rec().
     
    110129is a vector with size play->num_load_op_rec().
    111130The input value of its elements does not matter.
    112 Upon return,  it contains the variable index corresponding to each load 
     131Upon return,  it contains the variable index corresponding to each load
    113132instruction.
    114133In the case where the index is zero,
     
    118137\par Check User Errors
    119138\li In the LdvOp case check that the index is with in range; i.e.
    120 <code>i_vec < index_by_ind[ arg[0] - 1 ]</code>. 
    121 Note that, if x is a parameter, 
     139<code>i_vec < index_by_ind[ arg[0] - 1 ]</code>.
     140Note that, if x is a parameter,
    122141the corresponding vector index and it does not change.
    123142In this case, the error above should be detected during tape recording.
     
    127146        player<Base>*  play        ,
    128147        size_t         i_z         ,
    129         const addr_t*  arg         , 
     148        const addr_t*  arg         ,
    130149        const Base*    parameter   ,
    131150        size_t         cap_order   ,
     
    139158}
    140159/*!
    141 Shared documentation for sparsity operations corresponding to 
     160Shared documentation for sparsity operations corresponding to
    142161op = LdpOp or LdvOp (not called).
    143162
    144 <!-- define sparse_load_op -->
     163<!-- replace preamble -->
    145164The C++ source code corresponding to this operation is
    146165\verbatim
    147         z = v[x]
    148 \endverbatim
    149 where v is a VecAD<Base> vector and x is an AD<Base> index.
     166        v[x] = y
     167\endverbatim
     168where v is a VecAD<Base> vector, x is an AD<Base> object,
     169and y is AD<Base> or Base objects.
     170We define the index corresponding to v[x] by
     171\verbatim
     172        i_v_x = index_by_ind[ arg[0] + i_vec ]
     173\endverbatim
     174where i_vec is defined under the heading arg[1] below:
     175<!-- end preamble -->
    150176
    151177\tparam Vector_set
     
    154180
    155181\param op
    156 is the code corresponding to this operator; i.e., LdpOp or LdvOp
    157 (only used for error checking).
     182is the code corresponding to this operator;
     183i.e., LdpOp or LdvOp.
    158184
    159185\param i_z
     
    192218the sparsity pattern for z is added to the sparsity pattern for v.
    193219
    194 \par Checked Assertions 
     220\par Checked Assertions
    195221\li NumArg(op) == 3
    196222\li NumRes(op) == 1
     
    198224\li \a arg[0] < \a num_combined
    199225\li i_v       < \a vecad_sparsity.n_set()
    200 <!-- end sparse_load_op -->
    201226*/
    202227template <class Vector_set>
     
    204229        OpCode              op             ,
    205230        size_t              i_z            ,
    206         const addr_t*        arg           , 
     231        const addr_t*        arg           ,
    207232        size_t              num_combined   ,
    208233        const size_t*       combined       ,
     
    224249        player<Base>*  play        ,
    225250        size_t         i_z         ,
    226         const addr_t*  arg         , 
     251        const addr_t*  arg         ,
    227252        const Base*    parameter   ,
    228253        size_t         cap_order   ,
     
    267292        player<Base>*  play        ,
    268293        size_t         i_z         ,
    269         const addr_t*  arg         , 
     294        const addr_t*  arg         ,
    270295        const Base*    parameter   ,
    271296        size_t         cap_order   ,
     
    280305
    281306        size_t i_vec = Integer( taylor[ arg[1] * cap_order + 0 ] );
    282         CPPAD_ASSERT_KNOWN( 
     307        CPPAD_ASSERT_KNOWN(
    283308                i_vec < index_by_ind[ arg[0] - 1 ] ,
    284309                "VecAD: index during zero order forward sweep is out of range"
     
    286311        CPPAD_ASSERT_UNKNOWN( arg[0] + i_vec < play->num_vec_ind_rec() );
    287312
    288         size_t i_v_x  = index_by_ind[ arg[0] + i_vec ]; 
     313        size_t i_v_x  = index_by_ind[ arg[0] + i_vec ];
    289314        Base* z       = taylor + i_z * cap_order;
    290315        if( isvar_by_ind[ arg[0] + i_vec ]  )
     
    305330Forward mode, except for zero order, for op = LdpOp or op = LdvOp
    306331
     332
     333<!-- replace preamble -->
    307334The C++ source code corresponding to this operation is
    308335\verbatim
    309         z = v[x]
    310 \endverbatim
    311 where v is a VecAD<Base> vector and x is an AD<Base> or Base index.
     336        v[x] = y
     337\endverbatim
     338where v is a VecAD<Base> vector, x is an AD<Base> object,
     339and y is AD<Base> or Base objects.
     340We define the index corresponding to v[x] by
     341\verbatim
     342        i_v_x = index_by_ind[ arg[0] + i_vec ]
     343\endverbatim
     344where i_vec is defined under the heading arg[1] below:
     345<!-- end preamble -->
    312346
    313347\tparam Base
     
    385419        size_t               cap_order            ,
    386420        size_t               i_z                  ,
    387         const addr_t*        arg                  , 
     421        const addr_t*        arg                  ,
    388422        const addr_t*        var_by_load_op       ,
    389423              Base*          taylor               )
    390 {       
     424{
    391425        CPPAD_ASSERT_UNKNOWN( NumArg(op) == 3 );
    392426        CPPAD_ASSERT_UNKNOWN( NumRes(op) == 1 );
     
    424458Reverse mode for op = LdpOp or LdvOp.
    425459
     460<!-- replace preamble -->
    426461The C++ source code corresponding to this operation is
    427462\verbatim
    428         z = y[x]
    429 \endverbatim
    430 where y is a VecAD<Base> vector and x is an AD<Base> or Base index.
    431 
    432 This routine is given the partial derivatives of a function
     463        v[x] = y
     464\endverbatim
     465where v is a VecAD<Base> vector, x is an AD<Base> object,
     466and y is AD<Base> or Base objects.
     467We define the index corresponding to v[x] by
     468\verbatim
     469        i_v_x = index_by_ind[ arg[0] + i_vec ]
     470\endverbatim
     471where i_vec is defined under the heading arg[1] below:
     472<!-- end preamble -->
     473
     474This routine is given the partial derivatives of a function
    433475G(z , y[x] , w , u ... )
    434 and it uses them to compute the partial derivatives of 
     476and it uses them to compute the partial derivatives of
    435477\verbatim
    436478        H( y[x] , w , u , ... ) = G[ z( y[x] ) , y[x] , w , u , ... ]
     
    439481\tparam Base
    440482base type for the operator; i.e., this operation was recorded
    441 using AD< \a Base > and computations by this routine are done using type 
     483using AD< \a Base > and computations by this routine are done using type
    442484\a Base.
    443485
     
    475517\n
    476518\n
    477 \a partial [ \a i_z * \a nc_partial + k ] 
     519\a partial [ \a i_z * \a nc_partial + k ]
    478520for k = 0 , ... , \a d
    479521is the partial derivative of G
     
    484526\a partial [ \a arg[2] * \a nc_partial + k ]
    485527for k = 0 , ... , \a d
    486 is the partial derivative with respect to 
     528is the partial derivative with respect to
    487529the k-th order Taylor coefficient for x.
    488530On input, it corresponds to the function G,
    489 and on output it corresponds to the the function H. 
     531and on output it corresponds to the the function H.
    490532
    491533\param var_by_load_op
     
    495537the instruction corresponds to a parameter (not variable).
    496538
    497 \par Checked Assertions 
     539\par Checked Assertions
    498540\li NumArg(op) == 3
    499541\li NumRes(op) == 1
     
    506548        size_t         d           ,
    507549        size_t         i_z         ,
    508         const addr_t*  arg         , 
     550        const addr_t*  arg         ,
    509551        size_t         cap_order   ,
    510552        const Base*    taylor      ,
     
    533575Forward mode sparsity operations for LdpOp and LdvOp
    534576
     577\param dependency
     578is this a dependency (or sparsity) calculation.
     579
    535580\copydetails sparse_load_op
    536581*/
    537582template <class Vector_set>
    538583inline void forward_sparse_load_op(
     584        bool               dependency     ,
    539585        OpCode             op             ,
    540586        size_t             i_z            ,
    541         const addr_t*      arg            , 
     587        const addr_t*      arg            ,
    542588        size_t             num_combined   ,
    543589        const size_t*      combined       ,
     
    553599
    554600        var_sparsity.assignment(i_z, i_v, vecad_sparsity);
     601        if( dependency & (op == LdvOp) )
     602                var_sparsity.binary_union(i_z, i_z, arg[1], var_sparsity);
    555603
    556604        return;
     
    560608/*!
    561609Reverse mode Jacobian sparsity operations for LdpOp and LdvOp
     610
     611\param dependency
     612is this a dependency (or sparsity) calculation.
    562613
    563614\copydetails sparse_load_op
     
    565616template <class Vector_set>
    566617inline void reverse_sparse_jacobian_load_op(
     618        bool               dependency     ,
    567619        OpCode             op             ,
    568620        size_t             i_z            ,
    569         const addr_t*      arg            , 
     621        const addr_t*      arg            ,
    570622        size_t             num_combined   ,
    571623        const size_t*      combined       ,
     
    581633
    582634        vecad_sparsity.binary_union(i_v, i_v, i_z, var_sparsity);
     635        if( dependency & (op == LdvOp) )
     636                var_sparsity.binary_union(arg[1], arg[1], i_z, var_sparsity);
    583637
    584638        return;
     
    589643Reverse mode Hessian sparsity operations for LdpOp and LdvOp
    590644
    591 This routine is given the sparsity patterns for
    592 G(z , v[x] , w , u ... )
    593 and it uses them to compute the sparsity patterns for
    594 \verbatim
    595         H( v[x] , w , u , ... ) = G[ z( v[x] ) , v[x] , w , u , ... ]
    596 \endverbatim
    597 
    598 <!-- replace sparse_load_op -->
    599 The C++ source code corresponding to this operation is
    600 \verbatim
    601         z = v[x]
    602 \endverbatim
    603 where v is a VecAD<Base> vector and x is an AD<Base> index.
    604 
    605 \tparam Vector_set
    606 is the type used for vectors of sets. It can be either
    607 \c sparse_pack, \c sparse_set, or \c sparse_list.
    608 
    609 \param op
    610 is the code corresponding to this operator; i.e., LdpOp or LdvOp
    611 (only used for error checking).
    612 
    613 \param i_z
    614 is the AD variable index corresponding to the variable z; i.e.,
    615 the set with index \a i_z in \a var_sparsity is the sparsity pattern
    616 correpsonding to z.
    617 
    618 \param arg
    619 \n
    620 \a arg[0]
    621 is the offset corresponding to this VecAD vector in the VecAD combined array.
    622 
    623 \param num_combined
    624 is the total number of elements in the VecAD combinded array.
    625 
    626 \param combined
    627 is the VecAD combined array.
    628 \n
    629 \n
    630 \a combined[ \a arg[0] - 1 ]
    631 is the index of the set corresponding to the vector v  in \a vecad_sparsity.
    632 We use the notation i_v for this value; i.e.,
    633 \verbatim
    634         i_v = combined[ \a arg[0] - 1 ]
    635 \endverbatim
    636 
    637 \param var_sparsity
    638 The set with index \a i_z in \a var_sparsity is the sparsity pattern for z.
    639 This is an output for forward mode operations,
    640 and an input for reverse mode operations.
    641 
    642 \param vecad_sparsity
    643 The set with index \a i_v is the sparsity pattern for the vector v.
    644 This is an input for forward mode operations.
    645 For reverse mode operations,
    646 the sparsity pattern for z is added to the sparsity pattern for v.
    647 
    648 \par Checked Assertions
    649 \li NumArg(op) == 3
    650 \li NumRes(op) == 1
    651 \li 0         <  \a arg[0]
    652 \li \a arg[0] < \a num_combined
    653 \li i_v       < \a vecad_sparsity.n_set()
    654 <!-- end sparse_load_op -->
     645\copydetails sparse_load_op
    655646
    656647\param var_jacobian
    657 \a var_jacobian[i_z] 
    658 is false (true) if the Jacobian of G with respect to z is always zero 
     648\a var_jacobian[i_z]
     649is false (true) if the Jacobian of G with respect to z is always zero
    659650(many be non-zero).
    660651
    661652\param vecad_jacobian
    662 \a vecad_jacobian[i_v] 
    663 is false (true) if the Jacobian with respect to x is always zero 
     653\a vecad_jacobian[i_v]
     654is false (true) if the Jacobian with respect to x is always zero
    664655(may be non-zero).
    665656On input, it corresponds to the function G,
     
    671662        OpCode             op             ,
    672663        size_t             i_z            ,
    673         const addr_t*      arg            , 
     664        const addr_t*      arg            ,
    674665        size_t             num_combined   ,
    675666        const size_t*      combined       ,
  • trunk/cppad/local/rev_jac_sweep.hpp

    r3718 r3719  
    351351                        case DisOp:
    352352                        CPPAD_ASSERT_NARG_NRES(op, 2, 1);
    353                         // derivative is identically zero
     353                        // derivative is identically zero but dependency is not
     354                        if( dependency ) reverse_sparse_jacobian_unary_op(
     355                                i_var, arg[1], var_sparsity
     356                        );
    354357                        break;
    355358                        // -------------------------------------------------
     
    414417                        case LdpOp:
    415418                        reverse_sparse_jacobian_load_op(
     419                                dependency,
    416420                                op,
    417421                                i_var,
     
    427431                        case LdvOp:
    428432                        reverse_sparse_jacobian_load_op(
     433                                dependency,
    429434                                op,
    430435                                i_var,
     
    556561
    557562                        case StppOp:
    558                         // sparsity cannot proagate through a parameter
     563                        // does not affect sparsity or dependency when both are parameters
    559564                        CPPAD_ASSERT_NARG_NRES(op, 3, 0);
    560565                        break;
     
    563568                        case StpvOp:
    564569                        reverse_sparse_jacobian_store_op(
     570                                dependency,
    565571                                op,
    566572                                arg,
     
    575581                        case StvpOp:
    576582                        CPPAD_ASSERT_NARG_NRES(op, 3, 0);
     583                        // storing a parameter only affects dependency
     584                        reverse_sparse_jacobian_store_op(
     585                                dependency,
     586                                op,
     587                                arg,
     588                                num_vecad_ind,
     589                                vecad_ind.data(),
     590                                var_sparsity,
     591                                vecad_sparsity
     592                        );
    577593                        break;
    578594                        // -------------------------------------------------
     
    580596                        case StvvOp:
    581597                        reverse_sparse_jacobian_store_op(
     598                                dependency,
    582599                                op,
    583600                                arg,
  • trunk/cppad/local/store_op.hpp

    r3322 r3719  
    44
    55/* --------------------------------------------------------------------------
    6 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-14 Bradley M. Bell
     6CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-15 Bradley M. Bell
    77
    88CppAD is distributed under multiple licenses. This distribution is under
    9 the terms of the 
     9the terms of the
    1010                    Eclipse Public License Version 1.0.
    1111
     
    1919Changing the current value of a VecAD element.
    2020*/
    21 /*!
    22 Shared documentation for zero order forward implementation of
     21/*
     22==============================================================================
     23<!-- define preamble -->
     24The C++ source code corresponding to this operation is
     25\verbatim
     26        v[x] = y
     27\endverbatim
     28where v is a VecAD<Base> vector, x is an AD<Base> object,
     29and y is AD<Base> or Base objects.
     30We define the index corresponding to v[x] by
     31\verbatim
     32        i_v_x = index_by_ind[ arg[0] + i_vec ]
     33\endverbatim
     34where i_vec is defined under the heading arg[1] below:
     35<!-- end preamble -->
     36==============================================================================
     37*/
     38/*!
     39Shared documentation for zero order forward implementation of
    2340op = StppOp, StpvOp, StvpOp, or StvvOp (not called).
    2441
     42<!-- replace preamble -->
    2543The C++ source code corresponding to this operation is
    2644\verbatim
     
    2846\endverbatim
    2947where v is a VecAD<Base> vector, x is an AD<Base> object,
    30 and y is AD<Base> or Base objects. 
     48and y is AD<Base> or Base objects.
    3149We define the index corresponding to v[x] by
    3250\verbatim
     
    3452\endverbatim
    3553where i_vec is defined under the heading arg[1] below:
     54<!-- end preamble -->
    3655
    3756\tparam Base
     
    4766arg[0]
    4867\n
    49 is the offset of this VecAD vector relative to the beginning 
     68is the offset of this VecAD vector relative to the beginning
    5069of the isvar_by_ind and index_by_ind arrays.
    5170\n
    52 \n 
    53 arg[1] 
    54 \n
    55 If this is a StppOp or StpvOp operation (if x is a parameter), 
     71\n
     72arg[1]
     73\n
     74If this is a StppOp or StpvOp operation (if x is a parameter),
    5675i_vec is defined by
    5776\verbatim
     
    83102
    84103\param isvar_by_ind
    85 If y is a varable (StpvOp and StvvOp cases), 
     104If y is a varable (StpvOp and StvvOp cases),
    86105<code>isvar_by_ind[ arg[0] + i_vec ] </code> is set to true.
    87 Otherwise y is a paraemter (StppOp and StvpOp cases) and 
     106Otherwise y is a paraemter (StppOp and StvpOp cases) and
    88107<code>isvar_by_ind[ arg[0] + i_vec ] </code> is set to false.
    89108
     
    97116\li Check that the index is with in range; i.e.
    98117<code>i_vec < index_by_ind[ arg[0] - 1 ]</code>
    99 Note that, if x is a parameter, 
     118Note that, if x is a parameter,
    100119the corresponding vector index and it does not change.
    101120In this case, the error above should be detected during tape recording.
    102121
    103 \par Checked Assertions 
     122\par Checked Assertions
    104123\li NumArg(op) == 3
    105124\li NumRes(op) == 0
     
    110129inline void forward_store_op_0(
    111130        size_t         i_z         ,
    112         const addr_t*  arg         , 
     131        const addr_t*  arg         ,
    113132        size_t         num_par     ,
    114133        size_t         cap_order   ,
     
    121140}
    122141/*!
    123 Shared documnetation for sparsity operations corresponding to 
     142Shared documnetation for sparsity operations corresponding to
    124143op = StpvOp or StvvOp (not called).
    125 
    126 <!-- define sparse_store_op -->
    127 The C++ source code corresponding to this operation is
    128 \verbatim
    129         v[x] = y
    130 \endverbatim
    131 where v is a VecAD<Base> vector, x is an AD<Base> object,
    132 and y is AD<Base> or Base objects.
    133 We define the index corresponding to v[x] by
    134 \verbatim
    135         i_v_x = combined[ arg[0] + i_vec ]
    136 \endverbatim
    137 where i_vec is defined under the heading \a arg[1] below:
    138144
    139145\tparam Vector_set
     
    142148
    143149\param op
    144 is the code corresponding to this operator; i.e., StpvOp or StvvOp
    145 (only used for error checking).
     150is the code corresponding to this operator;
     151i.e., StpvOp, StvpOp, or StvvOp.
    146152
    147153\param arg
     
    150156is the offset corresponding to this VecAD vector in the combined array.
    151157\n
    152 \n 
     158\n
    153159\a arg[2]
    154160\n
    155 The set with index \a arg[2] in \a var_sparsity 
     161The set with index \a arg[2] in \a var_sparsity
    156162is the sparsity pattern corresponding to y.
    157 (Note that \a arg[2] > 0 because y is a variable.) 
     163(Note that \a arg[2] > 0 because y is a variable.)
    158164
    159165\param num_combined
     
    170176
    171177\param var_sparsity
    172 The set  with index \a arg[2] in \a var_sparsity 
     178The set  with index \a arg[2] in \a var_sparsity
    173179is the sparsity pattern for y.
    174180This is an input for forward mode operations.
     
    177183
    178184\param vecad_sparsity
    179 The set with index \a i_v in \a vecad_sparsity 
     185The set with index \a i_v in \a vecad_sparsity
    180186is the sparsity pattern for v.
    181187This is an input for reverse mode operations.
     
    183189to the sparsity pattern for the vector v.
    184190
    185 \par Checked Assertions 
     191\par Checked Assertions
    186192\li NumArg(op) == 3
    187193\li NumRes(op) == 0
     
    190196\li \a arg[2] < \a var_sparsity.n_set()
    191197\li i_v       < \a vecad_sparsity.n_set()
    192 <!-- end sparse_store_op -->
    193198*/
    194199template <class Vector_set>
    195200inline void sparse_store_op(
    196201        OpCode         op             ,
    197         const addr_t*  arg            , 
     202        const addr_t*  arg            ,
    198203        size_t         num_combined   ,
    199204        const size_t*  combined       ,
     
    214219inline void forward_store_pp_op_0(
    215220        size_t         i_z         ,
    216         const addr_t*  arg         , 
     221        const addr_t*  arg         ,
    217222        size_t         num_par     ,
    218223        size_t         cap_order   ,
     
    222227{       size_t i_vec = arg[1];
    223228
    224         // Because the index is a parameter, this indexing error should be 
     229        // Because the index is a parameter, this indexing error should be
    225230        // caught and reported to the user when the tape is recording.
    226231        CPPAD_ASSERT_UNKNOWN( i_vec < index_by_ind[ arg[0] - 1 ] );
     
    243248inline void forward_store_pv_op_0(
    244249        size_t         i_z         ,
    245         const addr_t*  arg         , 
     250        const addr_t*  arg         ,
    246251        size_t         num_par     ,
    247252        size_t         cap_order   ,
     
    251256{       size_t i_vec = arg[1];
    252257
    253         // Because the index is a parameter, this indexing error should be 
     258        // Because the index is a parameter, this indexing error should be
    254259        // caught and reported to the user when the tape is recording.
    255260        CPPAD_ASSERT_UNKNOWN( i_vec < index_by_ind[ arg[0] - 1 ] );
     
    271276inline void forward_store_vp_op_0(
    272277        size_t         i_z         ,
    273         const addr_t*  arg         , 
     278        const addr_t*  arg         ,
    274279        size_t         num_par     ,
    275280        size_t         cap_order   ,
     
    277282        bool*          isvar_by_ind   ,
    278283        size_t*        index_by_ind   )
    279 {       
     284{
    280285        size_t i_vec = Integer( taylor[ arg[1] * cap_order + 0 ] );
    281         CPPAD_ASSERT_KNOWN( 
     286        CPPAD_ASSERT_KNOWN(
    282287                i_vec < index_by_ind[ arg[0] - 1 ] ,
    283288                "VecAD: index during zero order forward sweep is out of range"
     
    301306inline void forward_store_vv_op_0(
    302307        size_t         i_z         ,
    303         const addr_t*  arg         , 
     308        const addr_t*  arg         ,
    304309        size_t         num_par     ,
    305310        size_t         cap_order   ,
     
    307312        bool*          isvar_by_ind   ,
    308313        size_t*        index_by_ind   )
    309 {       
     314{
    310315        size_t i_vec = Integer( taylor[ arg[1] * cap_order + 0 ] );
    311         CPPAD_ASSERT_KNOWN( 
     316        CPPAD_ASSERT_KNOWN(
    312317                i_vec < index_by_ind[ arg[0] - 1 ] ,
    313318                "VecAD: index during zero order forward sweep is out of range"
     
    325330Forward mode sparsity operations for StpvOp and StvvOp
    326331
     332<!-- replace preamble -->
     333The C++ source code corresponding to this operation is
     334\verbatim
     335        v[x] = y
     336\endverbatim
     337where v is a VecAD<Base> vector, x is an AD<Base> object,
     338and y is AD<Base> or Base objects.
     339We define the index corresponding to v[x] by
     340\verbatim
     341        i_v_x = index_by_ind[ arg[0] + i_vec ]
     342\endverbatim
     343where i_vec is defined under the heading arg[1] below:
     344<!-- end preamble -->
     345
     346\param dependency
     347is this a dependency (or sparsity) calculation.
     348
    327349\copydetails sparse_store_op
    328350*/
    329351template <class Vector_set>
    330352inline void forward_sparse_store_op(
     353        bool                dependency     ,
    331354        OpCode              op             ,
    332         const addr_t*       arg            , 
     355        const addr_t*       arg            ,
    333356        size_t              num_combined   ,
    334357        const size_t*       combined       ,
     
    344367        CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < var_sparsity.n_set() );
    345368
    346         vecad_sparsity.binary_union(i_v, i_v, arg[2], var_sparsity);
     369        if( dependency & ( (op == StvvOp) | (op == StvpOp) ) )
     370                vecad_sparsity.binary_union(i_v, i_v, arg[1], var_sparsity);
     371
     372        if( (op == StpvOp) | (op == StvvOp ) )
     373                vecad_sparsity.binary_union(i_v, i_v, arg[2], var_sparsity);
    347374
    348375        return;
     
    350377
    351378/*!
    352 Reverse mode sparsity operations for StpvOp and StvvOp
     379Reverse mode sparsity operations for StpvOp, StvpOp, and StvvOp
     380
     381<!-- replace preamble -->
     382The C++ source code corresponding to this operation is
     383\verbatim
     384        v[x] = y
     385\endverbatim
     386where v is a VecAD<Base> vector, x is an AD<Base> object,
     387and y is AD<Base> or Base objects.
     388We define the index corresponding to v[x] by
     389\verbatim
     390        i_v_x = index_by_ind[ arg[0] + i_vec ]
     391\endverbatim
     392where i_vec is defined under the heading arg[1] below:
     393<!-- end preamble -->
    353394
    354395This routine is given the sparsity patterns for
    355 G(v[x], y , w , u ... ) and it uses them to compute the 
    356 sparsity patterns for 
     396G(v[x], y , w , u ... ) and it uses them to compute the
     397sparsity patterns for
    357398\verbatim
    358399        H(y , w , u , ... ) = G[ v[x], y , w , u , ... ]
    359400\endverbatim
    360401
    361 <!-- replace sparse_store_op -->
    362 The C++ source code corresponding to this operation is
    363 \verbatim
    364         v[x] = y
    365 \endverbatim
    366 where v is a VecAD<Base> vector, x is an AD<Base> object,
    367 and y is AD<Base> or Base objects.
    368 We define the index corresponding to v[x] by
    369 \verbatim
    370         i_v_x = combined[ arg[0] + i_vec ]
    371 \endverbatim
    372 where i_vec is defined under the heading \a arg[1] below:
    373 
    374 \tparam Vector_set
    375 is the type used for vectors of sets. It can be either
    376 \c sparse_pack, \c sparse_set, or \c sparse_list.
    377 
    378 \param op
    379 is the code corresponding to this operator; i.e., StpvOp or StvvOp
    380 (only used for error checking).
    381 
    382 \param arg
    383 \n
    384 \a arg[0]
    385 is the offset corresponding to this VecAD vector in the combined array.
    386 \n
    387 \n
    388 \a arg[2]
    389 \n
    390 The set with index \a arg[2] in \a var_sparsity
    391 is the sparsity pattern corresponding to y.
    392 (Note that \a arg[2] > 0 because y is a variable.)
    393 
    394 \param num_combined
    395 is the total number of elements in the VecAD address array.
    396 
    397 \param combined
    398 \a combined [ arg[0] - 1 ]
    399 is the index of the set in \a vecad_sparsity corresponding
    400 to the sparsity pattern for the vector v.
    401 We use the notation i_v below which is defined by
    402 \verbatim
    403         i_v = combined[ \a arg[0] - 1 ]
    404 \endverbatim
    405 
    406 \param var_sparsity
    407 The set  with index \a arg[2] in \a var_sparsity
    408 is the sparsity pattern for y.
    409 This is an input for forward mode operations.
    410 For reverse mode operations:
    411 The sparsity pattern for v is added to the spartisy pattern for y.
    412 
    413 \param vecad_sparsity
    414 The set with index \a i_v in \a vecad_sparsity
    415 is the sparsity pattern for v.
    416 This is an input for reverse mode operations.
    417 For forward mode operations, the sparsity pattern for y is added
    418 to the sparsity pattern for the vector v.
    419 
    420 \par Checked Assertions
    421 \li NumArg(op) == 3
    422 \li NumRes(op) == 0
    423 \li 0 <  \a arg[0]
    424 \li \a arg[0] < \a num_combined
    425 \li \a arg[2] < \a var_sparsity.n_set()
    426 \li i_v       < \a vecad_sparsity.n_set()
    427 <!-- end sparse_store_op -->
     402\param dependency
     403is this a dependency (or sparsity) calculation.
     404
     405\copydetails sparse_store_op
    428406*/
    429407template <class Vector_set>
    430408inline void reverse_sparse_jacobian_store_op(
     409        bool               dependency      ,
    431410        OpCode             op              ,
    432         const addr_t*      arg             , 
     411        const addr_t*      arg             ,
    433412        size_t             num_combined    ,
    434413        const size_t*      combined        ,
     
    444423        CPPAD_ASSERT_UNKNOWN( size_t(arg[2]) < var_sparsity.n_set() );
    445424
    446         var_sparsity.binary_union(arg[2], arg[2], i_v, vecad_sparsity);
     425        if( dependency & ( (op == StvpOp) | (op == StvvOp) ) )
     426                var_sparsity.binary_union(arg[1], arg[1], i_v, vecad_sparsity);
     427        if( (op == StpvOp) | (op == StvvOp) )
     428                var_sparsity.binary_union(arg[2], arg[2], i_v, vecad_sparsity);
    447429
    448430        return;
     
    451433/*!
    452434Reverse mode sparsity operations for StpvOp and StvvOp
     435
     436<!-- replace preamble -->
     437The C++ source code corresponding to this operation is
     438\verbatim
     439        v[x] = y
     440\endverbatim
     441where v is a VecAD<Base> vector, x is an AD<Base> object,
     442and y is AD<Base> or Base objects.
     443We define the index corresponding to v[x] by
     444\verbatim
     445        i_v_x = index_by_ind[ arg[0] + i_vec ]
     446\endverbatim
     447where i_vec is defined under the heading arg[1] below:
     448<!-- end preamble -->
    453449
    454450This routine is given the sparsity patterns for
    455451G(v[x], y , w , u ... )
    456 and it uses them to compute the sparsity patterns for 
     452and it uses them to compute the sparsity patterns for
    457453\verbatim
    458454        H(y , w , u , ... ) = G[ v[x], y , w , u , ... ]
    459455\endverbatim
    460456
    461 <!-- replace sparse_store_op -->
    462 The C++ source code corresponding to this operation is
    463 \verbatim
    464         v[x] = y
    465 \endverbatim
    466 where v is a VecAD<Base> vector, x is an AD<Base> object,
    467 and y is AD<Base> or Base objects.
    468 We define the index corresponding to v[x] by
    469 \verbatim
    470         i_v_x = combined[ arg[0] + i_vec ]
    471 \endverbatim
    472 where i_vec is defined under the heading \a arg[1] below:
    473 
    474 \tparam Vector_set
    475 is the type used for vectors of sets. It can be either
    476 \c sparse_pack, \c sparse_set, or \c sparse_list.
    477 
    478 \param op
    479 is the code corresponding to this operator; i.e., StpvOp or StvvOp
    480 (only used for error checking).
    481 
    482 \param arg
    483 \n
    484 \a arg[0]
    485 is the offset corresponding to this VecAD vector in the combined array.
    486 \n
    487 \n
    488 \a arg[2]
    489 \n
    490 The set with index \a arg[2] in \a var_sparsity
    491 is the sparsity pattern corresponding to y.
    492 (Note that \a arg[2] > 0 because y is a variable.)
    493 
    494 \param num_combined
    495 is the total number of elements in the VecAD address array.
    496 
    497 \param combined
    498 \a combined [ arg[0] - 1 ]
    499 is the index of the set in \a vecad_sparsity corresponding
    500 to the sparsity pattern for the vector v.
    501 We use the notation i_v below which is defined by
    502 \verbatim
    503         i_v = combined[ \a arg[0] - 1 ]
    504 \endverbatim
    505 
    506 \param var_sparsity
    507 The set  with index \a arg[2] in \a var_sparsity
    508 is the sparsity pattern for y.
    509 This is an input for forward mode operations.
    510 For reverse mode operations:
    511 The sparsity pattern for v is added to the spartisy pattern for y.
    512 
    513 \param vecad_sparsity
    514 The set with index \a i_v in \a vecad_sparsity
    515 is the sparsity pattern for v.
    516 This is an input for reverse mode operations.
    517 For forward mode operations, the sparsity pattern for y is added
    518 to the sparsity pattern for the vector v.
    519 
    520 \par Checked Assertions
    521 \li NumArg(op) == 3
    522 \li NumRes(op) == 0
    523 \li 0 <  \a arg[0]
    524 \li \a arg[0] < \a num_combined
    525 \li \a arg[2] < \a var_sparsity.n_set()
    526 \li i_v       < \a vecad_sparsity.n_set()
    527 <!-- end sparse_store_op -->
     457\copydetails sparse_store_op
    528458
    529459\param var_jacobian
    530 \a var_jacobian[ \a arg[2] ] 
    531 is false (true) if the Jacobian of G with respect to y is always zero 
     460\a var_jacobian[ \a arg[2] ]
     461is false (true) if the Jacobian of G with respect to y is always zero
    532462(may be non-zero).
    533463
    534464\param vecad_jacobian
    535 \a vecad_jacobian[i_v] 
    536 is false (true) if the Jacobian with respect to x is always zero 
     465\a vecad_jacobian[i_v]
     466is false (true) if the Jacobian with respect to x is always zero
    537467(may be non-zero).
    538468On input, it corresponds to the function G,
     
    542472inline void reverse_sparse_hessian_store_op(
    543473        OpCode             op           ,
    544         const addr_t*      arg          , 
     474        const addr_t*      arg          ,
    545475        size_t             num_combined ,
    546476        const size_t*      combined     ,
  • trunk/example/dependency.cpp

    r3718 r3719  
    5555// BEGIN C++
    5656# include <cppad/cppad.hpp>
     57namespace {
     58        double heavyside(const double& x)
     59        {       if( x <= 0.0 )
     60                        return 0.0;
     61                return 1.0;
     62        }
     63        CPPAD_DISCRETE_FUNCTION(double, heavyside)
     64}
    5765
    5866bool dependency(void)
     
    6169        using CppAD::NearEqual;
    6270
     71        // VecAD object for use later
     72        CppAD::VecAD<double> vec_ad(2);
     73        vec_ad[0] = 0.0;
     74        vec_ad[1] = 1.0;
     75
    6376        // domain space vector
    64         size_t n  = 3;
     77        size_t n  = 5;
    6578        CPPAD_TESTVECTOR(AD<double>) ax(n);
    6679        for(size_t j = 0; j < n; j++)
     
    8093        ay[m1-1] = CondExpLe( ax[1], azero, azero, aone);
    8194        ay[m1-2] = CondExpLe( azero, ax[2], azero, aone);
     95        ay[m1-3] = heavyside( ax[3] );
     96        ay[m1-4] = vec_ad[ ax[4] - AD<double>(4.0) ];
    8297
    8398        // create f: x -> y and stop tape recording
     
    109124        // -----------------------------------------------------------
    110125        // RevSparseJac and set dependency
    111         CPPAD_TESTVECTOR( std::set<size_t> ) eye_set(m), depend_set(m);
     126        CppAD::vector<    std::set<size_t> > eye_set(m), depend_set(m);
    112127        for(size_t i = 0; i < m; i++)
    113128        {       ok &= eye_set[i].empty();
  • trunk/omh/whats_new/whats_new_15.omh

    r3718 r3719  
    6464assist you in learning about changes between various versions of CppAD.
    6565
    66 $head 09-01$$
     66$head 09-02$$
    6767The $cref/dependency pattern/dependency.cpp/Dependency Pattern/$$
    68 was not being computed correctly for the $cref sign$$ function.
     68was not being computed correctly for the
     69$cref sign$$, $cref Discrete$$, and $cref VecAD$$ operations.
    6970This has been fixed.
    7071(It could have caused problems using $cref optimize$$ with an $cref ADFun$$
    71 that used the $code sign$$ function.).
     72that used any of these operations.)
    7273
    7374$head 08-31$$
    7475$list number$$
     76Mention the fact that using checkpoint functions can make
     77$cref/recordings faster/checkpoint/Purpose/Faster Recording/$$.
     78$lnext
    7579Add the
    7680$cref/pack/atomic_option/atomic_sparsity/pack_sparsity_enum/$$
Note: See TracChangeset for help on using the changeset viewer.