Changeset 3792


Ignore:
Timestamp:
Feb 26, 2016 8:55:30 AM (4 years ago)
Author:
bradbell
Message:

merge to branch: trunk
from repository: https://github.com/coin-or/CppAD
start hash code: b41cff3e1ace54eeb8cc4ed37ed4743594765bad
end hash code: 001743ad36561e8047c36cff04f6ba6c53c107cb

commit 001743ad36561e8047c36cff04f6ba6c53c107cb
Author: Brad Bell <bradbell@…>
Date: Fri Feb 26 06:52:29 2016 -0700

Correct statement of when sparsity pattern does not depend on x.

commit 94a5096512280ffc204b58ed2ac8cbc2732eac68
Author: Brad Bell <bradbell@…>
Date: Fri Feb 26 06:13:38 2016 -0700

rev_sparse_hes.hpp: remove two helper functions.

commit f16dc3ea0879ff4f2852c8e2674e41524c128007
Author: Brad Bell <bradbell@…>
Date: Fri Feb 26 05:55:46 2016 -0700

for_sparse_jac.hpp: fix typo in error messages.
rev_sparse_jac.hpp: remove two extra helper functions.

commit 954a9aef1b06ae1e7f3d4b1f913dfbb297dab11d
Author: Brad Bell <bradbell@…>
Date: Fri Feb 26 05:25:31 2016 -0700

for_sparse_jac.hpp: Remove two extra helper functions.

commit 13c5507c4c4020c4a9adc038ca6d6c428ab05c47
Author: Brad Bell <bradbell@…>
Date: Fri Feb 26 04:19:08 2016 -0700

  1. Remove the sparse_set class (always use sparse_list for set sparsity).
  2. Advance version to cppad-20160226

commit b5cb53d0b9a47cdbfcb9d8f746e4f9322cbee841
Author: Brad Bell <bradbell@…>
Date: Thu Feb 25 19:29:04 2016 -0700

  1. Advance version to cppad-20160225
  2. Change user2internal to pass error_msg and internal, not user, dimensions.

commit bd973e669c98709ac669f5f501b64be41acb6b48
Author: Brad Bell <bradbell@…>
Date: Thu Feb 25 08:04:09 2016 -0700

sparse_list.hpp: fix typo.

commit d3121a414e1a95e17a04cbf103c0190a76cce390
Author: Brad Bell <bradbell@…>
Date: Wed Feb 24 08:51:13 2016 -0700

Correct a spelling error currentl -> current.

commit 2b65f1b0a76eb95c2cf87ca53261f839234a92fa
Author: Brad Bell <bradbell@…>
Date: Wed Feb 24 06:02:10 2016 -0700

whats_new_16.omh: edit 02/23 entry.

Location:
trunk
Files:
1 deleted
31 edited

Legend:

