Changeset 1586


Ignore:
Timestamp:
Nov 23, 2009 10:53:08 AM (11 years ago)
Author:
bradbell
Message:

branches/multiple_result:

seq_property.cpp: account for NonOp? placed at end of operation sequence.
*/optimize.cpp: account for NonOp? placed at end of operation sequence.
player.hpp: remove special cases (all return index to last variable now).
prototype_op.hpp: changes to operator functions so primary result is last one.
asin_op.hpp: changes to operator functions so primary result is last one.
store_op.hpp: note that since store has no result, i_z points to previous var.
optimize.hpp: keep NonOp? in all cases (marks beginning and end of op sequence).
atan_op.hpp: note that since store has no result, i_z points to previous var.
forward0sweep.hpp: clean up now that all operators use last for primary result.
recorder.hpp: clean up now that all operators use last for primary result.
forward_sweep.hpp: clean up now that all operators use last for primary result.
reverse_sweep.hpp: convert last few operators to use last for primary result.
acos_op.hpp: note that since store has no result, i_z points to previous var.

Location:
branches/multiple_result
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • branches/multiple_result/cppad/local/acos_op.hpp

    r1447 r1586  
    4949        CPPAD_ASSERT_UNKNOWN( NumArg(AcosOp) == 1 );
    5050        CPPAD_ASSERT_UNKNOWN( NumRes(AcosOp) == 2 );
    51         CPPAD_ASSERT_UNKNOWN( i_x < i_z );
     51        CPPAD_ASSERT_UNKNOWN( i_x + 1 < i_z );
    5252        CPPAD_ASSERT_UNKNOWN( j < nc_taylor );
    5353
     
    5555        Base* x = taylor + i_x * nc_taylor;
    5656        Base* z = taylor + i_z * nc_taylor;
    57         Base* b = z      +       nc_taylor;  // called y in documentation
     57        Base* b = z      -       nc_taylor;  // called y in documentation
    5858
    5959        size_t k;
     
    110110        CPPAD_ASSERT_UNKNOWN( NumArg(AcosOp) == 1 );
    111111        CPPAD_ASSERT_UNKNOWN( NumRes(AcosOp) == 2 );
    112         CPPAD_ASSERT_UNKNOWN( i_x < i_z );
     112        CPPAD_ASSERT_UNKNOWN( i_x + 1 < i_z );
    113113        CPPAD_ASSERT_UNKNOWN( 0 < nc_taylor );
    114114
     
    116116        Base* x = taylor + i_x * nc_taylor;
    117117        Base* z = taylor + i_z * nc_taylor;
    118         Base* b = z      +       nc_taylor; // called y in documentation
     118        Base* b = z      -       nc_taylor; // called y in documentation
    119119
    120120        z[0] = acos( x[0] );
     
    150150        CPPAD_ASSERT_UNKNOWN( NumArg(AcosOp) == 1 );
    151151        CPPAD_ASSERT_UNKNOWN( NumRes(AcosOp) == 2 );
    152         CPPAD_ASSERT_UNKNOWN( i_x < i_z );
     152        CPPAD_ASSERT_UNKNOWN( i_x + 1 < i_z );
    153153        CPPAD_ASSERT_UNKNOWN( d < nc_taylor );
    154154        CPPAD_ASSERT_UNKNOWN( d < nc_partial );
     
    163163
    164164        // Taylor coefficients and partials corresponding to auxillary result
    165         const Base* b  = z  + nc_taylor; // called y in documentation
    166         Base* pb       = pz + nc_partial;
     165        const Base* b  = z  - nc_taylor; // called y in documentation
     166        Base* pb       = pz - nc_partial;
    167167
    168168        // number of indices to access
  • branches/multiple_result/cppad/local/asin_op.hpp

    r1447 r1586  
    4949        CPPAD_ASSERT_UNKNOWN( NumArg(AsinOp) == 1 );
    5050        CPPAD_ASSERT_UNKNOWN( NumRes(AsinOp) == 2 );
    51         CPPAD_ASSERT_UNKNOWN( i_x < i_z );
     51        CPPAD_ASSERT_UNKNOWN( i_x + 1 < i_z );
    5252        CPPAD_ASSERT_UNKNOWN( j < nc_taylor );
    5353
     
    5555        Base* x = taylor + i_x * nc_taylor;
    5656        Base* z = taylor + i_z * nc_taylor;
    57         Base* b = z      +       nc_taylor;  // called y in documentation
     57        Base* b = z      -       nc_taylor;  // called y in documentation
    5858
    5959        size_t k;
     
    110110        CPPAD_ASSERT_UNKNOWN( NumArg(AsinOp) == 1 );
    111111        CPPAD_ASSERT_UNKNOWN( NumRes(AsinOp) == 2 );
    112         CPPAD_ASSERT_UNKNOWN( i_x < i_z );
     112        CPPAD_ASSERT_UNKNOWN( i_x + 1 < i_z );
    113113        CPPAD_ASSERT_UNKNOWN( 0 < nc_taylor );
    114114
     
    116116        Base* x = taylor + i_x * nc_taylor;
    117117        Base* z = taylor + i_z * nc_taylor;
    118         Base* b = z      +       nc_taylor; // called y in documentation
     118        Base* b = z      -       nc_taylor; // called y in documentation
    119119
    120120        z[0] = asin( x[0] );
     
    150150        CPPAD_ASSERT_UNKNOWN( NumArg(AsinOp) == 1 );
    151151        CPPAD_ASSERT_UNKNOWN( NumRes(AsinOp) == 2 );
    152         CPPAD_ASSERT_UNKNOWN( i_x < i_z );
     152        CPPAD_ASSERT_UNKNOWN( i_x + 1 < i_z );
    153153        CPPAD_ASSERT_UNKNOWN( d < nc_taylor );
    154154        CPPAD_ASSERT_UNKNOWN( d < nc_partial );
     
    163163
    164164        // Taylor coefficients and partials corresponding to auxillary result
    165         const Base* b  = z  + nc_taylor; // called y in documentation
    166         Base* pb       = pz + nc_partial;
     165        const Base* b  = z  - nc_taylor; // called y in documentation
     166        Base* pb       = pz - nc_partial;
    167167
    168168        // number of indices to access
  • branches/multiple_result/cppad/local/atan_op.hpp

    r1447 r1586  
    4949        CPPAD_ASSERT_UNKNOWN( NumArg(AtanOp) == 1 );
    5050        CPPAD_ASSERT_UNKNOWN( NumRes(AtanOp) == 2 );
    51         CPPAD_ASSERT_UNKNOWN( i_x < i_z );
     51        CPPAD_ASSERT_UNKNOWN( i_x + 1 < i_z );
    5252        CPPAD_ASSERT_UNKNOWN( j < nc_taylor );
    5353
     
    5555        Base* x = taylor + i_x * nc_taylor;
    5656        Base* z = taylor + i_z * nc_taylor;
    57         Base* b = z      +       nc_taylor;  // called y in documentation
     57        Base* b = z      -       nc_taylor;  // called y in documentation
    5858
    5959        size_t k;
     
    101101        CPPAD_ASSERT_UNKNOWN( NumArg(AtanOp) == 1 );
    102102        CPPAD_ASSERT_UNKNOWN( NumRes(AtanOp) == 2 );
    103         CPPAD_ASSERT_UNKNOWN( i_x < i_z );
     103        CPPAD_ASSERT_UNKNOWN( i_x + 1 < i_z );
    104104        CPPAD_ASSERT_UNKNOWN( 0 < nc_taylor );
    105105
     
    107107        Base* x = taylor + i_x * nc_taylor;
    108108        Base* z = taylor + i_z * nc_taylor;
    109         Base* b = z      +       nc_taylor; // called y in documentation
     109        Base* b = z      -       nc_taylor; // called y in documentation
    110110
    111111        z[0] = atan( x[0] );
     
    141141        CPPAD_ASSERT_UNKNOWN( NumArg(AtanOp) == 1 );
    142142        CPPAD_ASSERT_UNKNOWN( NumRes(AtanOp) == 2 );
    143         CPPAD_ASSERT_UNKNOWN( i_x < i_z );
     143        CPPAD_ASSERT_UNKNOWN( i_x + 1 < i_z );
    144144        CPPAD_ASSERT_UNKNOWN( d < nc_taylor );
    145145        CPPAD_ASSERT_UNKNOWN( d < nc_partial );
     
    154154
    155155        // Taylor coefficients and partials corresponding to auxillary result
    156         const Base* b  = z  + nc_taylor; // called y in documentation
    157         Base* pb       = pz + nc_partial;
     156        const Base* b  = z  - nc_taylor; // called y in documentation
     157        Base* pb       = pz - nc_partial;
    158158
    159159        // number of indices to access
  • branches/multiple_result/cppad/local/dependent.hpp

    r1534 r1586  
    205205        dep_parameter_.resize(m);
    206206        dep_taddr_.resize(m);
    207         total_num_var_ = tape->Rec_.num_rec_var();
    208207        for(i = 0; i < m; i++)
    209208        {       dep_parameter_[i] = CppAD::Parameter(y[i]);
    210209                if( dep_parameter_[i] )
    211                 {       y_taddr = tape->RecordParOp( y[i].value_ );
    212                         total_num_var_++;
    213                 }
     210                        y_taddr = tape->RecordParOp( y[i].value_ );
    214211                else    y_taddr = y[i].taddr_;
    215212
    216213                CPPAD_ASSERT_UNKNOWN( y_taddr > 0 );
    217                 CPPAD_ASSERT_UNKNOWN( y_taddr < total_num_var_ );
    218214                dep_taddr_[i] = y_taddr;
    219215        }
    220216
     217        // put a NonOp at the end of the tape
     218        tape->Rec_.PutOp(NonOp);
     219
     220        // total number of variables on the tape
     221        total_num_var_ = tape->Rec_.num_rec_var();
     222
    221223        // now that each dependent variable has a place in the tape,
     224        // and there is a NonOp at the end of the tape,
    222225        // we can make a copy for this function and erase the tape.
    223226        play_ = tape->Rec_;
  • branches/multiple_result/cppad/local/forward0sweep.hpp

    r1585 r1586  
    197197
    198198                        case AcosOp:
    199                         // results: acos(x),  sqrt(1 - x * x)
    200                         CPPAD_ASSERT_UNKNOWN( (i_var+1) < numvar  );
     199                        // results: sqrt(1 - x * x), acos(x)
     200                        CPPAD_ASSERT_UNKNOWN( i_var < numvar  );
    201201                        forward_acos_op_0(i_var, arg[0], J, Taylor);
    202202                        break;
     
    204204
    205205                        case AsinOp:
    206                         // results: asin(x),  sqrt(1 - x * x)
    207                         CPPAD_ASSERT_UNKNOWN( (i_var+1) < numvar  );
     206                        // results: sqrt(1 - x * x), asin(x)
     207                        CPPAD_ASSERT_UNKNOWN( i_var < numvar  );
    208208                        forward_asin_op_0(i_var, arg[0], J, Taylor);
    209209                        break;
     
    211211
    212212                        case AtanOp:
    213                         // results: atan(x),  1 + x * x
    214                         CPPAD_ASSERT_UNKNOWN( (i_var+1) < numvar  );
     213                        // results: 1 + x * x, atan(x)
     214                        CPPAD_ASSERT_UNKNOWN( i_var < numvar  );
    215215                        forward_atan_op_0(i_var, arg[0], J, Taylor);
    216216                        break;
     
    338338                        case NonOp:
    339339                        CPPAD_ASSERT_UNKNOWN( NumArg(op) == 0 );
    340                         CPPAD_ASSERT_UNKNOWN( NumRes(op) == 0 );
     340                        CPPAD_ASSERT_UNKNOWN( NumRes(op) == 1 );
    341341                        break;
    342342                        // -------------------------------------------------
     
    496496        }
    497497# endif
    498 
    499 # ifndef NDEBUG
    500         // temporary: remove when all cases with NumRes(op) > 1
    501         // have been converted
    502         size_t check = i_var + NumRes(op);
    503         switch(op)
    504         {       case PowpvOp:
    505                 case PowvpOp:
    506                 case PowvvOp:
    507                 case CosOp:
    508                 case SinOp:
    509                 case CoshOp:
    510                 case SinhOp:
    511                 check = i_var + 1;
    512                 break;
    513 
    514                 default:
    515                 break;
    516         }
    517         CPPAD_ASSERT_UNKNOWN( check == Rec->num_rec_var() );
    518 # endif
     498        CPPAD_ASSERT_UNKNOWN( i_var + 1 == Rec->num_rec_var() );
    519499
    520500        if( VectorInd != CPPAD_NULL )
  • branches/multiple_result/cppad/local/forward_sweep.hpp

    r1585 r1586  
    208208
    209209                        case AcosOp:
    210                         // variables: acos(x),  sqrt(1 - x * x)
    211                         CPPAD_ASSERT_UNKNOWN( (i_var+1) < numvar  );
     210                        // variables: sqrt(1 - x * x), acos(x)
     211                        CPPAD_ASSERT_UNKNOWN( i_var < numvar  );
    212212                        forward_acos_op(d, i_var, arg[0], J, Taylor);
    213213                        break;
     
    215215
    216216                        case AsinOp:
    217                         // results: asin(x),  sqrt(1 - x * x)
    218                         CPPAD_ASSERT_UNKNOWN( (i_var+1) < numvar  );
     217                        // results: sqrt(1 - x * x), asin(x)
     218                        CPPAD_ASSERT_UNKNOWN( i_var < numvar  );
    219219                        forward_asin_op(d, i_var, arg[0], J, Taylor);
    220220                        break;
     
    222222
    223223                        case AtanOp:
    224                         // results: atan(x),  1 + x * x
    225                         CPPAD_ASSERT_UNKNOWN( (i_var+1) < numvar  );
     224                        // results: 1 + x * x, atan(x)
     225                        CPPAD_ASSERT_UNKNOWN( i_var < numvar  );
    226226                        forward_atan_op(d, i_var, arg[0], J, Taylor);
    227227                        break;
     
    547547        }
    548548# endif
    549 # ifndef NDEBUG
    550         // temporary: remove when all cases with NumRes(op) > 1
    551         // have been converted
    552         size_t check = i_var + NumRes(op);
    553         switch(op)
    554         {       case PowpvOp:
    555                 case PowvpOp:
    556                 case PowvvOp:
    557                 case CosOp:
    558                 case SinOp:
    559                 case CoshOp:
    560                 case SinhOp:
    561                 check = i_var + 1;
    562                 break;
    563 
    564                 default:
    565                 break;
    566         }
    567         CPPAD_ASSERT_UNKNOWN( check == Rec->num_rec_var() );
    568 # endif
     549        CPPAD_ASSERT_UNKNOWN( i_var + 1 == Rec->num_rec_var() );
     550
    569551        if( VectorInd != CPPAD_NULL )
    570552                CPPAD_TRACK_DEL_VEC(VectorInd);
  • branches/multiple_result/cppad/local/op_code.hpp

    r1523 r1586  
    6767        MulvpOp,  //      variable   * parameter
    6868        MulvvOp,  //      variable   * variable
    69         NonOp,    //                             space holder
     69        NonOp,    //  used to offset the first actual variable to have index 1
    7070        ParOp,    //      parameter
    7171        PowvpOp,  //  pow(variable,    parameter)
     
    200200        1, // MulpvOp
    201201        1, // MulvpOp
    202         1, // NonOp
     202        1, // NonOp    (used to offset the first variable to have index one)
    203203        1, // ParOp
    204204        3, // PowvpOp
  • branches/multiple_result/cppad/local/optimize.hpp

    r1584 r1586  
    404404        play->start_forward(op, arg, i_op, i_var);
    405405
    406         // put the beginning NonOp in the recording
     406        // playing forward skips NonOp at the beginning, but not the end.
     407        // Put the beginning NonOp in the recording
    407408        CPPAD_ASSERT_UNKNOWN( op == NonOp );
    408409        CPPAD_ASSERT_NARG_NRES(NonOp, 0, 1);
     
    428429
    429430                        case InvOp:
     431                        case NonOp:
    430432                        keep = true;
    431433                        break;
  • branches/multiple_result/cppad/local/player.hpp

    r1585 r1586  
    444444        size_t    op_arg_;
    445445
    446         /// Index for first variable corresponding to current operator
     446        /// Index for primary (last) variable corresponding to current operator
    447447        size_t    var_index_;
    448448
     
    469469        \param var_index
    470470        The input value of var_index does not matter. Its output value is the
    471         index of the first result variable corresponding to the the first
    472         operator; i.e., 0.
     471        index of the primary (last) result corresponding to the the first
     472        operator (which must be a NonOp); i.e., 0.
    473473        */
    474474        void start_forward(
     
    510510        \param var_index
    511511        The input value of var_index does not matter. Its output value is the
    512         index of the first result variable corresponding to the operator op.
     512        index of the primary (last) result corresponding to the operator op.
    513513        */
    514514
     
    518518                using CppAD::NumArg;
    519519
     520                // index for the next operator
    520521                op_index    = ++op_index_;
    521                 op_arg_    += NumArg(op_);
    522                 var_index_ += NumRes(op_);
    523 
     522
     523                // first argument for next operator
     524                op_arg_    += NumArg(op_);            // index
     525                op_arg      = op_arg_ + rec_op_arg_;  // pointer
     526
     527                // next operator
    524528                op          = op_         = rec_op_[ op_index_ ];
    525                 op_arg      = op_arg_ + rec_op_arg_;
    526                 var_index   = var_index_;
     529
     530                // index for last result for next operator
     531                var_index   = var_index_ += NumRes(op);
    527532
    528533                CPPAD_ASSERT_UNKNOWN( op_index_  < num_rec_op_ );
    529534                CPPAD_ASSERT_UNKNOWN( op_arg_ + NumArg(op) <= num_rec_op_arg_ );
    530                 CPPAD_ASSERT_UNKNOWN( var_index_ + NumRes(op) <= num_rec_var_ );
    531 
    532                 // temporary: remove when all cases with NumRes(op) > 1
    533                 // have been converted
    534                 switch( op )
    535                 {       case PowpvOp:
    536                         case PowvpOp:
    537                         case PowvvOp:
    538                         case SinOp:
    539                         case CosOp:
    540                         case SinhOp:
    541                         case CoshOp:
    542                         var_index += NumRes(op) - 1;
    543                         break;
    544 
    545                         default:
    546                         break;
    547                 }
     535                CPPAD_ASSERT_UNKNOWN( var_index_  < num_rec_var_ );
    548536        }
    549537        /*!
     
    560548        Start a play back of the recording during a reverse sweep.
    561549
     550        Initialize by pointing to data for NonOp at the end of the tape.
    562551        Use repeated calls to next_reverse to play back one operator at a time.
     552        The NonOp at the end is skipped by this procedure.
    563553        */
    564554        void start_reverse(void)
    565555        {
    566556                op_arg_     = num_rec_op_arg_;
    567                 op_index_   = num_rec_op_;
    568                 var_index_  = num_rec_var_;
     557                op_index_   = num_rec_op_ - 1;
     558                var_index_  = num_rec_var_ - 1;
     559                op_         = rec_op_[ op_index_ ];
     560
     561                CPPAD_ASSERT_UNKNOWN( op_ == NonOp );
    569562                return;
    570563        }
     
    599592        \param var_index
    600593        The input value of var_index does not matter. Its output value is the
    601         index of the first result variable corresponding to the operator op.
    602         The last operator sets var_index equal to 0.
     594        index of the primary (last) result corresponding to the operator op.
     595        The last operator sets var_index equal to 0 (corresponding to NonOp
     596        at beginning of operation sequence).
    603597        */
    604598
     
    608602                using CppAD::NumArg;
    609603
     604                // index of the last result for the next operator
     605                CPPAD_ASSERT_UNKNOWN( var_index_ >= NumRes(op_) );
     606                var_index   = var_index_ -= NumRes(op_);
     607
     608                // next operator
    610609                CPPAD_ASSERT_UNKNOWN( op_index_  > 0 );
    611                 op_index    = --op_index_;
    612                 op_         = rec_op_[ op_index_ ];
    613 
    614                 CPPAD_ASSERT_UNKNOWN( op_arg_ >= NumArg(op_)  );
    615                 op_arg_    -= NumArg(op_);
    616 
    617                 CPPAD_ASSERT_UNKNOWN( var_index_ >= NumRes(op_) );
    618                 var_index_ -= NumRes(op_);
    619 
    620                 op          = op_;
    621                 op_arg      = op_arg_ + rec_op_arg_;
    622                 var_index   = var_index_;
    623 
    624                 // temporary: remove when all cases with NumRes(op) > 1
    625                 // have been converted
    626                 switch( op )
    627                 {       case PowpvOp:
    628                         case PowvpOp:
    629                         case PowvvOp:
    630                         case SinOp:
    631                         case CosOp:
    632                         case SinhOp:
    633                         case CoshOp:
    634                         var_index += NumRes(op) - 1;
    635                         break;
    636 
    637                         default:
    638                         break;
    639                 }
    640 
     610                op_index    = --op_index_;                           // index
     611                op          = op_         = rec_op_[ op_index_ ];    // value
     612
     613                // first argument for next operator
     614                CPPAD_ASSERT_UNKNOWN( op_arg_ >= NumArg(op)  );
     615                op_arg_    -= NumArg(op);                            // index
     616                op_arg      = op_arg_ + rec_op_arg_;                 // pointer
    641617        }
    642618
  • branches/multiple_result/cppad/local/prototype_op.hpp

    r1584 r1586  
    216216
    217217\param i_z
    218 variable index corresponding to the first result for this operation;
     218variable index corresponding to the last (primary) result for this operation;
    219219i.e. the row index in \a taylor corresponding to z.
    220 The auxillary result is called y has index \a i_z + 1.
     220The auxillary result is called y has index \a i_z - 1.
    221221
    222222\param i_x
     
    236236is the k-th order Taylor coefficient corresponding to z.
    237237\n
    238 \b Input: \a taylor [ ( \a i_z + 1) * \a nc_taylor + k ]
     238\b Input: \a taylor [ ( \a i_z - 1) * \a nc_taylor + k ]
    239239for k = 0 , ... , \a j - 1
    240240is the k-th order Taylor coefficient corresponding to the auxillary result y.
     
    243243is the j-th order Taylor coefficient corresponding to z.
    244244\n
    245 \b Output: \a taylor [ ( \a i_z + 1 ) * \a nc_taylor + j ]
     245\b Output: \a taylor [ ( \a i_z - 1 ) * \a nc_taylor + j ]
    246246is the j-th order Taylor coefficient corresponding to
    247247the autillary result y.
     
    250250\li NumArg(op) == 1
    251251\li NumRes(op) == 2
    252 \li \a i_x < \a i_z
     252\li \a i_x + 1 < \a i_z
    253253\li \a j < \a nc_taylor
    254254*/
     
    273273
    274274\param i_z
    275 variable index corresponding to the result for this operation;
     275variable index corresponding to the last (primary) result for this operation;
    276276i.e. the row index in \a taylor corresponding to z.
    277 The auxillary result is called y and has index \a i_z + 1.
     277The auxillary result is called y and has index \a i_z - 1.
    278278
    279279\param i_x
     
    291291is the zero order Taylor coefficient corresponding to z.
    292292\n
    293 \b Output: \a taylor [ ( \a i_z + 1 ) * \a nc_taylor + j ]
     293\b Output: \a taylor [ ( \a i_z - 1 ) * \a nc_taylor + j ]
    294294is the j-th order Taylor coefficient corresponding to
    295295the autillary result y.
     
    298298\li NumArg(op) == 1
    299299\li NumRes(op) == 2
    300 \li \a i_x < \a i_z
     300\li \a i_x + 1 < \a i_z
    301301\li \a j < \a nc_taylor
    302302*/
     
    332332
    333333\param i_z
    334 variable index corresponding to the result for this operation;
     334variable index corresponding to the last (primary) result for this operation;
    335335i.e. the row index in \a taylor to z.
    336 The auxillary result is called y and has index \a i_z + 1.
     336The auxillary result is called y and has index \a i_z - 1.
    337337
    338338\param i_x
     
    352352is the k-th order Taylor coefficient corresponding to z.
    353353\n
    354 \a taylor [ ( \a i_z + 1) * \a nc_taylor + k ]
     354\a taylor [ ( \a i_z - 1) * \a nc_taylor + k ]
    355355for k = 0 , ... , \a d
    356356is the k-th order Taylor coefficient corresponding to
     
    372372the k-th order Taylor coefficient for z.
    373373\n
    374 \b Input: \a partial [ ( \a i_z + 1) * \a nc_partial + k ]
     374\b Input: \a partial [ ( \a i_z - 1) * \a nc_partial + k ]
    375375for k = 0 , ... , \a d
    376376is the partial derivative of G( z , x , w , u , ... ) with respect to
     
    382382the k-th order Taylor coefficient for x.
    383383\n
    384 \b Output: \a partial [ \a i_z * \a nc_partial + k ]
    385 for k = 0 , ... , \a d
    386 may be used as work space; i.e., may change in an unspecified manner.
    387 \n
    388 \b Output: \a partial [ ( \a i_z + 1) * \a nc_partial + k ]
    389 for k = 0 , ... , \a d
     384\b Output: \a partial [ \a ( i_z - j ) * \a nc_partial + k ]
     385for j = 0 , 1 , and for k = 0 , ... , \a d
    390386may be used as work space; i.e., may change in an unspecified manner.
    391387
     
    394390\li NumArg(op) == 1
    395391\li NumRes(op) == 2
    396 \li \a i_x < \a i_z
     392\li \a i_x + 1 < \a i_z
    397393\li \a d < \a nc_taylor
    398394\li \a d < \a nc_partial
     
    627623is the partial derivative of H( y , x , w , u , ... ) with respect to
    628624the k-th order Taylor coefficient for y.
     625\n
     626\b Output: \a partial [ \a i_z * \a nc_partial + k ]
     627for k = 0 , ... , \a d
     628may be used as work space; i.e., may change in an unspecified manner.
    629629
    630630\par Checked Assumptions
     
    663663
    664664\param i_z
    665 variable index corresponding to the final result for this operation;
     665variable index corresponding to the last (primary) result for this operation;
    666666i.e. the row index in \a taylor corresponding to z.
    667667Note that there are three results for this operation,
     
    702702is the k-th order Taylor coefficient corresponding to y.
    703703\n
    704 \b Input: \a taylor [ \a (i_z + j) * \a nc_taylor + k ]
     704\b Input: \a taylor [ \a (i_z - 2 + j) * \a nc_taylor + k ]
    705705for j = 0, 1, 2 , and for k = 0 , ... , \a d - 1
    706706is the k-th order Taylor coefficient corresponding to z_j.
    707707\n
    708 \b Output: \a taylor [ \a (i_z + j) * \a nc_taylor + \a d ]
     708\b Output: \a taylor [ \a (i_z - 2 + j) * \a nc_taylor + \a d ]
    709709is the \a d-th order Taylor coefficient corresponding to z_j.
    710710
     
    737737
    738738\param i_z
    739 variable index corresponding to the final result for this operation;
     739variable index corresponding to the last (primary) result for this operation;
    740740i.e. the row index in \a taylor corresponding to z.
    741741Note that there are three results for this operation,
     
    774774is the k-th order Taylor coefficient corresponding to y.
    775775\n
    776 \b Output: \a taylor [ \a (i_z + j) * \a nc_taylor + 0 ]
     776\b Output: \a taylor [ \a (i_z - 2 + j) * \a nc_taylor + 0 ]
    777777is the zero order Taylor coefficient corresponding to z_j.
    778778
     
    814814
    815815\param i_z
    816 variable index corresponding to the final result for this operation;
     816variable index corresponding to the last (primary) result for this operation;
    817817i.e. the row index in \a taylor corresponding to z.
    818818Note that there are three results for this operation,
     
    845845
    846846\param taylor
    847 \a taylor [ \a (i_z + j) * \a nc_taylor + k ]
     847\a taylor [ \a (i_z - 2 + j) * \a nc_taylor + k ]
    848848for j = 0, 1, 2 and k = 0 , ... , \a d
    849849is the k-th order Taylor coefficient corresponding to z_j.
     
    861861
    862862\param partial
    863 \b Input: \a partial [ \a (i_z + j) * \a nc_partial + k ]
     863\b Input: \a partial [ \a (i_z - 2 + j) * \a nc_partial + k ]
    864864for j = 0, 1, 2, and k = 0 , ... , \a d
    865865is the partial derivative of
     
    886886is the partial derivative of H( y , x , w , u , ... ) with respect to
    887887the k-th order Taylor coefficient for y.
     888\n
     889\b Output: \a partial [ \a ( i_z - j ) * \a nc_partial + k ]
     890for j = 0 , 1 , 2 and for k = 0 , ... , \a d
     891may be used as work space; i.e., may change in an unspecified manner.
    888892
    889893\par Checked Assumptions
     
    11231127
    11241128\param i_z
    1125 is the index corresponding to the next variable on the tape
     1129is the index corresponding to the previous variable on the tape
    11261130(only used for error checking).
    11271131
     
    11921196\li \a arg[0] + i_vec < nc_combined
    11931197\li if y is a parameter, arg[2] < num_par
    1194 \li if x is a variable, arg[1] < i_z
    1195 \li if y is a variable, arg[2] < i_z
     1198\li if x is a variable, arg[1] <= i_z
     1199\li if y is a variable, arg[2] <= i_z
    11961200*/
    11971201template <class Base>
  • branches/multiple_result/cppad/local/recorder.hpp

    r1585 r1586  
    212212
    213213\return
    214 The return value is the index of the first variable
     214The return value is the index of the primary (last) variable
    215215corresponding to the result of this operation.
    216216The number of variables corresponding to the operation is given by
     
    220220With each call to PutOp
    221221the return index increases by the number of variables corresponding
    222 to the previous call to PutOp.
     222to this call to PutOp.
    223223This index starts at zero after the default constructor
    224224and after each call to Erase.
     
    226226template <class Base>
    227227inline size_t recorder<Base>::PutOp(OpCode op)
    228 {       size_t varIndex = num_rec_var_;
    229        
     228{
    230229        CPPAD_ASSERT_UNKNOWN( num_rec_op_ <= len_rec_op_ );
    231230        if( num_rec_op_ == len_rec_op_ )
     
    239238        num_rec_var_ += NumRes(op);
    240239
    241         // temporary: make this the only return value when all cases with
    242         // all cases with NumRes(op) > 1 have been converted
    243         switch( op )
    244         {       case PowpvOp:
    245                 case PowvpOp:
    246                 case PowvvOp:
    247                 case CosOp:
    248                 case SinOp:
    249                 case CoshOp:
    250                 case SinhOp:
    251                 return num_rec_var_ - 1;
    252                 break;
    253 
    254                 default:
    255                 break;
    256         }
    257 
    258         return varIndex;
     240        // first operator should be a NonOp and NumRes( NonOp ) > 0
     241        CPPAD_ASSERT_UNKNOWN( num_rec_var_ > 0 );
     242
     243        return num_rec_var_ - 1;
    259244}
    260245
  • branches/multiple_result/cppad/local/reverse_sweep.hpp

    r1585 r1586  
    223223
    224224                        case AcosOp:
    225                         // results: acos(x),  sqrt(1 - x * x)
    226                         CPPAD_ASSERT_UNKNOWN( i_var < numvar - 1 );
     225                        // results: sqrt(1 - x * x), acos(x)
     226                        CPPAD_ASSERT_UNKNOWN( i_var < numvar );
    227227                        reverse_acos_op(
    228228                                d, i_var, arg[0], J, Taylor, K, Partial
     
    232232
    233233                        case AsinOp:
    234                         // results: sin(x),  sqrt(1 - x * x)
    235                         CPPAD_ASSERT_UNKNOWN( i_var < numvar - 1 );
     234                        // results: sqrt(1 - x * x), sin(x)
     235                        CPPAD_ASSERT_UNKNOWN( i_var < numvar );
    236236                        reverse_asin_op(
    237237                                d, i_var, arg[0], J, Taylor, K, Partial
     
    241241
    242242                        case AtanOp:
    243                         // results: atan(x),  1 + x * x
    244                         CPPAD_ASSERT_UNKNOWN( i_var < numvar - 1 );
     243                        // results: 1 + x * x, atan(x)
     244                        CPPAD_ASSERT_UNKNOWN( i_var < numvar );
    245245                        reverse_atan_op(
    246246                                d, i_var, arg[0], J, Taylor, K, Partial
  • branches/multiple_result/cppad/local/store_op.hpp

    r1529 r1586  
    8080        CPPAD_ASSERT_UNKNOWN( 0 < arg[0] );
    8181        CPPAD_ASSERT_UNKNOWN( arg[0] + i_vec < nc_combined );
    82         CPPAD_ASSERT_UNKNOWN( arg[2] < i_z );
     82        CPPAD_ASSERT_UNKNOWN( arg[2] <= i_z );
    8383
    8484        variable[ arg[0] + i_vec ] = true;
     
    102102        size_t*        combined    )
    103103{       
    104         CPPAD_ASSERT_UNKNOWN( arg[1] < i_z );
     104        CPPAD_ASSERT_UNKNOWN( arg[1] <= i_z );
    105105        size_t i_vec = Integer( taylor[ arg[1] * nc_taylor + 0 ] );
    106106        CPPAD_ASSERT_KNOWN(
     
    137137        size_t*        combined    )
    138138{       
    139         CPPAD_ASSERT_UNKNOWN( arg[1] < i_z );
     139        CPPAD_ASSERT_UNKNOWN( arg[1] <= i_z );
    140140        size_t i_vec = Integer( taylor[ arg[1] * nc_taylor + 0 ] );
    141141        CPPAD_ASSERT_KNOWN(
     
    150150        CPPAD_ASSERT_UNKNOWN( 0 < arg[0] );
    151151        CPPAD_ASSERT_UNKNOWN( arg[0] + i_vec < nc_combined );
    152         CPPAD_ASSERT_UNKNOWN( arg[2] < i_z );
     152        CPPAD_ASSERT_UNKNOWN( arg[2] <= i_z );
    153153
    154154        variable[ arg[0] + i_vec ] = true;
  • branches/multiple_result/example/optimize.cpp

    r1497 r1586  
    7373        // a:     the temporary variable inside the function fun.
    7474        // y:     the return value for the function fun and dependent variable.
    75         ok &= (F.size_var() == 4);
     75        // NonOp: at the end of every operation sequence.
     76        ok &= (F.size_var() == 5);
    7677
    7778        // Check zero order forward mode on the original operation sequence
     
    8889        // X[0]:  the independent variable.
    8990        // y:     the return value for the function fun and dependent variable.
    90         ok &= (F.size_var() == 3);
     91        // NonOp: at the end of every operation sequence.
     92        ok &= (F.size_var() == 4);
    9193
    9294        // Check result for a zero order calculation.
  • branches/multiple_result/example/seq_property.cpp

    r1497 r1586  
    5757
    5858        // Use nvar to track the number of variables in the operation sequence.
    59         // Start with one for the phantom variable at tape address zero.
    60         size_t nvar = 1;
     59        // Start with two for the phantom variable at the beginning and end
     60        // of the tape.
     61        size_t nvar = 2;
    6162
    6263        // Use npar to track the number of parameters in the operation sequence.
  • branches/multiple_result/test_more/optimize.cpp

    r1584 r1586  
    111111       
    112112                // Check size before optimization
    113                 ok &= F.size_var() == (n + 1 + original);
     113                // (add 2 for the NonOp at the beginning and end of op seq)
     114                ok &= F.size_var() == (n + 2 + original);
    114115       
    115116                // Optimize the operation sequence
     
    117118       
    118119                // Check size after optimization
    119                 ok &= F.size_var() == (n + 1 + opt);
     120                // (add 2 for the NonOp at the beginning and end of op seq)
     121                ok &= F.size_var() == (n + 2 + opt);
    120122       
    121123                // check result now
Note: See TracChangeset for help on using the changeset viewer.