CppAD: A C++ Algorithmic Differentiation Package  20130918
for_sparse_jac.hpp
Go to the documentation of this file.
00001 /* $Id$ */
00002 # ifndef CPPAD_FOR_SPARSE_JAC_INCLUDED
00003 # define CPPAD_FOR_SPARSE_JAC_INCLUDED
00004 
00005 /* --------------------------------------------------------------------------
00006 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-14 Bradley M. Bell
00007 
00008 CppAD is distributed under multiple licenses. This distribution is under
00009 the terms of the 
00010                     Eclipse Public License Version 1.0.
00011 
00012 A copy of this license is included in the COPYING file of this distribution.
00013 Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
00014 -------------------------------------------------------------------------- */
00015 
00016 /*
00017 $begin ForSparseJac$$
00018 $spell
00019      std
00020      var
00021      Jacobian
00022      Jac
00023      const
00024      Bool
00025      proportional
00026      VecAD
00027 $$
00028 
00029 $section Jacobian Sparsity Pattern: Forward Mode$$ 
00030 
00031 $index ForSparseJac$$
00032 $index forward, sparsity Jacobian$$
00033 $index sparsity, forward Jacobian$$
00034 $index pattern, forward Jacobian$$
00035 
00036 $head Syntax$$
00037 $icode%s% = %f%.ForSparseJac(%q%, %r%)
00038 %$$
00039 $icode%s% = %f%.ForSparseJac(%q%, %r%, %transpose%)%$$
00040 
00041 $head Purpose$$
00042 We use $latex F : B^n \rightarrow B^m$$ to denote the
00043 $cref/AD function/glossary/AD Function/$$ corresponding to $icode f$$.
00044 For a fixed $latex n \times q$$ matrix $latex R$$,
00045 the Jacobian of $latex F[ x + R * u ]$$
00046 with respect to $latex u$$ at $latex u = 0$$ is
00047 $latex \[
00048      S(x) = F^{(1)} ( x ) * R
00049 \] $$
00050 Given a
00051 $cref/sparsity pattern/glossary/Sparsity Pattern/$$ 
00052 for $latex R$$,
00053 $code ForSparseJac$$ returns a sparsity pattern for the $latex S(x)$$.
00054 
00055 $head f$$
00056 The object $icode f$$ has prototype
00057 $codei%
00058      ADFun<%Base%> %f%
00059 %$$
00060 Note that the $cref ADFun$$ object $icode f$$ is not $code const$$.
00061 After a call to $code ForSparseJac$$, the sparsity pattern
00062 for each of the variables in the operation sequence
00063 is held in $icode f$$ (for possible later use by $cref RevSparseHes$$).
00064 These sparsity patterns are stored with elements of type $code bool$$
00065 or elements of type $code std::set<size_t>$$
00066 (see $cref/VectorSet/ForSparseJac/VectorSet/$$ below).
00067  
00068 $subhead size_forward_bool$$
00069 After $code ForSparseJac$$, if $icode k$$ is a $code size_t$$ object, 
00070 $codei%
00071      %k% = %f%.size_forward_bool()
00072 %$$
00073 sets $icode k$$ to the amount of memory (in unsigned character units)
00074 used to store the sparsity pattern with elements of type $code bool$$
00075 in the function object $icode f$$.
00076 If the sparsity patterns for the previous $code ForSparseJac$$ used
00077 elements of type $code bool$$,
00078 the return value for $code size_forward_bool$$ will be non-zero.
00079 Otherwise, its return value will be zero.
00080 This sparsity pattern is stored for use by $cref RevSparseHes$$ and
00081 when it is not longer needed, it can be deleted 
00082 (and the corresponding memory freed) using 
00083 $codei%
00084      %f%.size_forward_bool(0)
00085 %$$
00086 After this call, $icode%f%.size_forward_bool()%$$ will return zero.
00087  
00088 $subhead size_forward_set$$
00089 After $code ForSparseJac$$, if $icode k$$ is a $code size_t$$ object, 
00090 $codei%
00091      %k% = %f%.size_forward_set()
00092 %$$
00093 sets $icode s$$ to the total number of elements in all the sets corresponding
00094 to the sparsity pattern stored in the function object $icode f$$.
00095 If the sparsity patterns for this operation use elements of type $code bool$$,
00096 the return value for $code size_forward_set$$ will be zero.
00097 Otherwise, its return value will be non-zero
00098 (unless the entire sparsity pattern is false).
00099 This sparsity pattern is stored for use by $cref RevSparseHes$$ and
00100 when it is not longer needed, it can be deleted 
00101 (and the corresponding memory freed) using
00102 $codei%
00103      %f%.size_forward_set(0)
00104 %$$
00105 After this call, $icode%f%.size_forward_set()%$$ will return zero.
00106 
00107 $head x$$
00108 the sparsity pattern is valid for all values of the independent 
00109 variables in $latex x \in B^n$$
00110 (even if it has $cref CondExp$$ or $cref VecAD$$ operations).
00111 
00112 $head q$$
00113 The argument $icode q$$ has prototype
00114 $codei%
00115      size_t %q%
00116 %$$
00117 It specifies the number of columns in 
00118 $latex R \in B^{n \times q}$$ and the Jacobian 
00119 $latex S(x) \in B^{m \times q}$$. 
00120 
00121 $head transpose$$
00122 The argument $icode transpose$$ has prototype
00123 $codei%
00124      bool %transpose%
00125 %$$
00126 The default value $code false$$ is used when $icode transpose$$ is not present.
00127 
00128 
00129 $head r$$
00130 The argument $icode r$$ has prototype
00131 $codei%
00132      const %VectorSet%& %r%
00133 %$$
00134 see $cref/VectorSet/ForSparseJac/VectorSet/$$ below.
00135 
00136 $subhead transpose false$$
00137 If $icode r$$ has elements of type $code bool$$,
00138 its size is $latex n * q$$.
00139 If it has elements of type $code std::set<size_t>$$,
00140 its size is $latex n$$ and all the set elements must be between
00141 zero and $icode%q%-1%$$ inclusive.
00142 It specifies a 
00143 $cref/sparsity pattern/glossary/Sparsity Pattern/$$ 
00144 for the matrix $icode R \in B^{n \times q}$$.
00145 
00146 $subhead transpose true$$
00147 If $icode r$$ has elements of type $code bool$$,
00148 its size is $latex q * n$$.
00149 If it has elements of type $code std::set<size_t>$$,
00150 its size is $latex q$$ and all the set elements must be between
00151 zero and $icode%n%-1%$$ inclusive.
00152 It specifies a 
00153 $cref/sparsity pattern/glossary/Sparsity Pattern/$$ 
00154 for the matrix $icode R^\R{T} \in B^{q \times n}$$.
00155 
00156 $head s$$
00157 The return value $icode s$$ has prototype
00158 $codei%
00159      %VectorSet% %s%
00160 %$$
00161 see $cref/VectorSet/ForSparseJac/VectorSet/$$ below.
00162 
00163 $subhead transpose false$$
00164 If $icode s$$ has elements of type $code bool$$,
00165 its size is $latex m * q$$.
00166 If it has elements of type $code std::set<size_t>$$,
00167 its size is $latex m$$ and all its set elements are between
00168 zero and $icode%q%-1%$$ inclusive.
00169 It specifies a 
00170 $cref/sparsity pattern/glossary/Sparsity Pattern/$$ 
00171 for the matrix $latex S(x) \in B^{m \times q}$$.
00172 
00173 $subhead transpose true$$
00174 If $icode s$$ has elements of type $code bool$$,
00175 its size is $latex q * m$$.
00176 If it has elements of type $code std::set<size_t>$$,
00177 its size is $latex q$$ and all its set elements are between
00178 zero and $icode%m%-1%$$ inclusive.
00179 It specifies a 
00180 $cref/sparsity pattern/glossary/Sparsity Pattern/$$ 
00181 for the matrix $latex S(x)^\R{T} \in B^{q \times m}$$.
00182 
00183 $head VectorSet$$
00184 The type $icode VectorSet$$ must be a $cref SimpleVector$$ class with
00185 $cref/elements of type/SimpleVector/Elements of Specified Type/$$
00186 $code bool$$ or $code std::set<size_t>$$;
00187 see $cref/sparsity pattern/glossary/Sparsity Pattern/$$ for a discussion
00188 of the difference.
00189 
00190 $head Entire Sparsity Pattern$$
00191 Suppose that $latex q = n$$ and
00192 $latex R$$ is the $latex n \times n$$ identity matrix.
00193 In this case, 
00194 the corresponding value for $icode s$$ is a 
00195 sparsity pattern for the Jacobian $latex S(x) = F^{(1)} ( x )$$.
00196 
00197 $head Example$$
00198 $children%
00199      example/for_sparse_jac.cpp
00200 %$$
00201 The file
00202 $cref for_sparse_jac.cpp$$
00203 contains an example and test of this operation.
00204 It returns true if it succeeds and false otherwise.
00205 
00206 $end
00207 -----------------------------------------------------------------------------
00208 */
00209 
00210 # include <cppad/local/std_set.hpp>
00211 
00212 namespace CppAD { // BEGIN_CPPAD_NAMESPACE
00213 /*!
00214 \file for_sparse_jac.hpp
00215 Forward mode Jacobian sparsity patterns.
00216 */
00217 
00218 // ---------------------------------------------------------------------------
00219 /*!
00220 Calculate Jacobian vector of bools sparsity patterns using forward mode.
00221 
00222 The C++ source code corresponding to this operation is
00223 \verbatim
00224      s = f.ForSparseJac(q, r)
00225 \endverbatim
00226 
00227 \tparam Base
00228 is the base type for this recording.
00229 
00230 \tparam VectorSet
00231 is a simple vector class with elements of type \c bool.
00232 
00233 \param transpose
00234 are the sparsity patterns transposed.
00235 
00236 \param q
00237 is the number of columns in the matrix \f$ R \f$.
00238 
00239 \param r
00240 is a sparsity pattern for the matrix \f$ R \f$.
00241 
00242 \param s
00243 The input value of \a s must be a vector with size \c m*q
00244 where \c m is the number of dependent variables
00245 corresponding to the operation sequence stored in \a play. 
00246 The input value of the components of \c s does not matter.
00247 On output, \a s is the sparsity pattern for the matrix
00248 \f[
00249      S(x) = F^{(1)} (x) * R
00250 \f]
00251 where \f$ F \f$ is the function corresponding to the operation sequence
00252 and \a x is any argument value.
00253 
00254 \param total_num_var
00255 is the total number of variable in this recording.
00256 
00257 \param dep_taddr
00258 maps dependendent variable index
00259 to the corresponding variable in the tape.
00260 
00261 \param ind_taddr
00262 maps independent variable index
00263 to the corresponding variable in the tape.
00264 
00265 \param play
00266 is the recording that defines the function we are computing the sparsity 
00267 pattern for.
00268 
00269 \param for_jac_sparsity
00270 the input value of \a for_jac_sparsity does not matter.
00271 On output, \a for_jac_sparsity.n_set() == \a total_num_var
00272 and \a for_jac_sparsity.end() == \a q.
00273 It contains the forward sparsity pattern for all of the variables on the
00274 tape (given the sparsity pattern for the independent variables is \f$ R \f$).
00275 */
00276 template <class Base, class VectorSet> 
00277 void ForSparseJacBool(
00278      bool                   transpose        ,
00279      size_t                 q                , 
00280      const VectorSet&       r                ,
00281      VectorSet&             s                ,
00282      size_t                 total_num_var    ,
00283      CppAD::vector<size_t>& dep_taddr        ,
00284      CppAD::vector<size_t>& ind_taddr        ,
00285      CppAD::player<Base>&   play             ,
00286      sparse_pack&           for_jac_sparsity )
00287 {
00288      // temporary indices
00289      size_t i, j;
00290 
00291      // range and domain dimensions for F
00292      size_t m = dep_taddr.size();
00293      size_t n = ind_taddr.size();
00294 
00295      CPPAD_ASSERT_KNOWN(
00296           q > 0,
00297           "ForSparseJac: q is not greater than zero"
00298      );
00299      CPPAD_ASSERT_KNOWN( 
00300           size_t(r.size()) == n * q,
00301           "ForSparseJac: size of r is not equal to\n"
00302           "q times domain dimension for ADFun object."
00303      );
00304 
00305      // allocate memory for the requested sparsity calculation result
00306      for_jac_sparsity.resize(total_num_var, q);
00307 
00308      // set values corresponding to independent variables
00309      for(i = 0; i < n; i++)
00310      {    CPPAD_ASSERT_UNKNOWN( ind_taddr[i] < total_num_var );
00311           // ind_taddr[i] is operator taddr for i-th independent variable
00312           CPPAD_ASSERT_UNKNOWN( play.GetOp( ind_taddr[i] ) == InvOp );
00313 
00314           // set bits that are true
00315           if( transpose )
00316           {    for(j = 0; j < q; j++) if( r[ j * n + i ] )
00317                     for_jac_sparsity.add_element( ind_taddr[i], j);
00318           }
00319           else
00320           {    for(j = 0; j < q; j++) if( r[ i * q + j ] )
00321                     for_jac_sparsity.add_element( ind_taddr[i], j);
00322           }
00323      }
00324 
00325      // evaluate the sparsity patterns
00326      ForJacSweep(
00327           n,
00328           total_num_var,
00329           &play,
00330           for_jac_sparsity
00331      );
00332 
00333      // return values corresponding to dependent variables
00334      CPPAD_ASSERT_UNKNOWN( size_t(s.size()) == m * q );
00335      for(i = 0; i < m; i++)
00336      {    CPPAD_ASSERT_UNKNOWN( dep_taddr[i] < total_num_var );
00337 
00338           // extract the result from for_jac_sparsity
00339           if( transpose )
00340           {    for(j = 0; j < q; j++)
00341                     s[ j * m + i ] = false;
00342           }
00343           else
00344           {    for(j = 0; j < q; j++)
00345                     s[ i * q + j ] = false;
00346           }
00347           CPPAD_ASSERT_UNKNOWN( for_jac_sparsity.end() == q );
00348           for_jac_sparsity.begin( dep_taddr[i] );
00349           j = for_jac_sparsity.next_element();
00350           while( j < q )
00351           {    if( transpose )
00352                     s[j * m + i] = true;
00353                else s[i * q + j] = true;
00354                j = for_jac_sparsity.next_element();
00355           }
00356      }
00357 }
00358 
00359 /*!
00360 Calculate Jacobian vector of sets sparsity patterns using forward mode.
00361 
00362 The C++ source code corresponding to this operation is
00363 \verbatim
00364      s = f.ForSparseJac(q, r)
00365 \endverbatim
00366 
00367 \tparam Base
00368 see \c SparseJacBool.
00369 
00370 \tparam VectorSet
00371 is a simple vector class with elements of type \c std::set<size_t>.
00372 
00373 \param transpose
00374 see \c SparseJacBool.
00375 
00376 \param q
00377 see \c SparseJacBool.
00378 
00379 \param r
00380 see \c SparseJacBool.
00381 
00382 \param s
00383 see \c SparseJacBool.
00384 
00385 \param total_num_var
00386 see \c SparseJacBool.
00387 
00388 \param dep_taddr
00389 see \c SparseJacBool.
00390 
00391 \param ind_taddr
00392 see \c SparseJacBool.
00393 
00394 \param play
00395 see \c SparseJacBool.
00396 
00397 \param for_jac_sparsity
00398 see \c SparseJacBool.
00399 */
00400 
00401 template <class Base, class VectorSet> 
00402 void ForSparseJacSet(
00403      bool                        transpose        , 
00404      size_t                      q                , 
00405      const VectorSet&            r                ,
00406      VectorSet&                  s                ,
00407      size_t                      total_num_var    ,
00408      CppAD::vector<size_t>&      dep_taddr        ,
00409      CppAD::vector<size_t>&      ind_taddr        ,
00410      CppAD::player<Base>&        play             ,
00411      CPPAD_INTERNAL_SPARSE_SET&  for_jac_sparsity )
00412 {
00413      // temporary indices
00414      size_t i, j;
00415      std::set<size_t>::const_iterator itr;
00416 
00417      // range and domain dimensions for F
00418      size_t m = dep_taddr.size();
00419      size_t n = ind_taddr.size();
00420 
00421      CPPAD_ASSERT_KNOWN(
00422           q > 0,
00423           "RevSparseJac: q is not greater than zero"
00424      );
00425      CPPAD_ASSERT_KNOWN(
00426           size_t(r.size()) == n || transpose,
00427           "RevSparseJac: size of r is not equal to n and transpose is false."
00428      );
00429      CPPAD_ASSERT_KNOWN(
00430           size_t(r.size()) == q || ! transpose,
00431           "RevSparseJac: size of r is not equal to q and transpose is true."
00432      );
00433 
00434      // allocate memory for the requested sparsity calculation
00435      for_jac_sparsity.resize(total_num_var, q);
00436 
00437      // set values corresponding to independent variables
00438      if( transpose )
00439      {    for(i = 0; i < q; i++)
00440           {    // add the elements that are present
00441                itr = r[i].begin();
00442                while( itr != r[i].end() )
00443                {    j = *itr++;
00444                     CPPAD_ASSERT_KNOWN(
00445                     j < n,
00446                     "ForSparseJac: transpose is true and element of the set\n"
00447                     "r[j] has value greater than or equal n."
00448                     );
00449                     CPPAD_ASSERT_UNKNOWN( ind_taddr[j] < total_num_var );
00450                     // operator for j-th independent variable
00451                     CPPAD_ASSERT_UNKNOWN( play.GetOp( ind_taddr[j] ) == InvOp );
00452                     for_jac_sparsity.add_element( ind_taddr[j], i);
00453                }
00454           }
00455      }
00456      else
00457      {    for(i = 0; i < n; i++)
00458           {    CPPAD_ASSERT_UNKNOWN( ind_taddr[i] < total_num_var );
00459                // ind_taddr[i] is operator taddr for i-th independent variable
00460                CPPAD_ASSERT_UNKNOWN( play.GetOp( ind_taddr[i] ) == InvOp );
00461 
00462                // add the elements that are present
00463                itr = r[i].begin();
00464                while( itr != r[i].end() )
00465                {    j = *itr++;
00466                     CPPAD_ASSERT_KNOWN(
00467                          j < q,
00468                          "ForSparseJac: an element of the set r[i] "
00469                          "has value greater than or equal q."
00470                     );
00471                     for_jac_sparsity.add_element( ind_taddr[i], j);
00472                }
00473           }
00474      }
00475      // evaluate the sparsity patterns
00476      ForJacSweep(
00477           n,
00478           total_num_var,
00479           &play,
00480           for_jac_sparsity
00481      );
00482 
00483      // return values corresponding to dependent variables
00484      CPPAD_ASSERT_UNKNOWN( size_t(s.size()) == m || transpose );
00485      CPPAD_ASSERT_UNKNOWN( size_t(s.size()) == q || ! transpose );
00486      for(i = 0; i < m; i++)
00487      {    CPPAD_ASSERT_UNKNOWN( dep_taddr[i] < total_num_var );
00488 
00489           // extract results from for_jac_sparsity
00490           // and add corresponding elements to sets in s
00491           CPPAD_ASSERT_UNKNOWN( for_jac_sparsity.end() == q );
00492           for_jac_sparsity.begin( dep_taddr[i] );
00493           j = for_jac_sparsity.next_element();
00494           while( j < q )
00495           {    if( transpose )
00496                     s[j].insert(i);
00497                else s[i].insert(j);
00498                j = for_jac_sparsity.next_element();
00499           }
00500      }
00501 }
00502 // ---------------------------------------------------------------------------
00503 /*! 
00504 Private helper function for ForSparseJac(q, r).
00505 
00506 All of the description in the public member function ForSparseJac(q, r) 
00507 applies. 
00508 
00509 \param set_type
00510 is a \c bool value. This argument is used to dispatch to the proper source
00511 code depending on the value of \c VectorSet::value_type.
00512 
00513 \param transpose
00514 See \c ForSparseJac(q, r).
00515 
00516 \param q
00517 See \c ForSparseJac(q, r).
00518 
00519 \param r
00520 See \c ForSparseJac(q, r).
00521 
00522 \param s
00523 is the return value for the corresponding call to \c ForSparseJac(q, r).
00524 */
00525 
00526 template <class Base>
00527 template <class VectorSet>
00528 void ADFun<Base>::ForSparseJacCase(
00529      bool                set_type      ,
00530      bool                transpose     ,
00531      size_t              q             ,
00532      const VectorSet&    r             ,
00533      VectorSet&          s             )
00534 {    size_t m = Range();
00535 
00536      // check VectorSet is Simple Vector class with bool elements
00537      CheckSimpleVector<bool, VectorSet>();
00538 
00539      // dimension size of result vector
00540      s.resize( m * q );
00541 
00542      // store results in s and for_jac_sparse_pack_
00543      ForSparseJacBool(
00544           transpose        , 
00545           q                , 
00546           r                ,
00547           s                ,
00548           num_var_tape_    ,
00549           dep_taddr_       ,
00550           ind_taddr_       ,
00551           play_            ,
00552           for_jac_sparse_pack_ 
00553      );
00554 }
00555 
00556 
00557 /*! 
00558 Private helper function for \c ForSparseJac(q, r).
00559 
00560 All of the description in the public member function \c ForSparseJac(q, r) 
00561 applies. 
00562 
00563 \param set_type
00564 is a \c std::set<size_t> object. 
00565 This argument is used to dispatch to the proper source
00566 code depending on the value of \c VectorSet::value_type.
00567 
00568 \param transpose
00569 See \c ForSparseJac(q, r).
00570 
00571 \param q
00572 See \c ForSparseJac(q, r).
00573 
00574 \param r
00575 See \c ForSparseJac(q, r).
00576 
00577 \param s
00578 is the return value for the corresponding call to \c ForSparseJac(q, r).
00579 */
00580 template <class Base>
00581 template <class VectorSet>
00582 void ADFun<Base>::ForSparseJacCase(
00583      const std::set<size_t>&    set_type      ,
00584      bool                       transpose     ,
00585      size_t                     q             ,
00586      const VectorSet&           r             ,
00587      VectorSet&                 s             )
00588 {    size_t m = Range();
00589 
00590      // check VectorSet is Simple Vector class with sets for elements
00591      CheckSimpleVector<std::set<size_t>, VectorSet>(
00592           one_element_std_set<size_t>(), two_element_std_set<size_t>()
00593      );
00594 
00595      // dimension size of result vector
00596      if( transpose )
00597           s.resize(q);
00598      else s.resize( m );
00599 
00600      // store results in r and for_jac_sparse_pack_
00601      CppAD::ForSparseJacSet(
00602           transpose        , 
00603           q                , 
00604           r                ,
00605           s                ,
00606           num_var_tape_    ,
00607           dep_taddr_       ,
00608           ind_taddr_       ,
00609           play_            ,
00610           for_jac_sparse_set_
00611      );
00612 }
00613 // ---------------------------------------------------------------------------
00614 
00615 /*!
00616 User API for Jacobian sparsity patterns using forward mode.
00617 
00618 The C++ source code corresponding to this operation is
00619 \verbatim
00620      s = f.ForSparseJac(q, r)
00621 \endverbatim
00622 
00623 \tparam Base
00624 is the base type for this recording.
00625 
00626 \tparam VectorSet
00627 is a simple vector with elements of type \c bool
00628 or \c std::set<size_t>.
00629 
00630 \param q
00631 is the number of columns in the matrix \f$ R \f$.
00632 
00633 \param r
00634 is a sparsity pattern for the matrix \f$ R \f$.
00635 
00636 \param transpose
00637 are sparsity patterns for \f$ R \f$ and \f$ S(x) \f$ transposed.
00638 
00639 \return
00640 The value of \c transpose is false (true),
00641 the return value is a sparsity pattern for \f$ S(x) \f$ (\f$ S(x)^T \f$) where
00642 \f[
00643      S(x) = F^{(1)} (x) * R
00644 \f]
00645 where \f$ F \f$ is the function corresponding to the operation sequence
00646 and \a x is any argument value.
00647 If \c VectorSet::value_type is \c bool,
00648 the return value has size \f$ m * q \f$ (\f$ q * m \f$). 
00649 where \c m is the number of dependent variables
00650 corresponding to the operation sequence stored in \c f. 
00651 If \c VectorSet::value_type is \c std::set<size_t>,
00652 the return value has size \f$ m \f$ ( \f$ q \f$ )
00653 and with all its elements between zero and 
00654 \f$ q - 1 \f$ ( \f$ m - 1 \f$).
00655 
00656 \par Side Effects
00657 If \c VectorSet::value_type is \c bool,
00658 the forward sparsity pattern for all of the variables on the
00659 tape is stored in \c for_jac_sparse_pack__.
00660 In this case 
00661 \verbatim
00662      for_jac_sparse_pack_.n_set() == num_var_tape_
00663      for_jac_sparse_pack_.end() == q
00664      for_jac_sparse_set_.n_set()  == 0
00665      for_jac_sparse_set_.end()  == 0
00666 \endverbatim
00667 \n
00668 \n
00669 If \c VectorSet::value_type is \c std::set<size_t>,
00670 the forward sparsity pattern for all of the variables on the
00671 tape is stored in \c for_jac_sparse_set__.
00672 In this case 
00673 \verbatim
00674      for_jac_sparse_set_.n_set()   == num_var_tape_
00675      for_jac_sparse_set_.end()   == q
00676      for_jac_sparse_pack_.n_set()  == 0
00677      for_jac_sparse_pack_.end()  == 0
00678 \endverbatim
00679 */
00680 template <class Base>
00681 template <class VectorSet>
00682 VectorSet ADFun<Base>::ForSparseJac(
00683      size_t             q             , 
00684      const VectorSet&   r             ,
00685      bool               transpose     )
00686 {    VectorSet s;
00687      typedef typename VectorSet::value_type Set_type; 
00688 
00689      // free all memory currently in sparsity patterns
00690      for_jac_sparse_pack_.resize(0, 0);
00691      for_jac_sparse_set_.resize(0, 0);
00692 
00693      ForSparseJacCase(
00694           Set_type()  ,
00695           transpose   ,
00696           q           ,
00697           r           ,
00698           s
00699      );
00700 
00701      return s;
00702 }
00703 
00704 
00705 } // END_CPPAD_NAMESPACE
00706 # endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines