Changeset 3605


Ignore:
Timestamp:
Jan 20, 2015 10:19:58 AM (5 years ago)
Author:
bradbell
Message:

merge to branch: branches/compare_op
from repository: https://github.com/coin-or/CppAD
start hash code: 45315907c70e5b383d984fb9498b54a474001af0
end hash code: 6e46df5c850ecd58d7a886db4043bc3f2d4579d1

commit 6e46df5c850ecd58d7a886db4043bc3f2d4579d1
Author: Brad Bell <bradbell@…>
Date: Tue Jan 20 08:16:57 2015 -0700

Always return f.compare_change_op_index() == 0 after f.optimize().


checkpoint.hpp: ignore comparison operators.
fun_construct.hpp: remove double initilaization of values.
compare_change.cpp: demonstrate more features of new interface.
whats_new_15.omh: prepare for merging this branch into master.
wish_list.omh: update wish list item to new compare_change interface.

Location:
branches/compare_op
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • branches/compare_op/cppad/local/ad_fun.hpp

    r3603 r3605  
    7777// Private member variables
    7878private:
     79        /// Has this ADFun object been optmized
     80        bool has_been_optimized_;
     81
    7982        /// Check for nan's and report message to user (default value is true).
    8083        bool check_for_nan_;
     
    427430        /// operator index for the count-th  comparison change
    428431        size_t compare_change_op_index(void) const
    429         {       return compare_change_op_index_; }
     432        {       if( has_been_optimized_ )
     433                        return 0;
     434                return compare_change_op_index_;
     435        }
    430436
    431437        /// calculate entire Jacobian
  • branches/compare_op/cppad/local/checkpoint.hpp

    r3301 r3605  
    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
     
    197197                // now optimize (we expect to use this function many times).
    198198                f_.optimize();
     199                // now disable checking of comparison opertaions
     200                // 2DO: add a debugging mode that checks for changes and aborts
     201                f_.compare_change_count(0);
    199202        }
    200203        /*!
  • branches/compare_op/cppad/local/dependent.hpp

    r3603 r3605  
    279279
    280280        // some size_t values in ad_fun.hpp
     281        has_been_optimized_        = false;
    281282        compare_change_count_      = 1;
    282283        compare_change_number_     = 0;
  • branches/compare_op/cppad/local/fun_construct.hpp

    r3603 r3605  
    262262template <typename Base>
    263263ADFun<Base>::ADFun(void) :
     264has_been_optimized_(false),
    264265check_for_nan_(true) ,
    265266compare_change_count_(1),
     
    297298        //
    298299        // size_t objects
     300        has_been_optimized_        = f.has_been_optimized_;
    299301        check_for_nan_             = f.check_for_nan_;
    300302        compare_change_count_      = f.compare_change_count_;
     
    433435        Dependent(tape, y);
    434436
     437
    435438        // ad_fun.hpp member values not set by dependent
    436439        check_for_nan_ = true;
    437 
    438         // compare changes values
    439         compare_change_count_    = 1;
    440         compare_change_number_   = 0;
    441         compare_change_op_index_ = 0;
    442440
    443441        // allocate memory for one zero order taylor_ coefficient
  • branches/compare_op/cppad/local/independent.hpp

    r3604 r3605  
    8585
    8686$head abort_op_index$$
    87 The syntax that includes this parameter is not available when
    88 $cref/NDEBUG/Faq/Speed/NDEBUG/$$ is defined.
     87$index abort_op_index$$
    8988It specifies the operator index at which the execution is be aborted
    9089by calling the CppAD $cref/error handler/ErrorHandler/$$.
     
    9392this operator index; see
    9493$cref/purpose/compare_change/op_index/Purpose/$$.
    95 
     94No abort will occur if $icode abort_op_index$$ is zero,
     95of if $cref/NDEBUG/Faq/Speed/NDEBUG/$$ is defined.
    9696
    9797$head VectorAD$$
  • branches/compare_op/cppad/local/optimize.hpp

    r3598 r3605  
    28042804        play_.get(rec);
    28052805
     2806        // set flag so this function knows it has been optimized
     2807        has_been_optimized_ = true;
     2808
    28062809        // free memory allocated for sparse Jacobian calculation
    28072810        // (the results are no longer valid)
  • branches/compare_op/example/compare_change.cpp

    r3604 r3605  
    116116        size_t op_index = f.compare_change_op_index();
    117117
     118        // Local block during which default CppAD error handler is replaced.
    118119        // If you do not replace the default CppAD error handler,
    119120        // and you run in the debugger, you will be able to inspect the
    120121        // call stack and see that 'if( x < y )' is where the comparison is.
    121         CppAD::ErrorHandler local_error_handler(error_handler);
     122        bool caught_error = false;
     123        {       CppAD::ErrorHandler local_error_handler(error_handler);
    122124
    123         bool caught_error = false;
    124         std::string check_msg =
    125                 "Operator index equals abort_op_index in Independent";
    126         try {
    127                 // determine the operation index where the change occurred
    128                 CppAD::Independent(ax, op_index);
    129                 ay[0] = Minimum(ax[0], ax[1]);
    130         }
    131         catch( error_info info )
    132         {       caught_error = true;
    133                 ok          &= info.known;
    134                 ok          &= info.msg == check_msg;
    135                 // Must abort the recording so we can start a new one
    136                 // (and to avoid a memory leak).
    137                 AD<double>::abort_recording();
     125                std::string check_msg =
     126                        "Operator index equals abort_op_index in Independent";
     127                try {
     128                        // determine the operation index where the change occurred
     129                        CppAD::Independent(ax, op_index);
     130                        ay[0] = Minimum(ax[0], ax[1]);
     131                }
     132                catch( error_info info )
     133                {       caught_error = true;
     134                        ok          &= info.known;
     135                        ok          &= info.msg == check_msg;
     136                        // Must abort the recording so we can start a new one
     137                        // (and to avoid a memory leak).
     138                        AD<double>::abort_recording();
     139                }
    138140        }
    139141        ok &= caught_error;
     
    148150        ok  &= (f.compare_change_op_index() == 0);
    149151
     152        // now demonstrate that compare_change_number works for an optimized
     153        // tape (note that compare_change_op_index is always zero after optimize)
     154        f.optimize();
     155        f.compare_change_count(1);
     156        y    = f.Forward(0, x);
     157        ok  &= (y[0] == x[0]);
     158        ok  &= (y[0] != Minimum(x[0], x[1]));
     159        ok  &= (f.compare_change_number()   == 1);
     160        ok  &= (f.compare_change_op_index() == 0);
     161
     162        // now retape to get the a tape that agrees with the algorithm
     163        ax[0] = x[0];
     164        ax[1] = x[1];
     165        Independent(ax);
     166        ay[0] = Minimum(ax[0], ax[1]);
     167        f.Dependent(ax, ay);
     168        y    = f.Forward(0, x);
     169        ok  &= (y[0] == x[1]);
     170        ok  &= (y[0] == Minimum(x[0], x[1]));
     171        ok  &= (f.compare_change_number()   == 0);
     172        ok  &= (f.compare_change_op_index() == 0);
     173
    150174        return ok;
    151175}
  • branches/compare_op/omh/forward/compare_change.omh

    r3604 r3605  
    134134will also be zero.
    135135If $icode count$$ is zero,
     136if the function $icode f$$ has been $cref/optimized/optimize/$$,
    136137or if no calls to $icode%f%.Forward(0, %x%)%$$ follow the previous
    137138setting of $icode count$$,
     
    147148See $cref/abort_op_index/Independent/abort_op_index/$$ in the syntax
    148149$codei%
    149         Independent(%x%, %op_index%)
     150        Independent(%x%, %abort_op_index%)
    150151%$$
    151 Note that the operator index $icode op_index$$,
    152 must correspond to the original tape,
    153 and not an $cref/optimized/optimize/$$ version of the tape.
    154152
    155153$children%
  • branches/compare_op/omh/whats_new/whats_new_15.omh

    r3596 r3605  
    3131assist you in learning about changes between various versions of CppAD.
    3232
    33 $head compare_op branch$$
    34 $list number$$
    35 The $cref CompareChange$$ function
    36 $codei%
    37         %f%.CompareChange()
    38 %$$
    39 is now available when $cref/NDEBUG/Faq/Speed/NDEBUG/$$ is defined
    40 (it used to not be so).
    41 In addition, it returns correct values after
     33$head 01-20$$
     34The new $cref compare_change$$ interface has been created
     35and the old $cref CompareChange$$ function has been deprecated;
     36see the $cref compare_change.cpp$$ example.
     37This enables one to determine the source code during taping
     38that corresponds to changes in the comparisons during
     39$cref/zero order forward/forward_zero/$$ operations; see
     40$cref/abort_op_index/Independent/abort_op_index/$$.
     41$pre
     42
     43$$
     44This new $cref compare_change$$ interface can detect comparison changes
     45even if $cref/NDEBUG/Faq/Speed/NDEBUG/$$ is defined and
     46even if $cref/f.optimize()/optimize/$$ has been called.
     47The deprecated function $code CompareChange$$ used to always return zero after
    4248$codei%
    4349        %f%.optimize()
    4450%$$
    45 is called (it used to always return zero after $cref optimize$$).
    46 See the wish list
    47 $cref/optimize compare_change/WishList/Optimization/CompareChange/$$ entry.
    48 $lnext
    49 The $cref optimize.cpp$$ example was changed to include a demonstration
    50 of how $cref CompareChange$$ can be used with an optimized tape.
    51 $lend
     51and was not even defined when $code NDEBUG$$ was defined.
     52There was a resulting speed effect for this; see the wish list
     53$cref/compare change/WishList/Optimization/Comparison Changes/$$ entry.
    5254
    5355$head 01-09$$
  • branches/compare_op/omh/wish_list.omh

    r3597 r3605  
    175175$index tape, optimize$$
    176176
    177 $subhead CompareChange$$
    178 The $code ComOp$$ operators are no longer removed by
    179 the $cref optimize$$ procedure (so that $cref CompareChange$$
    180 can be used after optimization).
     177$subhead Comparison Changes$$
     178The comparison operators used to not be taped when
     179$cref/NDEBUG/Faq/Speed/NDEBUG/$$ was defined.
     180They are now taped so that the $cref compare_change$$ interface
     181works even for compiler optimize code.
    181182This caused a significant slow down in the
    182 $cref cppad_det_lu.cpp$$ speed test.
    183 For the other $cref speed_cppad$$ tests, this had little
    184 or no effect.
    185 Perhaps $code optimize$$ should have an option whereby
    186 the user can choose to have these operators removed.
     183$cref cppad_det_lu.cpp$$ speed test (with no options specified).
     184Perhaps there should be an option to skip the comparison taping.
    187185
    188186$subhead Expression Hashing$$
Note: See TracChangeset for help on using the changeset viewer.