Unmodified
Added
Removed
  • trunk/AUTHORS

    r3791 r3792  
    22             ===========================================
    33
    4 To date, 2016-02-23, Bradley M. Bell is the sole author of CppAD.
     4To date, 2016-02-26, Bradley M. Bell is the sole author of CppAD.
    55While Bradley M. Bell worked for the University of Washington during
    66the development of CppAD, the following are also true:
  • trunk/CMakeLists.txt

    r3791 r3792  
    1818
    1919# cppad_version is used by set_version.sh to get the version number.
    20 SET(cppad_version      "20160223" )
     20SET(cppad_version      "20160226" )
    2121SET(cppad_url          "http://www.coin-or.org/CppAD" )
    2222SET(cppad_description  "Differentiation of C++ Algorithms" )
  • trunk/bin/batch_edit.sh

    r3788 r3792  
    1818#
    1919cat << EOF > junk.sed
    20 #
    21 /\$codep [*]\//! b two
    22 : one
    23 N
    24 /\/[*] *\$\\\$/! b one
    25 s|\$codep [*]/|\$srccode%cpp% */|
    26 s|/[*] *\$\\\$|/* %\$\$|
    27 #
    28 : two
    29 /\$verbatim/! b end
    30 /\$\\\$/! N
    31 /\$\\\$/! b two
    32 /\.[ch]pp%/s|\$verbatim|\$srcfile|
    33 #
     20s|CPPAD_INTERNAL_SPARSE_SET  |sparse_list                |
     21s|CPPAD_INTERNAL_SPARSE_SET&  |sparse_list\&                |
     22s|CPPAD_INTERNAL_SPARSE_SET |sparse_list |
     23/cppad\/local\/sparse_set.hpp/d
    3424: end
    3525EOF
  • trunk/bin/run_cmake.sh

    r3781 r3792  
    3131no_colpack='no'
    3232no_ipopt='no'
    33 no_sparse_list='no'
    3433no_documentation='no'
    3534testvector='boost'
     
    4948        [--no_colpack] \\
    5049        [--no_ipopt] \\
    51         [--no_sparse_list] \\
    5250        [--no_documentation] \\
    5351        [--<package>_vector]
     
    8381        then
    8482                no_ipopt='yes'
    85         elif [ "$1" == '--no_sparse_list' ]
    86         then
    87                 no_sparse_list='yes'
    8883        elif [ "$1" == '--no_documentation' ]
    8984        then
     
    182177done
    183178#
    184 # sparse_list
    185 if [ "$no_sparse_list" == 'yes' ]
    186 then
    187         cmake_args="$cmake_args -D cppad_sparse_list=NO"
    188 else
    189         cmake_args="$cmake_args -D cppad_sparse_list=YES"
    190 fi
    191 #
    192179# cppad_cxx_flags
    193180cppad_cxx_flags="-Wall -pedantic-errors -std=$standard"
  • trunk/configure

    r3791 r3792  
    11#! /bin/sh
    22# Guess values for system-dependent variables and create Makefiles.
    3 # Generated by GNU Autoconf 2.69 for cppad 20160223.
     3# Generated by GNU Autoconf 2.69 for cppad 20160226.
    44#
    55# Report bugs to <cppad@list.coin-or.org>.
     
    581581PACKAGE_NAME='cppad'
    582582PACKAGE_TARNAME='cppad'
    583 PACKAGE_VERSION='20160223'
    584 PACKAGE_STRING='cppad 20160223'
     583PACKAGE_VERSION='20160226'
     584PACKAGE_STRING='cppad 20160226'
    585585PACKAGE_BUGREPORT='cppad@list.coin-or.org'
    586586PACKAGE_URL=''
     
    14081408  # This message is too long to be a string in the A/UX 3.1 sh.
    14091409  cat <<_ACEOF
    1410 \`configure' configures cppad 20160223 to adapt to many kinds of systems.
     1410\`configure' configures cppad 20160226 to adapt to many kinds of systems.
    14111411
    14121412Usage: $0 [OPTION]... [VAR=VALUE]...
     
    14781478if test -n "$ac_init_help"; then
    14791479  case $ac_init_help in
    1480      short | recursive ) echo "Configuration of cppad 20160223:";;
     1480     short | recursive ) echo "Configuration of cppad 20160226:";;
    14811481   esac
    14821482  cat <<\_ACEOF
     
    16121612if $ac_init_version; then
    16131613  cat <<\_ACEOF
    1614 cppad configure 20160223
     1614cppad configure 20160226
    16151615generated by GNU Autoconf 2.69
    16161616
     
    22412241running configure, to aid debugging if configure makes a mistake.
    22422242
    2243 It was created by cppad $as_me 20160223, which was
     2243It was created by cppad $as_me 20160226, which was
    22442244generated by GNU Autoconf 2.69.  Invocation command line was
    22452245
     
    31313131# Define the identity of the package.
    31323132 PACKAGE='cppad'
    3133  VERSION='20160223'
     3133 VERSION='20160226'
    31343134
    31353135
     
    85838583# values after options handling.
    85848584ac_log="
    8585 This file was extended by cppad $as_me 20160223, which was
     8585This file was extended by cppad $as_me 20160226, which was
    85868586generated by GNU Autoconf 2.69.  Invocation command line was
    85878587
     
    86408640ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
    86418641ac_cs_version="\\
    8642 cppad config.status 20160223
     8642cppad config.status 20160226
    86438643configured by $0, generated by GNU Autoconf 2.69,
    86448644  with options \\"\$ac_cs_config\\"
  • trunk/configure.ac

    r3791 r3792  
    1313dnl Process this file with autoconf to produce a configure script.
    1414dnl   package   version              bug-report
    15 AC_INIT([cppad], [20160223], [cppad@list.coin-or.org])
     15AC_INIT([cppad], [20160226], [cppad@list.coin-or.org])
    1616AM_SILENT_RULES([yes])
    1717
  • trunk/cppad/CMakeLists.txt

    r3768 r3792  
    11# $Id$
    22# -----------------------------------------------------------------------------
    3 # CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-15 Bradley M. Bell
     3# CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell
    44#
    55# CppAD is distributed under multiple licenses. This distribution is under
     
    3535)
    3636# cppad_sparse_list
    37 command_line_arg(cppad_sparse_list YES BOOL
    38         "use sparse list for internal sparse set representation"
    39 )
     37IF( cppad_sparse_list )
     38        MESSAGE(FATAL_ERROR
     39                "cppad_sparse_list = ${cppad_sparse_list}"
     40                ": this command line argument has been removed"
     41        )
     42ENDIF( cppad_sparse_list )
    4043#
    4144# cppad_tape_id_type
     
    6063        SET(cppad_deprecated 0)
    6164ENDIF( cppad_deprecated )
    62 # -----------------------------------------------------------------------------
    63 # cppad_internal_sparse_set
    64 #
    65 IF( cppad_sparse_list )
    66         SET(cppad_internal_sparse_set  sparse_list )
    67 ELSE( cppad_sparse_list )
    68         SET(cppad_internal_sparse_set  sparse_set )
    69 ENDIF( cppad_sparse_list )
    70 MESSAGE(STATUS "cppad_internal_sparse_set = ${cppad_internal_sparse_set}" )
    71 #
    7265# -----------------------------------------------------------------------------
    7366# cppad_boostvector, cppad_cppadvector, cppad_eigenvector, cppad_stdvector
  • trunk/cppad/configure.hpp.in

    r3760 r3792  
    44
    55/* --------------------------------------------------------------------------
    6 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-15 Bradley M. Bell
     6CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell
    77
    88CppAD is distributed under multiple licenses. This distribution is under
     
    7979*/
    8080# define CPPAD_HAS_COLPACK @cppad_has_colpack@
    81 
    82 /*!
    83 def CPPAD_INTERNAL_SPARSE_SET
    84 is the internal representation used for sparse vectors of std::set<size_t>
    85 either sparse_set or sparse_list).
    86 */
    87 # define CPPAD_INTERNAL_SPARSE_SET @cppad_internal_sparse_set@
    8881
    8982/*!
  • trunk/cppad/local/ad_fun.hpp

    r3757 r3792  
    44
    55/* --------------------------------------------------------------------------
    6 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-15 Bradley M. Bell
     6CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell
    77
    88CppAD is distributed under multiple licenses. This distribution is under
     
    137137        /// Set results of the forward mode Jacobian sparsity calculations
    138138        /// for_jac_sparse_set_.n_set() != 0  implies for_sparse_pack_ is empty.
    139         CPPAD_INTERNAL_SPARSE_SET  for_jac_sparse_set_;
     139        sparse_list                for_jac_sparse_set_;
    140140
    141141// ------------------------------------------------------------
     
    330330                vector<bool>&                 s         ,
    331331                bool                          transpose ,
    332                 CPPAD_INTERNAL_SPARSE_SET&    h
     332                sparse_list&                  h
    333333        );
    334334        // internal set sparsity version of RevSparseJac
     
    336336        void RevSparseJacCheckpoint(
    337337                size_t                        q          ,
    338                 CPPAD_INTERNAL_SPARSE_SET&    r          ,
     338                sparse_list&                  r          ,
    339339                bool                          transpose  ,
    340340                bool                          dependency ,
    341                 CPPAD_INTERNAL_SPARSE_SET&    s
     341                sparse_list&                  s
    342342        );
    343343    // internal set sparsity version of RevSparseJac
     
    345345        void ForSparseJacCheckpoint(
    346346        size_t                        q          ,
    347         CPPAD_INTERNAL_SPARSE_SET&    r          ,
     347        sparse_list&                  r          ,
    348348        bool                          transpose  ,
    349349        bool                          dependency ,
    350         CPPAD_INTERNAL_SPARSE_SET&    s
     350        sparse_list&                  s
    351351        );
    352352
  • trunk/cppad/local/checkpoint.hpp

    r3757 r3792  
    44
    55/* --------------------------------------------------------------------------
    6 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-15 Bradley M. Bell
     6CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell
    77
    88CppAD is distributed under multiple licenses. This distribution is under
     
    1313Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
    1414-------------------------------------------------------------------------- */
    15 # include <cppad/local/sparse_set.hpp>
    1615# include <cppad/local/sparse_list.hpp>
    1716# include <cppad/local/sparse_pack.hpp>
     
    213212        //
    214213        /// sparsity for entire Jacobian f(x)^{(1)} does not change so can cache it
    215         CPPAD_INTERNAL_SPARSE_SET  jac_sparse_set_;
     214        sparse_list                jac_sparse_set_;
    216215        vectorBool                 jac_sparse_bool_;
    217216        //
    218217        /// sparsity for sum_i f_i(x)^{(2)} does not change so can cache it
    219         CPPAD_INTERNAL_SPARSE_SET  hes_sparse_set_;
     218        sparse_list                hes_sparse_set_;
    220219        vectorBool                 hes_sparse_bool_;
    221220        // ------------------------------------------------------------------------
     
    233232                // size for the sparsity pattern of all variables in the tape.
    234233                if( n <= m )
    235                 {       CPPAD_INTERNAL_SPARSE_SET identity;
     234                {       sparse_list identity;
    236235                        identity.resize(n, n);
    237236                        for(size_t j = 0; j < n; j++)
     
    243242                }
    244243                else
    245                 {       CPPAD_INTERNAL_SPARSE_SET identity;
     244                {       sparse_list identity;
    246245                        identity.resize(m, m);
    247246                        for(size_t i = 0; i < m; i++)
     
    300299
    301300                // set version of sparsity for n by n idendity matrix
    302                 CPPAD_INTERNAL_SPARSE_SET identity;
     301                sparse_list identity;
    303302                identity.resize(n, n);
    304303                for(size_t j = 0; j < n; j++)
  • trunk/cppad/local/for_jac_sweep.hpp

    r3757 r3792  
    33# define CPPAD_FOR_JAC_SWEEP_HPP
    44/* --------------------------------------------------------------------------
    5 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-15 Bradley M. Bell
     5CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell
    66
    77CppAD is distributed under multiple licenses. This distribution is under
     
    8888The object \a play is effectly constant.
    8989It is not declared const because while playing back the tape
    90 the object \a play holds information about the currentl location
     90the object \a play holds information about the current location
    9191with in the tape and this changes during playback.
    9292
  • trunk/cppad/local/for_sparse_jac.hpp

    r3757 r3792  
    44
    55/* --------------------------------------------------------------------------
    6 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-15 Bradley M. Bell
     6CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell
    77
    88CppAD is distributed under multiple licenses. This distribution is under
     
    104104
    105105$head x$$
    106 the sparsity pattern is valid for all values of the independent
    107 variables in $latex x \in B^n$$
     106If the operation sequence in $icode f$$ is
     107$cref/independent/glossary/Operation/Independent/$$ of
     108the independent variables in $latex x \in B^n$$,
     109the sparsity pattern is valid for all values of
    108110(even if it has $cref CondExp$$ or $cref VecAD$$ operations).
    109111
     
    225227Forward mode Jacobian sparsity patterns.
    226228*/
    227 
    228229// ---------------------------------------------------------------------------
    229230/*!
    230 Calculate Jacobian vector of bools sparsity patterns using forward mode.
    231 
    232 The C++ source code corresponding to this operation is
    233 \verbatim
    234         s = f.ForSparseJac(q, r)
    235 \endverbatim
    236 
    237 \tparam Base
    238 is the base type for this recording.
    239 
    240 \tparam VectorSet
    241 is a simple vector class with elements of type \c bool.
    242 
    243 \param transpose
    244 are the sparsity patterns transposed.
    245 
    246 \param dependency
    247 Are the derivatives with respect to left and right of the expression below
    248 considered to be non-zero:
    249 \code
    250     CondExpRel(left, right, if_true, if_false)
    251 \endcode
    252 This is used by the optimizer to obtain the correct dependency relations.
    253 
    254 \param q
    255 is the number of columns in the matrix \f$ R \f$.
    256 
    257 \param r
    258 is a sparsity pattern for the matrix \f$ R \f$.
    259 
    260 \param s
    261 The input value of \a s must be a vector with size \c m*q
    262 where \c m is the number of dependent variables
    263 corresponding to the operation sequence stored in \a play.
    264 The input value of the components of \c s does not matter.
    265 On output, \a s is the sparsity pattern for the matrix
    266 \f[
    267         S(x) = F^{(1)} (x) * R
    268 \f]
    269 where \f$ F \f$ is the function corresponding to the operation sequence
    270 and \a x is any argument value.
    271 
    272 \param total_num_var
    273 is the total number of variable in this recording.
    274 
    275 \param dep_taddr
    276 maps dependendent variable index
    277 to the corresponding variable in the tape.
    278 
    279 \param ind_taddr
    280 maps independent variable index
    281 to the corresponding variable in the tape.
    282 
    283 \param play
    284 is the recording that defines the function we are computing the sparsity
    285 pattern for.
    286 
    287 \param for_jac_sparsity
    288 the input value of \a for_jac_sparsity does not matter.
    289 On output, \a for_jac_sparsity.n_set() == \a total_num_var
    290 and \a for_jac_sparsity.end() == \a q.
    291 It contains the forward sparsity pattern for all of the variables on the
    292 tape (given the sparsity pattern for the independent variables is \f$ R \f$).
    293 */
    294 template <class Base, class VectorSet>
    295 void ForSparseJacBool(
    296         bool                   transpose        ,
    297         bool                   dependency       ,
    298         size_t                 q                ,
    299         const VectorSet&       r                ,
    300         VectorSet&             s                ,
    301         size_t                 total_num_var    ,
    302         CppAD::vector<size_t>& dep_taddr        ,
    303         CppAD::vector<size_t>& ind_taddr        ,
    304         CppAD::player<Base>&   play             ,
    305         sparse_pack&           for_jac_sparsity )
    306 {
    307         // temporary indices
    308         size_t i, j;
    309 
    310         // range and domain dimensions for F
    311         size_t m = dep_taddr.size();
    312         size_t n = ind_taddr.size();
    313 
    314         CPPAD_ASSERT_KNOWN(
    315                 q > 0,
    316                 "ForSparseJac: q is not greater than zero"
    317         );
    318         CPPAD_ASSERT_KNOWN(
    319                 size_t(r.size()) == n * q,
    320                 "ForSparseJac: size of r is not equal to\n"
    321                 "q times domain dimension for ADFun object."
    322         );
    323 
    324         // allocate memory for the requested sparsity calculation result
    325         for_jac_sparsity.resize(total_num_var, q);
    326 
    327         // set values corresponding to independent variables
    328         for(i = 0; i < n; i++)
    329         {       CPPAD_ASSERT_UNKNOWN( ind_taddr[i] < total_num_var );
    330                 // ind_taddr[i] is operator taddr for i-th independent variable
    331                 CPPAD_ASSERT_UNKNOWN( play.GetOp( ind_taddr[i] ) == InvOp );
    332 
    333                 // set bits that are true
    334                 if( transpose )
    335                 {       for(j = 0; j < q; j++) if( r[ j * n + i ] )
    336                                 for_jac_sparsity.add_element( ind_taddr[i], j);
    337                 }
    338                 else
    339                 {       for(j = 0; j < q; j++) if( r[ i * q + j ] )
    340                                 for_jac_sparsity.add_element( ind_taddr[i], j);
    341                 }
    342         }
    343 
    344         // evaluate the sparsity patterns
    345         ForJacSweep(
    346                 dependency,
    347                 n,
    348                 total_num_var,
    349                 &play,
    350                 for_jac_sparsity
    351         );
    352 
    353         // return values corresponding to dependent variables
    354         CPPAD_ASSERT_UNKNOWN( size_t(s.size()) == m * q );
    355         for(i = 0; i < m; i++)
    356         {       CPPAD_ASSERT_UNKNOWN( dep_taddr[i] < total_num_var );
    357 
    358                 // extract the result from for_jac_sparsity
    359                 if( transpose )
    360                 {       for(j = 0; j < q; j++)
    361                                 s[ j * m + i ] = false;
    362                 }
    363                 else
    364                 {       for(j = 0; j < q; j++)
    365                                 s[ i * q + j ] = false;
    366                 }
    367                 CPPAD_ASSERT_UNKNOWN( for_jac_sparsity.end() == q );
    368                 for_jac_sparsity.begin( dep_taddr[i] );
    369                 j = for_jac_sparsity.next_element();
    370                 while( j < q )
    371                 {       if( transpose )
    372                                 s[j * m + i] = true;
    373                         else    s[i * q + j] = true;
    374                         j = for_jac_sparsity.next_element();
    375                 }
    376         }
    377 }
    378 
    379 /*!
    380 Calculate Jacobian vector of sets sparsity patterns using forward mode.
    381 
    382 The C++ source code corresponding to this operation is
    383 \verbatim
    384         s = f.ForSparseJac(q, r)
    385 \endverbatim
    386 
    387 \tparam Base
    388 see \c SparseJacBool.
    389 
    390 \tparam VectorSet
    391 is a simple vector class with elements of type \c std::set<size_t>.
    392 
    393 \param transpose
    394 see \c SparseJacBool.
    395 
    396 \param dependency
    397 see \c SparseJacBool.
    398 
    399 \param q
    400 see \c SparseJacBool.
    401 
    402 \param r
    403 see \c SparseJacBool.
    404 
    405 \param s
    406 see \c SparseJacBool.
    407 
    408 \param total_num_var
    409 see \c SparseJacBool.
    410 
    411 \param dep_taddr
    412 see \c SparseJacBool.
    413 
    414 \param ind_taddr
    415 see \c SparseJacBool.
    416 
    417 \param play
    418 see \c SparseJacBool.
    419 
    420 \param for_jac_sparsity
    421 see \c SparseJacBool.
    422 */
    423 
    424 template <class Base, class VectorSet>
    425 void ForSparseJacSet(
    426         bool                        transpose        ,
    427         bool                        dependency       ,
    428         size_t                      q                ,
    429         const VectorSet&            r                ,
    430         VectorSet&                  s                ,
    431         size_t                      total_num_var    ,
    432         CppAD::vector<size_t>&      dep_taddr        ,
    433         CppAD::vector<size_t>&      ind_taddr        ,
    434         CppAD::player<Base>&        play             ,
    435         CPPAD_INTERNAL_SPARSE_SET&  for_jac_sparsity )
    436 {
    437         // temporary indices
    438         size_t i, j;
    439         std::set<size_t>::const_iterator itr;
    440 
    441         // range and domain dimensions for F
    442         size_t m = dep_taddr.size();
    443         size_t n = ind_taddr.size();
    444 
    445         CPPAD_ASSERT_KNOWN(
    446                 q > 0,
    447                 "RevSparseJac: q is not greater than zero"
    448         );
    449         CPPAD_ASSERT_KNOWN(
    450                 size_t(r.size()) == n || transpose,
    451                 "RevSparseJac: size of r is not equal to n and transpose is false."
    452         );
    453         CPPAD_ASSERT_KNOWN(
    454                 size_t(r.size()) == q || ! transpose,
    455                 "RevSparseJac: size of r is not equal to q and transpose is true."
    456         );
    457 
    458         // allocate memory for the requested sparsity calculation
    459         for_jac_sparsity.resize(total_num_var, q);
    460 
    461         // set values corresponding to independent variables
    462         if( transpose )
    463         {       for(i = 0; i < q; i++)
    464                 {       // add the elements that are present
    465                         itr = r[i].begin();
    466                         while( itr != r[i].end() )
    467                         {       j = *itr++;
    468                                 CPPAD_ASSERT_KNOWN(
    469                                 j < n,
    470                                 "ForSparseJac: transpose is true and element of the set\n"
    471                                 "r[j] has value greater than or equal n."
    472                                 );
    473                                 CPPAD_ASSERT_UNKNOWN( ind_taddr[j] < total_num_var );
    474                                 // operator for j-th independent variable
    475                                 CPPAD_ASSERT_UNKNOWN( play.GetOp( ind_taddr[j] ) == InvOp );
    476                                 for_jac_sparsity.add_element( ind_taddr[j], i);
    477                         }
    478                 }
    479         }
    480         else
    481         {       for(i = 0; i < n; i++)
    482                 {       CPPAD_ASSERT_UNKNOWN( ind_taddr[i] < total_num_var );
    483                         // ind_taddr[i] is operator taddr for i-th independent variable
    484                         CPPAD_ASSERT_UNKNOWN( play.GetOp( ind_taddr[i] ) == InvOp );
    485 
    486                         // add the elements that are present
    487                         itr = r[i].begin();
    488                         while( itr != r[i].end() )
    489                         {       j = *itr++;
    490                                 CPPAD_ASSERT_KNOWN(
    491                                         j < q,
    492                                         "ForSparseJac: an element of the set r[i] "
    493                                         "has value greater than or equal q."
    494                                 );
    495                                 for_jac_sparsity.add_element( ind_taddr[i], j);
    496                         }
    497                 }
    498         }
    499         // evaluate the sparsity patterns
    500         ForJacSweep(
    501                 dependency,
    502                 n,
    503                 total_num_var,
    504                 &play,
    505                 for_jac_sparsity
    506         );
    507 
    508         // return values corresponding to dependent variables
    509         CPPAD_ASSERT_UNKNOWN( size_t(s.size()) == m || transpose );
    510         CPPAD_ASSERT_UNKNOWN( size_t(s.size()) == q || ! transpose );
    511         for(i = 0; i < m; i++)
    512         {       CPPAD_ASSERT_UNKNOWN( dep_taddr[i] < total_num_var );
    513 
    514                 // extract results from for_jac_sparsity
    515                 // and add corresponding elements to sets in s
    516                 CPPAD_ASSERT_UNKNOWN( for_jac_sparsity.end() == q );
    517                 for_jac_sparsity.begin( dep_taddr[i] );
    518                 j = for_jac_sparsity.next_element();
    519                 while( j < q )
    520                 {       if( transpose )
    521                                 s[j].insert(i);
    522                         else    s[i].insert(j);
    523                         j = for_jac_sparsity.next_element();
    524                 }
    525         }
    526 }
    527 // ---------------------------------------------------------------------------
    528 /*!
    529 Private helper function for ForSparseJac(q, r).
     231Private helper function for ForSparseJac(q, r) boolean sparsity patterns.
    530232
    531233All of the description in the public member function ForSparseJac(q, r)
     
    562264        VectorSet&          s             )
    563265{       size_t m = Range();
     266        size_t n = Domain();
    564267
    565268        // check VectorSet is Simple Vector class with bool elements
     
    569272        s.resize( m * q );
    570273
    571         // store results in s and for_jac_sparse_pack_
    572         ForSparseJacBool(
    573                 transpose        ,
    574                 dependency       ,
    575                 q                ,
    576                 r                ,
    577                 s                ,
    578                 num_var_tape_    ,
    579                 dep_taddr_       ,
    580                 ind_taddr_       ,
    581                 play_            ,
     274        // temporary indices
     275        size_t i, j;
     276        //
     277        CPPAD_ASSERT_KNOWN(
     278                q > 0,
     279                "ForSparseJac: q is not greater than zero"
     280        );
     281        CPPAD_ASSERT_KNOWN(
     282                size_t(r.size()) == n * q,
     283                "ForSparseJac: size of r is not equal to\n"
     284                "q times domain dimension for ADFun object."
     285        );
     286        //
     287        // allocate memory for the requested sparsity calculation result
     288        for_jac_sparse_pack_.resize(num_var_tape_, q);
     289
     290        // set values corresponding to independent variables
     291        for(i = 0; i < n; i++)
     292        {       CPPAD_ASSERT_UNKNOWN( ind_taddr_[i] < num_var_tape_ );
     293                // ind_taddr_[i] is operator taddr for i-th independent variable
     294                CPPAD_ASSERT_UNKNOWN( play_.GetOp( ind_taddr_[i] ) == InvOp );
     295
     296                // set bits that are true
     297                if( transpose )
     298                {       for(j = 0; j < q; j++) if( r[ j * n + i ] )
     299                                for_jac_sparse_pack_.add_element( ind_taddr_[i], j);
     300                }
     301                else
     302                {       for(j = 0; j < q; j++) if( r[ i * q + j ] )
     303                                for_jac_sparse_pack_.add_element( ind_taddr_[i], j);
     304                }
     305        }
     306
     307        // evaluate the sparsity patterns
     308        ForJacSweep(
     309                dependency,
     310                n,
     311                num_var_tape_,
     312                &play_,
    582313                for_jac_sparse_pack_
    583314        );
     315
     316        // return values corresponding to dependent variables
     317        CPPAD_ASSERT_UNKNOWN( size_t(s.size()) == m * q );
     318        for(i = 0; i < m; i++)
     319        {       CPPAD_ASSERT_UNKNOWN( dep_taddr_[i] < num_var_tape_ );
     320
     321                // extract the result from for_jac_sparse_pack_
     322                if( transpose )
     323                {       for(j = 0; j < q; j++)
     324                                s[ j * m + i ] = false;
     325                }
     326                else
     327                {       for(j = 0; j < q; j++)
     328                                s[ i * q + j ] = false;
     329                }
     330                CPPAD_ASSERT_UNKNOWN( for_jac_sparse_pack_.end() == q );
     331                for_jac_sparse_pack_.begin( dep_taddr_[i] );
     332                j = for_jac_sparse_pack_.next_element();
     333                while( j < q )
     334                {       if( transpose )
     335                                s[j * m + i] = true;
     336                        else    s[i * q + j] = true;
     337                        j = for_jac_sparse_pack_.next_element();
     338                }
     339        }
    584340}
    585 
    586 
     341// ---------------------------------------------------------------------------
    587342/*!
    588 Private helper function for \c ForSparseJac(q, r).
     343Private helper function for \c ForSparseJac(q, r) set sparsity.
    589344
    590345All of the description in the public member function \c ForSparseJac(q, r)
     
    621376        VectorSet&                 s             )
    622377{       size_t m = Range();
     378        size_t n = Domain();
    623379
    624380        // check VectorSet is Simple Vector class with sets for elements
     
    632388        else    s.resize( m );
    633389
    634         // store results in r and for_jac_sparse_pack_
    635         CppAD::ForSparseJacSet(
    636                 transpose        ,
    637                 dependency       ,
    638                 q                ,
    639                 r                ,
    640                 s                ,
    641                 num_var_tape_    ,
    642                 dep_taddr_       ,
    643                 ind_taddr_       ,
    644                 play_            ,
     390        // temporary indices
     391        size_t i, j;
     392        std::set<size_t>::const_iterator itr;
     393        //
     394        CPPAD_ASSERT_KNOWN(
     395                q > 0,
     396                "ForSparseJac: q is not greater than zero"
     397        );
     398        CPPAD_ASSERT_KNOWN(
     399                size_t(r.size()) == n || transpose,
     400                "ForSparseJac: size of r is not equal to n and transpose is false."
     401        );
     402        CPPAD_ASSERT_KNOWN(
     403                size_t(r.size()) == q || ! transpose,
     404                "ForSparseJac: size of r is not equal to q and transpose is true."
     405        );
     406        //
     407        // allocate memory for the requested sparsity calculation
     408        for_jac_sparse_set_.resize(num_var_tape_, q);
     409
     410        // set values corresponding to independent variables
     411        if( transpose )
     412        {       for(i = 0; i < q; i++)
     413                {       // add the elements that are present
     414                        itr = r[i].begin();
     415                        while( itr != r[i].end() )
     416                        {       j = *itr++;
     417                                CPPAD_ASSERT_KNOWN(
     418                                j < n,
     419                                "ForSparseJac: transpose is true and element of the set\n"
     420                                "r[j] has value greater than or equal n."
     421                                );
     422                                CPPAD_ASSERT_UNKNOWN( ind_taddr_[j] < num_var_tape_ );
     423                                // operator for j-th independent variable
     424                                CPPAD_ASSERT_UNKNOWN( play_.GetOp( ind_taddr_[j] ) == InvOp );
     425                                for_jac_sparse_set_.add_element( ind_taddr_[j], i);
     426                        }
     427                }
     428        }
     429        else
     430        {       for(i = 0; i < n; i++)
     431                {       CPPAD_ASSERT_UNKNOWN( ind_taddr_[i] < num_var_tape_ );
     432                        // ind_taddr_[i] is operator taddr for i-th independent variable
     433                        CPPAD_ASSERT_UNKNOWN( play_.GetOp( ind_taddr_[i] ) == InvOp );
     434
     435                        // add the elements that are present
     436                        itr = r[i].begin();
     437                        while( itr != r[i].end() )
     438                        {       j = *itr++;
     439                                CPPAD_ASSERT_KNOWN(
     440                                        j < q,
     441                                        "ForSparseJac: an element of the set r[i] "
     442                                        "has value greater than or equal q."
     443                                );
     444                                for_jac_sparse_set_.add_element( ind_taddr_[i], j);
     445                        }
     446                }
     447        }
     448        // evaluate the sparsity patterns
     449        ForJacSweep(
     450                dependency,
     451                n,
     452                num_var_tape_,
     453                &play_,
    645454                for_jac_sparse_set_
    646455        );
     456
     457        // return values corresponding to dependent variables
     458        CPPAD_ASSERT_UNKNOWN( size_t(s.size()) == m || transpose );
     459        CPPAD_ASSERT_UNKNOWN( size_t(s.size()) == q || ! transpose );
     460        for(i = 0; i < m; i++)
     461        {       CPPAD_ASSERT_UNKNOWN( dep_taddr_[i] < num_var_tape_ );
     462
     463                // extract results from for_jac_sparse_set_
     464                // and add corresponding elements to sets in s
     465                CPPAD_ASSERT_UNKNOWN( for_jac_sparse_set_.end() == q );
     466                for_jac_sparse_set_.begin( dep_taddr_[i] );
     467                j = for_jac_sparse_set_.next_element();
     468                while( j < q )
     469                {       if( transpose )
     470                                s[j].insert(i);
     471                        else    s[i].insert(j);
     472                        j = for_jac_sparse_set_.next_element();
     473                }
     474        }
    647475}
    648476// ---------------------------------------------------------------------------
     
    812640void ADFun<Base>::ForSparseJacCheckpoint(
    813641        size_t                        q          ,
    814         CPPAD_INTERNAL_SPARSE_SET&    r          ,
     642        sparse_list&                  r          ,
    815643        bool                          transpose  ,
    816644        bool                          dependency ,
    817         CPPAD_INTERNAL_SPARSE_SET&    s          )
     645        sparse_list&                  s          )
    818646{       size_t n = Domain();
    819647        size_t m = Range();
  • trunk/cppad/local/rev_hes_sweep.hpp

    r3757 r3792  
    44
    55/* --------------------------------------------------------------------------
    6 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-15 Bradley M. Bell
     6CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell
    77
    88CppAD is distributed under multiple licenses. This distribution is under
     
    6262The object \a play is effectly constant.
    6363It is not declared const because while playing back the tape
    64 the object \a play holds information about the currentl location
     64the object \a play holds information about the current location
    6565with in the tape and this changes during playback.
    6666
  • trunk/cppad/local/rev_jac_sweep.hpp

    r3757 r3792  
    44
    55/* --------------------------------------------------------------------------
    6 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-15 Bradley M. Bell
     6CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell
    77
    88CppAD is distributed under multiple licenses. This distribution is under
     
    8787The object \a play is effectly constant.
    8888It is not declared const because while playing back the tape
    89 the object \a play holds information about the currentl location
     89the object \a play holds information about the current location
    9090with in the tape and this changes during playback.
    9191
  • trunk/cppad/local/rev_sparse_hes.hpp

    r3757 r3792  
    44
    55/* --------------------------------------------------------------------------
    6 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-15 Bradley M. Bell
     6CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell
    77
    88CppAD is distributed under multiple licenses. This distribution is under
     
    3737%$$
    3838$icode%h% = %f%.RevSparseHes(%q%, %s%, %transpose%)%$$
    39 
    4039
    4140$head Purpose$$
     
    6867
    6968$head x$$
    70 the sparsity pattern is valid for all values of the independent
    71 variables in $latex x \in \B{R}^n$$
     69If the operation sequence in $icode f$$ is
     70$cref/independent/glossary/Operation/Independent/$$ of
     71the independent variables in $latex x \in B^n$$,
     72the sparsity pattern is valid for all values of
    7273(even if it has $cref CondExp$$ or $cref VecAD$$ operations).
    7374
     
    199200Reverse mode Hessian sparsity patterns.
    200201*/
    201 
    202202// ===========================================================================
    203 // RevSparseHesBool
     203// RevSparseHesCase
    204204/*!
    205 Calculate Hessian sparsity patterns using reverse mode.
    206 
    207 The C++ source code corresponding to this operation is
    208 \verbatim
    209         h = f.RevSparseHes(q, s)
    210 \endverbatim
    211 
    212 \tparam Base
    213 is the base type for this recording.
    214 
    215 \tparam VectorSet
    216 is a simple vector with elements of type \c bool.
     205Private helper function for RevSparseHes(q, s) bool sparsity.
     206
     207All of the description in the public member function RevSparseHes(q, s)
     208applies.
     209
     210\param set_type
     211is a \c bool value. This argument is used to dispatch to the proper source
     212code depending on the vlaue of \c VectorSet::value_type.
    217213
    218214\param transpose
    219 is true (false) if \c is is equal to \f$ H(x) \f$ (\f$ H(x)^T \f$)
    220 where
    221 \f[
    222         H(x) = R^T (S * F)^{(2)} (x)
    223 \f]
    224 where \f$ F \f$ is the function corresponding to the operation sequence
    225 and \a x is any argument value.
     215See \c RevSparseHes(q, s).
    226216
    227217\param q
    228 is the value of \a q in the
    229 by the previous call of the form
    230 \verbatim
    231         f.ForSparseJac(q, r)
    232 \endverbatim
    233 The value \c r in this call is a sparsity pattern for the matrix \f$ R \f$.
     218See \c RevSparseHes(q, s).
    234219
    235220\param s
    236 is a vector with size \c m that specifies the sparsity pattern
    237 for the vector \f$ S \f$,
    238 where \c m is the number of dependent variables
    239 corresponding to the operation sequence stored in \a play.
     221See \c RevSparseHes(q, s).
    240222
    241223\param h
    242 the input value of \a h must be a vector with size \c q*n.
    243 The input value of its elements does not matter.
    244 On output, \a h is the sparsity pattern for the matrix \f$ H(x) \f$
    245 or \f$ H(x)^T \f$ depending on \c transpose.
    246 
    247 \param num_var
    248 is the total number of variables in this recording.
    249 
    250 \param dep_taddr
    251 maps dependendent variable index
    252 to the corresponding variable in the tape.
    253 
    254 \param ind_taddr
    255 maps independent variable index
    256 to the corresponding variable in the tape.
    257 
    258 \param play
    259 is the recording that defines the function we are computing the sparsity
    260 pattern for.
    261 
    262 \param for_jac_sparsity
    263 is a vector of sets containing the
    264 the forward Jacobian sparsity pattern corresponding to
    265 $latex R$$ for all of the variables on the tape.
     224is the return value for the corresponging call to \c RevSparseJac(q, s).
    266225*/
    267 
    268 template <class Base, class VectorSet>
    269 void RevSparseHesBool(
    270         bool                      transpose         ,
    271         size_t                    q                 ,
    272         const VectorSet&          s                 ,
    273         VectorSet&                h                 ,
    274         size_t                    num_var           ,
    275         CppAD::vector<size_t>&    dep_taddr         ,
    276         CppAD::vector<size_t>&    ind_taddr         ,
    277         CppAD::player<Base>&      play              ,
    278         sparse_pack&              for_jac_sparsity  )
    279 {
     226template <class Base>
     227template <class VectorSet>
     228void ADFun<Base>::RevSparseHesCase(
     229        bool              set_type         ,
     230        bool              transpose        ,
     231        size_t            q                ,
     232        const VectorSet&  s                ,
     233        VectorSet&        h                )
     234{       size_t n = Domain();
     235        size_t m = Range();
     236        //
     237        h.resize(q * n );
     238
     239        CPPAD_ASSERT_KNOWN(
     240                for_jac_sparse_pack_.n_set() > 0,
     241                "RevSparseHes: previous stored call to ForSparseJac did not "
     242                "use bool for the elements of r."
     243        );
     244        CPPAD_ASSERT_UNKNOWN( for_jac_sparse_set_.n_set() == 0 );
     245        CPPAD_ASSERT_UNKNOWN( for_jac_sparse_pack_.n_set() == num_var_tape_  );
     246        //
    280247        // temporary indices
    281248        size_t i, j;
     
    284251        CheckSimpleVector<bool, VectorSet>();
    285252
    286         // range and domain dimensions for F
    287         size_t m = dep_taddr.size();
    288         size_t n = ind_taddr.size();
    289 
    290253        CPPAD_ASSERT_KNOWN(
    291                 q == for_jac_sparsity.end(),
     254                q == for_jac_sparse_pack_.end(),
    292255                "RevSparseHes: q is not equal to its value\n"
    293256                "in the previous call to ForSparseJac with this ADFun object."
     
    302265        // Initialize as true for the dependent variables.
    303266        pod_vector<bool> RevJac;
    304         RevJac.extend(num_var);
    305         for(i = 0; i < num_var; i++)
     267        RevJac.extend(num_var_tape_);
     268        for(i = 0; i < num_var_tape_; i++)
    306269                RevJac[i] = false;
    307270        for(i = 0; i < m; i++)
    308         {       CPPAD_ASSERT_UNKNOWN( dep_taddr[i] < num_var );
    309                 RevJac[ dep_taddr[i] ] = s[i];
     271        {       CPPAD_ASSERT_UNKNOWN( dep_taddr_[i] < num_var_tape_ );
     272                RevJac[ dep_taddr_[i] ] = s[i];
    310273        }
    311274
    312275        // vector of sets that will hold reverse Hessain values
    313276        sparse_pack rev_hes_sparsity;
    314         rev_hes_sparsity.resize(num_var, q);
     277        rev_hes_sparsity.resize(num_var_tape_, q);
    315278
    316279        // compute the Hessian sparsity patterns
    317280        RevHesSweep(
    318281                n,
    319                 num_var,
    320                 &play,
    321                 for_jac_sparsity,
     282                num_var_tape_,
     283                &play_,
     284                for_jac_sparse_pack_,
    322285                RevJac.data(),
    323286                rev_hes_sparsity
     
    336299        // j is index corresponding to reverse mode partial
    337300        for(j = 0; j < n; j++)
    338         {       CPPAD_ASSERT_UNKNOWN( ind_taddr[j] < num_var );
    339 
    340                 // ind_taddr[j] is operator taddr for j-th independent variable
    341                 CPPAD_ASSERT_UNKNOWN( ind_taddr[j] == j + 1 );
    342                 CPPAD_ASSERT_UNKNOWN( play.GetOp( ind_taddr[j] ) == InvOp );
     301        {       CPPAD_ASSERT_UNKNOWN( ind_taddr_[j] < num_var_tape_ );
     302
     303                // ind_taddr_[j] is operator taddr for j-th independent variable
     304                CPPAD_ASSERT_UNKNOWN( ind_taddr_[j] == j + 1 );
     305                CPPAD_ASSERT_UNKNOWN( play_.GetOp( ind_taddr_[j] ) == InvOp );
    343306
    344307                // extract the result from rev_hes_sparsity
     
    353316                }
    354317        }
    355 
    356         return;
    357318}
    358 
    359 // ===========================================================================
    360 // RevSparseHesSet
    361319/*!
    362 Calculate Hessian sparsity patterns using reverse mode.
    363 
    364 The C++ source code corresponding to this operation is
    365 \verbatim
    366         h = f.RevSparseHes(q, s)
    367 \endverbatim
    368 
    369 \tparam Base
    370 is the base type for this recording.
    371 
    372 \tparam VectorSet
    373 is a simple vector with elements of type \c std::set<size_t>.
     320Private helper function for RevSparseHes(q, s) set sparsity.
     321
     322All of the description in the public member function RevSparseHes(q, s)
     323applies.
     324
     325\param set_type
     326is a \c std::set<size_t> value.
     327This argument is used to dispatch to the proper source
     328code depending on the vlaue of \c VectorSet::value_type.
    374329
    375330\param transpose
    376 is true (false) if \c is is equal to \f$ H(x) \f$ (\f$ H(x)^T \f$)
    377 where
    378 \f[
    379         H(x) = R^T (S * F)^{(2)} (x)
    380 \f]
    381 where \f$ F \f$ is the function corresponding to the operation sequence
    382 and \a x is any argument value.
     331See \c RevSparseHes(q, s).
    383332
    384333\param q
    385 is the value of \a q in the
    386 by the previous call of the form
    387 \verbatim
    388         f.ForSparseJac(q, r)
    389 \endverbatim
    390 The value \c r in this call is a sparsity pattern for the matrix \f$ R \f$.
     334See \c RevSparseHes(q, s).
    391335
    392336\param s
    393 is a vector with size \c m that specifies the sparsity pattern
    394 for the vector \f$ S \f$,
    395 where \c m is the number of dependent variables
    396 corresponding to the operation sequence stored in \a play.
     337See \c RevSparseHes(q, s).
    397338
    398339\param h
    399 If \c transpose, the input value of \a h must be a vector with size \a q.
    400 Otherwise, its input value must have size \c n;
    401 On input, each element of \a h must be an empty set.
    402 On output, \a h is the sparsity pattern for the matrix \f$ H(x) \f$
    403 or \f$ H(x)^T \f$ depending on \c transpose.
    404 
    405 \param num_var
    406 is the total number of variables in this recording.
    407 
    408 \param dep_taddr
    409 maps dependendent variable index
    410 to the corresponding variable in the tape.
    411 
    412 \param ind_taddr
    413 maps independent variable index
    414 to the corresponding variable in the tape.
    415 
    416 \param play
    417 is the recording that defines the function we are computing the sparsity
    418 pattern for.
    419 
    420 \param for_jac_sparsity
    421 is a vector of sets containing the
    422 the forward Jacobian sparsity pattern corresponding to
    423 $latex R$$ for all of the variables on the tape.
     340is the return value for the corresponging call to \c RevSparseJac(q, s).
    424341*/
    425 
    426 template <class Base, class VectorSet>
    427 void RevSparseHesSet(
    428         bool                       transpose         ,
    429         size_t                     q                 ,
    430         const  VectorSet&          s                 ,
    431         VectorSet&                 h                 ,
    432         size_t                     num_var           ,
    433         CppAD::vector<size_t>&     dep_taddr         ,
    434         CppAD::vector<size_t>&     ind_taddr         ,
    435         CppAD::player<Base>&       play              ,
    436         CPPAD_INTERNAL_SPARSE_SET& for_jac_sparsity  )
    437 {
     342template <class Base>
     343template <class VectorSet>
     344void ADFun<Base>::RevSparseHesCase(
     345        const std::set<size_t>&   set_type         ,
     346        bool                      transpose        ,
     347        size_t                    q                ,
     348        const VectorSet&          s                ,
     349        VectorSet&                h                )
     350{       size_t n = Domain();
     351# ifndef NDEBUG
     352        size_t m = Range();
     353# endif
     354        //
     355        if( transpose )
     356                h.resize(n);
     357        else    h.resize(q);
     358
     359        CPPAD_ASSERT_KNOWN(
     360                for_jac_sparse_set_.n_set() > 0,
     361                "RevSparseHes: previous stored call to ForSparseJac did not "
     362                "use std::set<size_t> for the elements of r."
     363        );
     364        CPPAD_ASSERT_UNKNOWN( for_jac_sparse_pack_.n_set() == 0 );
     365        CPPAD_ASSERT_UNKNOWN( for_jac_sparse_set_.n_set() == num_var_tape_  );
     366        //
    438367        // temporary indices
    439368        size_t i, j;
     
    445374        );
    446375
    447         // range and domain dimensions for F
    448 # ifndef NDEBUG
    449         size_t m = dep_taddr.size();
    450 # endif
    451         size_t n = ind_taddr.size();
    452 
    453376        CPPAD_ASSERT_KNOWN(
    454                 q == for_jac_sparsity.end(),
     377                q == for_jac_sparse_set_.end(),
    455378                "RevSparseHes: q is not equal to its value\n"
    456379                "in the previous call to ForSparseJac with this ADFun object."
     
    464387        // Initialize as true for the dependent variables.
    465388        pod_vector<bool> RevJac;
    466         RevJac.extend(num_var);
    467         for(i = 0; i < num_var; i++)
     389        RevJac.extend(num_var_tape_);
     390        for(i = 0; i < num_var_tape_; i++)
    468391                RevJac[i] = false;
    469392        itr = s[0].begin();
     
    475398                        "greater than or equal m"
    476399                );
    477                 CPPAD_ASSERT_UNKNOWN( dep_taddr[i] < num_var );
    478                 RevJac[ dep_taddr[i] ] = true;
     400                CPPAD_ASSERT_UNKNOWN( dep_taddr_[i] < num_var_tape_ );
     401                RevJac[ dep_taddr_[i] ] = true;
    479402        }
    480403
    481404
    482405        // vector of sets that will hold reverse Hessain values
    483         CPPAD_INTERNAL_SPARSE_SET rev_hes_sparsity;
    484         rev_hes_sparsity.resize(num_var, q);
     406        sparse_list rev_hes_sparsity;
     407        rev_hes_sparsity.resize(num_var_tape_, q);
    485408
    486409        // compute the Hessian sparsity patterns
    487410        RevHesSweep(
    488411                n,
    489                 num_var,
    490                 &play,
    491                 for_jac_sparsity,
     412                num_var_tape_,
     413                &play_,
     414                for_jac_sparse_set_,
    492415                RevJac.data(),
    493416                rev_hes_sparsity
     
    499422        CPPAD_ASSERT_UNKNOWN( size_t(h.size()) == n || ! transpose );
    500423        for(j = 0; j < n; j++)
    501         {       CPPAD_ASSERT_UNKNOWN( ind_taddr[j] < num_var );
    502                 CPPAD_ASSERT_UNKNOWN( ind_taddr[j] == j + 1 );
    503                 CPPAD_ASSERT_UNKNOWN( play.GetOp( ind_taddr[j] ) == InvOp );
     424        {       CPPAD_ASSERT_UNKNOWN( ind_taddr_[j] < num_var_tape_ );
     425                CPPAD_ASSERT_UNKNOWN( ind_taddr_[j] == j + 1 );
     426                CPPAD_ASSERT_UNKNOWN( play_.GetOp( ind_taddr_[j] ) == InvOp );
    504427
    505428                // extract the result from rev_hes_sparsity
     
    515438                }
    516439        }
    517 
    518         return;
    519440}
    520441
     
    593514}
    594515// ===========================================================================
    595 // RevSparseHesCase
    596 /*!
    597 Private helper function for RevSparseHes(q, s).
    598 
    599 All of the description in the public member function RevSparseHes(q, s)
    600 applies.
    601 
    602 \param set_type
    603 is a \c bool value. This argument is used to dispatch to the proper source
    604 code depending on the vlaue of \c VectorSet::value_type.
    605 
    606 \param transpose
    607 See \c RevSparseHes(q, s).
    608 
    609 \param q
    610 See \c RevSparseHes(q, s).
    611 
    612 \param s
    613 See \c RevSparseHes(q, s).
    614 
    615 \param h
    616 is the return value for the corresponging call to \c RevSparseJac(q, s).
    617 */
    618 template <class Base>
    619 template <class VectorSet>
    620 void ADFun<Base>::RevSparseHesCase(
    621         bool              set_type         ,
    622         bool              transpose        ,
    623         size_t            q                ,
    624         const VectorSet&  s                ,
    625         VectorSet&        h                )
    626 {       size_t n = Domain();
    627         h.resize(q * n );
    628 
    629         CPPAD_ASSERT_KNOWN(
    630                 for_jac_sparse_pack_.n_set() > 0,
    631                 "RevSparseHes: previous stored call to ForSparseJac did not "
    632                 "use bool for the elements of r."
    633         );
    634         CPPAD_ASSERT_UNKNOWN( for_jac_sparse_set_.n_set() == 0 );
    635         CPPAD_ASSERT_UNKNOWN( for_jac_sparse_pack_.n_set() == num_var_tape_  );
    636 
    637         // use sparse_pack for the calculation
    638         CppAD::RevSparseHesBool(
    639                 transpose                ,
    640                 q                        ,
    641                 s                        ,
    642                 h                        ,
    643                 num_var_tape_            ,
    644                 dep_taddr_               ,
    645                 ind_taddr_               ,
    646                 play_                    ,
    647                 for_jac_sparse_pack_
    648         );
    649 }
    650 /*!
    651 Private helper function for RevSparseHes(q, s).
    652 
    653 All of the description in the public member function RevSparseHes(q, s)
    654 applies.
    655 
    656 \param set_type
    657 is a \c std::set<size_t> value.
    658 This argument is used to dispatch to the proper source
    659 code depending on the vlaue of \c VectorSet::value_type.
    660 
    661 \param transpose
    662 See \c RevSparseHes(q, s).
    663 
    664 \param q
    665 See \c RevSparseHes(q, s).
    666 
    667 \param s
    668 See \c RevSparseHes(q, s).
    669 
    670 \param h
    671 is the return value for the corresponging call to \c RevSparseJac(q, s).
    672 */
    673 template <class Base>
    674 template <class VectorSet>
    675 void ADFun<Base>::RevSparseHesCase(
    676         const std::set<size_t>&   set_type         ,
    677         bool                      transpose        ,
    678         size_t                    q                ,
    679         const VectorSet&          s                ,
    680         VectorSet&                h                )
    681 {       size_t n = Domain();
    682         if( transpose )
    683                 h.resize(n);
    684         else    h.resize(q);
    685 
    686         CPPAD_ASSERT_KNOWN(
    687                 for_jac_sparse_set_.n_set() > 0,
    688                 "RevSparseHes: previous stored call to ForSparseJac did not "
    689                 "use std::set<size_t> for the elements of r."
    690         );
    691         CPPAD_ASSERT_UNKNOWN( for_jac_sparse_pack_.n_set() == 0 );
    692         CPPAD_ASSERT_UNKNOWN( for_jac_sparse_set_.n_set() == num_var_tape_  );
    693 
    694         // use sparse_pack for the calculation
    695         CppAD::RevSparseHesSet(
    696                 transpose                ,
    697                 q                        ,
    698                 s                        ,
    699                 h                        ,
    700                 num_var_tape_            ,
    701                 dep_taddr_               ,
    702                 ind_taddr_               ,
    703                 play_                    ,
    704                 for_jac_sparse_set_
    705         );
    706 }
    707 // ===========================================================================
    708516// RevSparseHesCheckpoint
    709517/*!
     
    749557        vector<bool>&                 s         ,
    750558        bool                          transpose ,
    751         CPPAD_INTERNAL_SPARSE_SET&    h         )
     559        sparse_list&                  h         )
    752560{       size_t n = Domain();
    753561        size_t m = Range();
     
    771579
    772580        // holds reverse Hessian sparsity pattern for all variables
    773         CPPAD_INTERNAL_SPARSE_SET rev_hes_sparsity;
     581        sparse_list rev_hes_sparsity;
    774582        rev_hes_sparsity.resize(num_var_tape_, q);
    775583
  • trunk/cppad/local/rev_sparse_jac.hpp

    r3757 r3792  
    44
    55/* --------------------------------------------------------------------------
    6 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-15 Bradley M. Bell
     6CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell
    77
    88CppAD is distributed under multiple licenses. This distribution is under
     
    3434$mindex RevSparseJac sparse$$
    3535
    36 
    3736$head Syntax$$
    3837$icode%s% = %f%.RevSparseJac(%q%, %r%)
     
    6160
    6261$head x$$
    63 the sparsity pattern is valid for all values of the independent
    64 variables in $latex x \in B^n$$
     62If the operation sequence in $icode f$$ is
     63$cref/independent/glossary/Operation/Independent/$$ of
     64the independent variables in $latex x \in B^n$$,
     65the sparsity pattern is valid for all values of
    6566(even if it has $cref CondExp$$ or $cref VecAD$$ operations).
    6667
     
    178179Reverse mode Jacobian sparsity patterns.
    179180*/
    180 
    181 // =========================================================================
    182 // RevSparseJacBool
    183 /*!
    184 Calculate Jacobian vector of bools sparsity patterns using reverse mode.
    185 
    186 The C++ source code corresponding to this operation is
    187 \verbatim
    188         s = f.RevSparseJac(q, r)
    189 \endverbatim
    190 
    191 \tparam Base
    192 is the base type for this recording.
    193 
    194 \tparam VectorSet
    195 is a simple vector class with elements of type \c bool.
    196 
    197 \param transpose
    198 are the sparsity patterns transposed.
    199 
    200 \param dependency
    201 Are the derivatives with respect to left and right of the expression below
    202 considered to be non-zero:
    203 \code
    204         CondExpRel(left, right, if_true, if_false)
    205 \endcode
    206 This is used by the optimizer to obtain the correct dependency relations.
    207 
    208 \param q
    209 is the number of rows in the matrix \f$ R \f$.
    210 
    211 \param r
    212 is a sparsity pattern for the matrix \f$ R \f$.
    213 
    214 \param s
    215 the input value of \a s must be a vector with size <tt>p*n</tt>
    216 where \c n is the number of independent variables
    217 corresponding to the operation sequence stored in \a play.
    218 The input value of the components of \c s does not matter.
    219 On output, \a s is the sparsity pattern for the matrix
    220 \f[
    221         S(x) = R * F^{(1)} (x)
    222 \f]
    223 where \f$ F \f$ is the function corresponding to the operation sequence
    224 and \a x is any argument value.
    225 
    226 \param total_num_var
    227 is the total number of variable in this recording.
    228 
    229 \param dep_taddr
    230 maps dependendent variable index
    231 to the corresponding variable in the tape.
    232 
    233 \param ind_taddr
    234 maps independent variable index
    235 to the corresponding variable in the tape.
    236 
    237 \param play
    238 is the recording that defines the function we are computing the sparsity
    239 pattern for.
    240 */
    241 
    242 template <class Base, class VectorSet>
    243 void RevSparseJacBool(
    244         bool                   transpose        ,
    245         bool                   dependency       ,
    246         size_t                 q                ,
    247         const VectorSet&       r                ,
    248         VectorSet&             s                ,
    249         size_t                 total_num_var    ,
    250         CppAD::vector<size_t>& dep_taddr        ,
    251         CppAD::vector<size_t>& ind_taddr        ,
    252         CppAD::player<Base>&   play             )
    253 {
    254         // temporary indices
    255         size_t i, j;
    256 
    257         // check VectorSet is Simple Vector class with bool elements
    258         CheckSimpleVector<bool, VectorSet>();
    259 
    260         // range and domain dimensions for F
    261         size_t m = dep_taddr.size();
    262         size_t n = ind_taddr.size();
    263 
    264         CPPAD_ASSERT_KNOWN(
    265                 q > 0,
    266                 "RevSparseJac: q is not greater than zero"
    267         );
    268         CPPAD_ASSERT_KNOWN(
    269                 size_t(r.size()) == q * m,
    270                 "RevSparseJac: size of r is not equal to\n"
    271                 "q times range dimension for ADFun object."
    272         );
    273 
    274         // vector of sets that will hold the results
    275         sparse_pack    var_sparsity;
    276         var_sparsity.resize(total_num_var, q);
    277 
    278         // The sparsity pattern corresponding to the dependent variables
    279         for(i = 0; i < m; i++)
    280         {       CPPAD_ASSERT_UNKNOWN( dep_taddr[i] < total_num_var );
    281                 if( transpose )
    282                 {       for(j = 0; j < q; j++) if( r[ i * q + j ] )
    283                                 var_sparsity.add_element( dep_taddr[i], j );
    284                 }
    285                 else
    286                 {       for(j = 0; j < q; j++) if( r[ j * m + i ] )
    287                                 var_sparsity.add_element( dep_taddr[i], j );
    288                 }
    289         }
    290 
    291         // evaluate the sparsity patterns
    292         RevJacSweep(
    293                 dependency,
    294                 n,
    295                 total_num_var,
    296                 &play,
    297                 var_sparsity
    298         );
    299 
    300         // return values corresponding to dependent variables
    301         CPPAD_ASSERT_UNKNOWN( size_t(s.size()) == q * n );
    302         for(j = 0; j < n; j++)
    303         {       CPPAD_ASSERT_UNKNOWN( ind_taddr[j] == (j+1) );
    304 
    305                 // ind_taddr[j] is operator taddr for j-th independent variable
    306                 CPPAD_ASSERT_UNKNOWN( play.GetOp( ind_taddr[j] ) == InvOp );
    307 
    308                 // extract the result from var_sparsity
    309                 if( transpose )
    310                 {       for(i = 0; i < q; i++)
    311                                 s[ j * q + i ] = false;
    312                 }
    313                 else
    314                 {       for(i = 0; i < q; i++)
    315                                 s[ i * n + j ] = false;
    316                 }
    317                 CPPAD_ASSERT_UNKNOWN( var_sparsity.end() == q );
    318                 var_sparsity.begin(j+1);
    319                 i = var_sparsity.next_element();
    320                 while( i < q )
    321                 {       if( transpose )
    322                                 s[ j * q + i ] = true;
    323                         else    s[ i * n + j ] = true;
    324                         i  = var_sparsity.next_element();
    325                 }
    326         }
    327 }
    328 // =========================================================================
    329 // RevSparseJacSet
    330 /*!
    331 Calculate Jacobian vector of sets sparsity patterns using reverse mode.
    332 
    333 The C++ source code corresponding to this operation is
    334 \verbatim
    335         s = f.RevSparseJac(q, r)
    336 \endverbatim
    337 
    338 \tparam Base
    339 see \c RevSparseJacBool.
    340 
    341 \tparam VectorSet
    342 is a simple vector class with elements of type \c std::set<size_t>.
    343 
    344 \param transpose
    345 see \c RevSparseJacBool.
    346 
    347 \param dependency
    348 see \c RevSparseJacBool.
    349 
    350 \param q
    351 see \c RevSparseJacBool.
    352 
    353 \param r
    354 see \c RevSparseJacBool.
    355 
    356 \param s
    357 see \c RevSparseJacBool.
    358 
    359 \param total_num_var
    360 see \c RevSparseJacBool.
    361 
    362 \param dep_taddr
    363 see \c RevSparseJacBool.
    364 
    365 \param ind_taddr
    366 see \c RevSparseJacBool.
    367 
    368 \param play
    369 see \c RevSparseJacBool.
    370 */
    371 template <class Base, class VectorSet>
    372 void RevSparseJacSet(
    373         bool                   transpose        ,
    374         bool                   dependency       ,
    375         size_t                 q                ,
    376         const VectorSet&       r                ,
    377         VectorSet&             s                ,
    378         size_t                 total_num_var    ,
    379         CppAD::vector<size_t>& dep_taddr        ,
    380         CppAD::vector<size_t>& ind_taddr        ,
    381         CppAD::player<Base>&   play             )
    382 {
    383         // temporary indices
    384         size_t i, j;
    385         std::set<size_t>::const_iterator itr;
    386 
    387         // check VectorSet is Simple Vector class with sets for elements
    388         CheckSimpleVector<std::set<size_t>, VectorSet>(
    389                 one_element_std_set<size_t>(), two_element_std_set<size_t>()
    390         );
    391 
    392         // domain dimensions for F
    393         size_t n = ind_taddr.size();
    394         size_t m = dep_taddr.size();
    395 
    396         CPPAD_ASSERT_KNOWN(
    397                 q > 0,
    398                 "RevSparseJac: q is not greater than zero"
    399         );
    400         CPPAD_ASSERT_KNOWN(
    401                 size_t(r.size()) == q || transpose,
    402                 "RevSparseJac: size of r is not equal to q and transpose is false."
    403         );
    404         CPPAD_ASSERT_KNOWN(
    405                 size_t(r.size()) == m || ! transpose,
    406                 "RevSparseJac: size of r is not equal to m and transpose is true."
    407         );
    408 
    409         // vector of lists that will hold the results
    410         CPPAD_INTERNAL_SPARSE_SET    var_sparsity;
    411         var_sparsity.resize(total_num_var, q);
    412 
    413         // The sparsity pattern corresponding to the dependent variables
    414         if( transpose )
    415         {       for(i = 0; i < m; i++)
    416                 {       itr = r[i].begin();
    417                         while(itr != r[i].end())
    418                         {       j = *itr++;
    419                                 CPPAD_ASSERT_KNOWN(
    420                                 j < q,
    421                                 "RevSparseJac: transpose is true and element of the set\n"
    422                                 "r[i] has value greater than or equal q."
    423                                 );
    424                                 CPPAD_ASSERT_UNKNOWN( dep_taddr[i] < total_num_var );
    425                                 var_sparsity.add_element( dep_taddr[i], j );
    426                         }
    427                 }
    428         }
    429         else
    430         {       for(i = 0; i < q; i++)
    431                 {       itr = r[i].begin();
    432                         while(itr != r[i].end())
    433                         {       j = *itr++;
    434                                 CPPAD_ASSERT_KNOWN(
    435                                 j < m,
    436                                 "RevSparseJac: transpose is false and element of the set\n"
    437                                 "r[i] has value greater than or equal range dimension."
    438                                 );
    439                                 CPPAD_ASSERT_UNKNOWN( dep_taddr[j] < total_num_var );
    440                                 var_sparsity.add_element( dep_taddr[j], i );
    441                         }
    442                 }
    443         }
    444         // evaluate the sparsity patterns
    445         RevJacSweep(
    446                 dependency,
    447                 n,
    448                 total_num_var,
    449                 &play,
    450                 var_sparsity
    451         );
    452 
    453         // return values corresponding to dependent variables
    454         CPPAD_ASSERT_UNKNOWN( size_t(s.size()) == q || transpose );
    455         CPPAD_ASSERT_UNKNOWN( size_t(s.size()) == n || ! transpose );
    456         for(j = 0; j < n; j++)
    457         {       CPPAD_ASSERT_UNKNOWN( ind_taddr[j] == (j+1) );
    458 
    459                 // ind_taddr[j] is operator taddr for j-th independent variable
    460                 CPPAD_ASSERT_UNKNOWN( play.GetOp( ind_taddr[j] ) == InvOp );
    461 
    462                 CPPAD_ASSERT_UNKNOWN( var_sparsity.end() == q );
    463                 var_sparsity.begin(j+1);
    464                 i = var_sparsity.next_element();
    465                 while( i < q )
    466                 {       if( transpose )
    467                                 s[j].insert(i);
    468                         else    s[i].insert(j);
    469                         i = var_sparsity.next_element();
    470                 }
    471         }
    472 }
    473181// =========================================================================
    474182// RevSparseJacCase
    475183
    476184/*!
    477 Private helper function for \c RevSparseJac(q, r, transpose).
     185Private helper function for RevSparseJac(q, r, transpose) boolean sparsity.
    478186
    479187All of the description in the public member function
     
    512220        VectorSet&          s                 )
    513221{       size_t n = Domain();
     222        size_t m = Range();
    514223
    515224        // dimension of the result vector
    516225        s.resize( q * n );
    517226
    518         // store results in s
    519         RevSparseJacBool(
    520                 transpose      ,
    521                 dependency     ,
    522                 q              ,
    523                 r              ,
    524                 s              ,
    525                 num_var_tape_  ,
    526                 dep_taddr_     ,
    527                 ind_taddr_     ,
    528                 play_
    529         );
     227        // temporary indices
     228        size_t i, j;
     229
     230        // check VectorSet is Simple Vector class with bool elements
     231        CheckSimpleVector<bool, VectorSet>();
     232        //
     233        CPPAD_ASSERT_KNOWN(
     234                q > 0,
     235                "RevSparseJac: q is not greater than zero"
     236        );
     237        CPPAD_ASSERT_KNOWN(
     238                size_t(r.size()) == q * m,
     239                "RevSparseJac: size of r is not equal to\n"
     240                "q times range dimension for ADFun object."
     241        );
     242        //
     243        // vector of sets that will hold the results
     244        sparse_pack    var_sparsity;
     245        var_sparsity.resize(num_var_tape_, q);
     246
     247        // The sparsity pattern corresponding to the dependent variables
     248        for(i = 0; i < m; i++)
     249        {       CPPAD_ASSERT_UNKNOWN( dep_taddr_[i] < num_var_tape_ );
     250                if( transpose )
     251                {       for(j = 0; j < q; j++) if( r[ i * q + j ] )
     252                                var_sparsity.add_element( dep_taddr_[i], j );
     253                }
     254                else
     255                {       for(j = 0; j < q; j++) if( r[ j * m + i ] )
     256                                var_sparsity.add_element( dep_taddr_[i], j );
     257                }
     258        }
     259
     260        // evaluate the sparsity patterns
     261        RevJacSweep(
     262                dependency,
     263                n,
     264                num_var_tape_,
     265                &play_,
     266                var_sparsity
     267        );
     268
     269        // return values corresponding to dependent variables
     270        CPPAD_ASSERT_UNKNOWN( size_t(s.size()) == q * n );
     271        for(j = 0; j < n; j++)
     272        {       CPPAD_ASSERT_UNKNOWN( ind_taddr_[j] == (j+1) );
     273
     274                // ind_taddr_[j] is operator taddr for j-th independent variable
     275                CPPAD_ASSERT_UNKNOWN( play_.GetOp( ind_taddr_[j] ) == InvOp );
     276
     277                // extract the result from var_sparsity
     278                if( transpose )
     279                {       for(i = 0; i < q; i++)
     280                                s[ j * q + i ] = false;
     281                }
     282                else
     283                {       for(i = 0; i < q; i++)
     284                                s[ i * n + j ] = false;
     285                }
     286                CPPAD_ASSERT_UNKNOWN( var_sparsity.end() == q );
     287                var_sparsity.begin(j+1);
     288                i = var_sparsity.next_element();
     289                while( i < q )
     290                {       if( transpose )
     291                                s[ j * q + i ] = true;
     292                        else    s[ i * n + j ] = true;
     293                        i  = var_sparsity.next_element();
     294                }
     295        }
    530296}
    531297
    532298/*!
    533 Private helper function for \c RevSparseJac(q, r, transpose).
     299Private helper function for RevSparseJac(q, r, transpose) set sparsity
    534300
    535301All of the description in the public member function
     
    571337        else    s.resize( q );
    572338
    573         // store results in r
    574         RevSparseJacSet(
    575                 transpose      ,
    576                 dependency     ,
    577                 q              ,
    578                 r              ,
    579                 s              ,
    580                 num_var_tape_  ,
    581                 dep_taddr_     ,
    582                 ind_taddr_     ,
    583                 play_
    584         );
     339        // temporary indices
     340        size_t i, j;
     341        std::set<size_t>::const_iterator itr;
     342
     343        // check VectorSet is Simple Vector class with sets for elements
     344        CheckSimpleVector<std::set<size_t>, VectorSet>(
     345                one_element_std_set<size_t>(), two_element_std_set<size_t>()
     346        );
     347
     348        // domain dimensions for F
     349        size_t n = ind_taddr_.size();
     350        size_t m = dep_taddr_.size();
     351
     352        CPPAD_ASSERT_KNOWN(
     353                q > 0,
     354                "RevSparseJac: q is not greater than zero"
     355        );
     356        CPPAD_ASSERT_KNOWN(
     357                size_t(r.size()) == q || transpose,
     358                "RevSparseJac: size of r is not equal to q and transpose is false."
     359        );
     360        CPPAD_ASSERT_KNOWN(
     361                size_t(r.size()) == m || ! transpose,
     362                "RevSparseJac: size of r is not equal to m and transpose is true."
     363        );
     364
     365        // vector of lists that will hold the results
     366        sparse_list                  var_sparsity;
     367        var_sparsity.resize(num_var_tape_, q);
     368
     369        // The sparsity pattern corresponding to the dependent variables
     370        if( transpose )
     371        {       for(i = 0; i < m; i++)
     372                {       itr = r[i].begin();
     373                        while(itr != r[i].end())
     374                        {       j = *itr++;
     375                                CPPAD_ASSERT_KNOWN(
     376                                j < q,
     377                                "RevSparseJac: transpose is true and element of the set\n"
     378                                "r[i] has value greater than or equal q."
     379                                );
     380                                CPPAD_ASSERT_UNKNOWN( dep_taddr_[i] < num_var_tape_ );
     381                                var_sparsity.add_element( dep_taddr_[i], j );
     382                        }
     383                }
     384        }
     385        else
     386        {       for(i = 0; i < q; i++)
     387                {       itr = r[i].begin();
     388                        while(itr != r[i].end())
     389                        {       j = *itr++;
     390                                CPPAD_ASSERT_KNOWN(
     391                                j < m,
     392                                "RevSparseJac: transpose is false and element of the set\n"
     393                                "r[i] has value greater than or equal range dimension."
     394                                );
     395                                CPPAD_ASSERT_UNKNOWN( dep_taddr_[j] < num_var_tape_ );
     396                                var_sparsity.add_element( dep_taddr_[j], i );
     397                        }
     398                }
     399        }
     400        // evaluate the sparsity patterns
     401        RevJacSweep(
     402                dependency,
     403                n,
     404                num_var_tape_,
     405                &play_,
     406                var_sparsity
     407        );
     408
     409        // return values corresponding to dependent variables
     410        CPPAD_ASSERT_UNKNOWN( size_t(s.size()) == q || transpose );
     411        CPPAD_ASSERT_UNKNOWN( size_t(s.size()) == n || ! transpose );
     412        for(j = 0; j < n; j++)
     413        {       CPPAD_ASSERT_UNKNOWN( ind_taddr_[j] == (j+1) );
     414
     415                // ind_taddr_[j] is operator taddr for j-th independent variable
     416                CPPAD_ASSERT_UNKNOWN( play_.GetOp( ind_taddr_[j] ) == InvOp );
     417
     418                CPPAD_ASSERT_UNKNOWN( var_sparsity.end() == q );
     419                var_sparsity.begin(j+1);
     420                i = var_sparsity.next_element();
     421                while( i < q )
     422                {       if( transpose )
     423                                s[j].insert(i);
     424                        else    s[i].insert(j);
     425                        i = var_sparsity.next_element();
     426                }
     427        }
    585428}
     429
    586430// =========================================================================
    587431// RevSparseJac
     
    697541void ADFun<Base>::RevSparseJacCheckpoint(
    698542        size_t                        q          ,
    699         CPPAD_INTERNAL_SPARSE_SET&    r          ,
     543        sparse_list&                  r          ,
    700544        bool                          transpose  ,
    701545        bool                          dependency ,
    702         CPPAD_INTERNAL_SPARSE_SET&    s          )
     546        sparse_list&                  s          )
    703547{       size_t n = Domain();
    704548        size_t m = Range();
     
    718562
    719563        // holds reverse Jacobian sparsity pattern for all variables
    720         CPPAD_INTERNAL_SPARSE_SET var_sparsity;
     564        sparse_list var_sparsity;
    721565        var_sparsity.resize(num_var_tape_, q);
    722566
  • trunk/cppad/local/sparse_hessian.hpp

    r3757 r3792  
    44
    55/* --------------------------------------------------------------------------
    6 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-15 Bradley M. Bell
     6CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell
    77
    88CppAD is distributed under multiple licenses. This distribution is under
     
    646646        if( work.color.size() == 0 )
    647647        {       bool transpose = false;
    648                 sparsity_user2internal(s, p, n, n, transpose);
     648                const char* error_msg = "SparseHessian: sparsity pattern"
     649                " does not have proper row or column dimension";
     650                sparsity_user2internal(s, p, n, n, transpose, error_msg);
    649651        }
    650652        n_sweep = SparseHessianCompute(x, w, s, row, col, hes, work);
     
    718720        sparse_hessian_work   work;
    719721        bool transpose = false;
    720         sparsity_user2internal(s, p, n, n, transpose);
     722        const char* error_msg = "SparseHessian: sparsity pattern"
     723        " does not have proper row or column dimension";
     724        sparsity_user2internal(s, p, n, n, transpose, error_msg);
    721725        k = 0;
    722726        for(i = 0; i < n; i++)
  • trunk/cppad/local/sparse_jacobian.hpp

    r3757 r3792  
    44
    55/* --------------------------------------------------------------------------
    6 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-15 Bradley M. Bell
     6CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell
    77
    88CppAD is distributed under multiple licenses. This distribution is under
     
    780780        if( work.color.size() == 0 )
    781781        {       bool transpose = true;
    782                 sparsity_user2internal(s_transpose, p, m, n, transpose);
     782                const char* error_msg = "SparseJacobianForward: transposed sparsity"
     783                " pattern does not have proper row or column dimension";
     784                sparsity_user2internal(s_transpose, p, n, m, transpose, error_msg);
    783785        }
    784786        n_sweep = SparseJacobianFor(x, s_transpose, row, col, jac, work);
     
    893895        if( work.color.size() == 0 )
    894896        {       bool transpose = false;
    895                 sparsity_user2internal(s, p, m, n, transpose);
     897                const char* error_msg = "SparseJacobianReverse: sparsity"
     898                " pattern does not have proper row or column dimension";
     899                sparsity_user2internal(s, p, m, n, transpose, error_msg);
    896900        }
    897901        n_sweep = SparseJacobianRev(x, s, row, col, jac, work);
     
    961965                Pattern_type s_transpose;
    962966                bool transpose = true;
    963                 sparsity_user2internal(s_transpose, p, m, n, transpose);
     967                const char* error_msg = "SparseJacobian: transposed sparsity"
     968                " pattern does not have proper row or column dimension";
     969                sparsity_user2internal(s_transpose, p, n, m, transpose, error_msg);
    964970
    965971                k = 0;
     
    989995                Pattern_type s;
    990996                bool transpose = false;
    991                 sparsity_user2internal(s, p, m, n, transpose);
     997                const char* error_msg = "SparseJacobian: sparsity"
     998                " pattern does not have proper row or column dimension";
     999                sparsity_user2internal(s, p, m, n, transpose, error_msg);
    9921000
    9931001                k = 0;
  • trunk/cppad/local/sparse_list.hpp

    r3791 r3792  
    835835
    836836\tparam VectorSet
    837 is a simple vector with elements of type \c std::list<set>.
     837is a simple vector with elements of type std::set<size_t>.
    838838
    839839\param internal
     
    843843
    844844\param user
    845 sparsity pattern that we are placing \c internal.
    846 
    847 \param n_row
    848 number of rows in the sparsity pattern in \c user
    849 (range dimension).
    850 
    851 \param n_col
    852 number of columns in the sparsity pattern in \c user
    853 (domain dimension).
     845sparsity pattern that we are placing internal.
     846
     847\param n_set
     848number of sets (rows) in the internal sparsity pattern.
     849
     850\param end
     851end of set value (number of columns) in the interanl sparsity pattern.
    854852
    855853\param transpose
    856 if true, the sparsity pattern in \c internal is the transpose
    857 of the one in \c user.
    858 Otherwise it is the same sparsity pattern.
     854if true, the user sparsity patter is the transposed.
     855
     856\param error_msg
     857is the error message to display if some values in the user sparstiy
     858pattern are not valid.
    859859*/
    860860template<class VectorSet>
     
    862862        sparse_list&            internal  ,
    863863        const VectorSet&        user      ,
    864         size_t                  n_row     ,
    865         size_t                  n_col     ,
    866         bool                    transpose )
     864        size_t                  n_set     ,
     865        size_t                  end       ,
     866        bool                    transpose ,
     867        const char*             error_msg )
    867868{
    868         CPPAD_ASSERT_KNOWN(
    869                 size_t( user.size() ) == n_row,
    870                 "Size of this vector of sets sparsity pattern is not equal\n"
    871                 "the range dimension for the corresponding function."
    872         );
    873 
    874         size_t i, j;
     869# ifndef NDEBUG
     870        if( transpose )
     871                CPPAD_ASSERT_KNOWN( size_t(end) == user.size(), error_msg);
     872        if( ! transpose )
     873                CPPAD_ASSERT_KNOWN( size_t(n_set) == user.size(), error_msg);
     874# endif
     875
     876        // iterator for user set
    875877        std::set<size_t>::const_iterator itr;
    876878
    877         // transposed pattern case
     879        // size of internal sparsity pattern
     880        internal.resize(n_set, end);
     881
    878882        if( transpose )
    879         {       internal.resize(n_col, n_row);
    880                 for(i = 0; i < n_row; i++)
     883        {       // transposed pattern case
     884                for(size_t j = 0; j < end; j++)
     885                {       itr = user[j].begin();
     886                        while(itr != user[j].end())
     887                        {       size_t i = *itr++;
     888                                CPPAD_ASSERT_KNOWN(i < n_set, error_msg);
     889                                internal.add_element(i, j);
     890                        }
     891                }
     892        }
     893        else
     894        {       for(size_t i = 0; i < n_set; i++)
    881895                {       itr = user[i].begin();
    882896                        while(itr != user[i].end())
    883                         {       j = *itr++;
    884                                 CPPAD_ASSERT_KNOWN(
    885                                         j < n_col,
    886                                         "An element in this vector of sets sparsity pattern "
    887                                         "is greater than or equal\n"
    888                                         "the domain dimension for the corresponding function."
    889                                 );
    890                                 internal.add_element(j, i);
    891                         }
    892                 }
    893                 return;
    894         }
    895 
    896         // same pattern case
    897         internal.resize(n_row, n_col);
    898         for(i = 0; i < n_row; i++)
    899         {       itr = user[i].begin();
    900                 while(itr != user[i].end())
    901                 {       j = *itr++;
    902                         CPPAD_ASSERT_UNKNOWN( j < n_col );
    903                         internal.add_element(i, j);
     897                        {       size_t j = *itr++;
     898                                CPPAD_ASSERT_KNOWN( j < end, error_msg);
     899                                internal.add_element(i, j);
     900                        }
    904901                }
    905902        }
     
    907904}
    908905
    909 
    910906} // END_CPPAD_NAMESPACE
    911907# endif
  • trunk/cppad/local/sparse_pack.hpp

    r3757 r3792  
    44
    55/* --------------------------------------------------------------------------
    6 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-15 Bradley M. Bell
     6CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell
    77
    88CppAD is distributed under multiple licenses. This distribution is under
     
    348348
    349349/*!
    350 Copy a user vector of bools sparsity pattern to an internal sparse_pack object.
    351 
    352 \tparam VectorBool
    353 is a simple vector with elements of type bool.
     350Copy a user vector of sets sparsity pattern to an internal sparse_pack object.
     351
     352\tparam VectorSet
     353is a simple vector with elements of type std::set<size_t>.
    354354
    355355\param internal
     
    359359
    360360\param user
    361 sparsity pattern that we are placing \c internal.
    362 
    363 \param n_row
    364 number of rows in the sparsity pattern in \c user
    365 (rand dimension).
    366 
    367 \param n_col
    368 number of columns in the sparsity pattern in \c user
    369 (domain dimension).
     361sparsity pattern that we are placing internal.
     362
     363\param n_set
     364number of sets (rows) in the internal sparsity pattern.
     365
     366\param end
     367end of set value (number of columns) in the interanl sparsity pattern.
    370368
    371369\param transpose
    372 if true, the sparsity pattern in \c internal is the transpose
    373 of the one in \c user.
    374 Otherwise it is the same sparsity pattern.
     370if true, the user sparsity patter is the transposed.
     371
     372\param error_msg
     373is the error message to display if some values in the user sparstiy
     374pattern are not valid.
    375375*/
    376 template<class VectorBool>
     376template<class VectorSet>
    377377void sparsity_user2internal(
    378         sparse_pack&       internal  ,
    379         const VectorBool&  user      ,
    380         size_t             n_row     ,
    381         size_t             n_col     ,
    382         bool               transpose )
    383 {
    384         size_t i, j;
    385 
    386         CPPAD_ASSERT_KNOWN(
    387                 size_t( user.size() ) == n_row * n_col,
    388                 "Size of this vector of bools sparsity pattern is not equal\n"
    389                 "product of domain and range dimensions for corresponding function."
    390         );
    391 
    392         // transposed pattern case
     378        sparse_pack&            internal  ,
     379        const VectorSet&        user      ,
     380        size_t                  n_set     ,
     381        size_t                  end       ,
     382        bool                    transpose ,
     383        const char*             error_msg )
     384{       CPPAD_ASSERT_KNOWN(size_t( user.size() ) == n_set * end, error_msg );
     385
     386        // size of internal sparsity pattern
     387        internal.resize(n_set, end);
     388
    393389        if( transpose )
    394         {       internal.resize(n_col, n_row);
    395                 for(j = 0; j < n_col; j++)
    396                 {       for(i = 0; i < n_row; i++)
    397                         {       if( user[ i * n_col + j ] )
    398                                         internal.add_element(j, i);
     390        {       // transposed pattern case
     391                for(size_t j = 0; j < end; j++)
     392                {       for(size_t i = 0; i < n_set; i++)
     393                        {       if( user[ j * n_set + i ] )
     394                                        internal.add_element(i, j);
    399395                        }
    400396                }
    401397                return;
    402398        }
    403 
    404         // same pattern case
    405         internal.resize(n_row, n_col);
    406         for(i = 0; i < n_row; i++)
    407         {       for(j = 0; j < n_col; j++)
    408                 {       if( user[ i * n_col + j ] )
     399        else
     400        {       for(size_t i = 0; i < n_set; i++)
     401                {       for(size_t j = 0; j < end; j++)
     402                        {       if( user[ i * end + j ] )
    409403                                internal.add_element(i, j);
     404                        }
    410405                }
    411406        }
  • trunk/cppad/local/sparse_pattern.hpp

    r3757 r3792  
    44
    55/* --------------------------------------------------------------------------
    6 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-15 Bradley M. Bell
     6CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell
    77
    88CppAD is distributed under multiple licenses. This distribution is under
     
    1717# include <cppad/local/define.hpp>
    1818# include <cppad/local/sparse_pack.hpp>
    19 # include <cppad/local/sparse_set.hpp>
    2019# include <cppad/local/sparse_list.hpp>
    2120
     
    5251struct internal_sparsity< std::set<size_t> >
    5352{
    54         typedef CPPAD_INTERNAL_SPARSE_SET pattern_type;
     53        typedef sparse_list pattern_type;
    5554};
    5655
  • trunk/cppad/local/undef.hpp

    r3768 r3792  
    44
    55/* --------------------------------------------------------------------------
    6 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-15 Bradley M. Bell
     6CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell
    77
    88CppAD is distributed under multiple licenses. This distribution is under
     
    2828# undef CPPAD_DISCRETE_FUNCTION   in user api
    2929# undef CPPAD_EIGENVECTOR         in user api
    30 # undef CPPAD_INTERNAL_SPARSE_SET in user api
    3130# undef CPPAD_MAX_NUM_THREADS     in user api
    3231# undef CPPAD_NUMERIC_LIMITS      in user api
  • trunk/doc.omh

    r3791 r3792  
    9292$comment bin/version assumes that : follows cppad version number here$$
    9393$section
    94 cppad-20160223: A Package for Differentiation of C++ Algorithms
     94cppad-20160226: A Package for Differentiation of C++ Algorithms
    9595$$
    9696$mindex AD algorithmic differentiation automatic C++ algorithm derivative CppAD version cppad.hpp$$
  • trunk/makefile.am

    r3783 r3792  
    241241        cppad/local/sparse_pack.hpp \
    242242        cppad/local/sparse_pattern.hpp \
    243         cppad/local/sparse_set.hpp \
    244243        cppad/local/sparse_unary_op.hpp \
    245244        cppad/local/sqrt_op.hpp \
  • trunk/makefile.in

    r3769 r3792  
    631631        cppad/local/sparse_pack.hpp \
    632632        cppad/local/sparse_pattern.hpp \
    633         cppad/local/sparse_set.hpp \
    634633        cppad/local/sparse_unary_op.hpp \
    635634        cppad/local/sqrt_op.hpp \
  • trunk/omh/install/cmake.omh

    r3760 r3792  
    11$Id$
    22/* --------------------------------------------------------------------------
    3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-15 Bradley M. Bell
     3CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell
    44
    55CppAD is distributed under multiple licenses. This distribution is under
     
    111111    -D cppad_testvector=%cppad_testvector%                                   \
    112112    -D cppad_max_num_threads=%cppad_max_num_threads%                         \
    113     -D cppad_sparse_list=%cppad_sparse_list%                                 \
    114113    -D cppad_tape_id_type=%cppad_tape_id_type%                               \
    115114    -D cppad_tape_addr_type=%cppad_tape_addr_type%                           \
     
    286285$cref/CPPAD_MAX_NUM_THREADS/multi_thread/CPPAD_MAX_NUM_THREADS/$$.
    287286
    288 $head cppad_sparse_list$$
    289 There are two possible values for this option, $code YES$$ and $code NO$$.
    290 This affect the internal data structure used to store a
    291 $cref/sparsity pattern/glossary/Sparsity Pattern/$$ when the
    292 users version of the sparsity pattern is a vector of $code std::set<size_t>$$.
    293 If $icode cppad_sparse_list$$ is $code NO$$
    294 the vectors of standard sets are also used internally.
    295 If $icode cppad_sparse_list$$ is $code YES$$,
    296 a special sparse list structure is used instead.
    297 This should affect the speed and memory required by the
    298 $cref sparse_jacobian$$, $cref sparse_hessian$$, and
    299 $cref/sparse drivers/sparse/$$
    300 The default value for $icode cppad_sparse_list$$ is $code YES$$
    301 
    302287$head cppad_tape_id_type$$
    303288The type $icode cppad_tape_id_type$$
  • trunk/omh/install/download.omh

    r3791 r3792  
    9797$rnext
    9898current  $cnext EPL $cnext $href%
    99 http://www.coin-or.org/download/source/CppAD/cppad-20160223.epl.tgz%
    100 cppad-20160223.epl.tgz%$$
     99http://www.coin-or.org/download/source/CppAD/cppad-20160226.epl.tgz%
     100cppad-20160226.epl.tgz%$$
    101101$rnext
    102102current  $cnext GPL $cnext $href%
    103 http://www.coin-or.org/download/source/CppAD/cppad-20160223.gpl.tgz%
    104 cppad-20160223.gpl.tgz%$$
     103http://www.coin-or.org/download/source/CppAD/cppad-20160226.gpl.tgz%
     104cppad-20160226.gpl.tgz%$$
    105105$tend
    106106
  • trunk/omh/whats_new/whats_new_11.omh

    r3778 r3792  
    11$Id$
    22/* --------------------------------------------------------------------------
    3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-15 Bradley M. Bell
     3CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell
    44
    55CppAD is distributed under multiple licenses. This distribution is under
     
    921921A faster set operations item was added to the wish list.
    922922This has since been satisfied by
    923 $cref/cppad_sparse_list/cmake/cppad_sparse_list/$$ choice during
    924 the install process.
     923$code cppad_sparse_list$$ choice during
     924the install process (since removed).
    925925
    926926$head 02-02$$
  • trunk/omh/whats_new/whats_new_12.omh

    r3778 r3792  
    11$Id$
    22/* --------------------------------------------------------------------------
    3 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-15 Bradley M. Bell
     3CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-16 Bradley M. Bell
    44
    55CppAD is distributed under multiple licenses. This distribution is under
     
    229229$lnext
    230230Remove faster sparse set operations item that was completed using
    231 $cref/cppad_sparse_list/cmake/cppad_sparse_list/$$.
     231$code cppad_sparse_list$$ (not part of user API).
    232232$lnext
    233233Remove $cref cmake$$ items that have been completed.
  • trunk/omh/whats_new/whats_new_16.omh

    r3791 r3792  
    2323        namespace
    2424        cppad
     25        Hes
     26        Jac
    2527$$
    2628
     
    3335assist you in learning about changes between various versions of CppAD.
    3436
     37$head 02-26$$
     38The condition that the operation sequence in $icode f$$ is
     39$cref/independent/glossary/Operation/Independent/$$ of
     40the independent variables was added to the statement about
     41the validity of the sparsity patterns; see $icode x$$ in
     42$cref/ForSparseJac/ForSparseJac/x/$$,
     43$cref/RevSparseJac/RevSparseJac/x/$$, and
     44$cref/RevSparseHes/RevSparseHes/x/$$.
     45
     46$head 02-25$$
     47The $cref cmake$$ command line argument $code cppad_sparse_list$$
     48has been removed (because it is so much better than the other option).
     49
    3550$head 02-23$$
    3651A new version of the
    37 $cref/cppad_sparse_list/cmake/cppad_sparse_list/$$ class uses
    38 reference counters reduce the number of copies of sets that are equal.
     52$code cppad_sparse_list$$ class (not part of user API) uses
     53reference counters to reduce the number of copies of sets that are equal.
    3954This improved the speed of sparsity pattern computations that use
    4055the $cref/vector of sets/glossary/Sparsity Pattern/Vector of Sets/$$
     
    4762        sparse_hessian_rate_new = [ 1328, 241.61, 92.99, 40.51, 3.80 ]
    4863$$
    49 Note that the improvement is better for larger problems. In fact,
    50 for large problems, the new vector of sets representation preforms better than
     64Note that the improvement is only for large problems. In fact,
     65for large problems, preliminary testing indicates that
     66the new vector of sets representation preforms better than
    5167the $cref/vector of boolean/glossary/Sparsity Pattern/Vector of Boolean/$$
    5268representation.
  • trunk/test_more/local/vector_set.cpp

    r3791 r3792  
    132132{       bool ok = true;
    133133        ok     &= test_no_other<CppAD::sparse_pack>();
    134         ok     &= test_no_other<CppAD::sparse_set>();
    135134        ok     &= test_no_other<CppAD::sparse_list>();
    136135        //
    137136        ok     &= test_yes_other<CppAD::sparse_pack>();
    138         ok     &= test_yes_other<CppAD::sparse_set>();
    139137        ok     &= test_yes_other<CppAD::sparse_list>();
    140138        //
Note: See TracChangeset for help on using the changeset viewer.