Changeset 3365
 Timestamp:
 Sep 27, 2014 5:35:28 AM (6 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/bug/opt_atomic.sh
r3364 r3365 16 16 cat << EOF > bug.$$ 17 17 # include <cppad/cppad.hpp> 18 # include <example/atomic/reciprocal.cpp> // Get an atomic test function 19 using namespace CppAD; 18 19 using CppAD::vector; 20 using CppAD::AD; 21 using CppAD::ADFun; 22 23 class atomic_reciprocal : public CppAD::atomic_base<double> { 24 public: 25 atomic_reciprocal(const std::string& name) : 26 CppAD::atomic_base<double>(name) 27 { } 28 private: 29 virtual bool forward( 30 size_t p , 31 size_t q , 32 const vector<bool>& vx , 33 vector<bool>& vy , 34 const vector<double>& tx , 35 vector<double>& ty 36 ) 37 { size_t n = tx.size() / (q + 1); 38 size_t m = ty.size() / (q + 1); 39 assert( n == 1 ); 40 assert( m == 1 ); 41 assert( p <= q ); 42 43 // return flag 44 bool ok = true; 45 46 // check for defining variable information 47 // This case must always be implemented 48 if( vx.size() > 0 ) 49 vy[0] = vx[0]; 50 51 // Order zero forward mode. 52 // This case must always be implemented 53 // y^0 = f( x^0 ) = 1 / x^0 54 double f = 1. / tx[0]; 55 if( p <= 0 ) 56 ty[0] = f; 57 if( q <= 0 ) 58 return ok; 59 // 60 assert( vx.size() == 0 ); 61 ok = false; 62 return ok; 63 } 64 virtual bool rev_sparse_jac( 65 size_t p , 66 const vector<bool>& rt , 67 vector<bool>& st ) 68 { // This function needed if using RevSparseJac or optimize 69 // with afun.option( CppAD::atomic_base<double>::bool_sparsity_enum ) 70 size_t n = st.size() / p; 71 size_t m = rt.size() / p; 72 assert( n == 1 ); 73 assert( m == 1 ); 74 75 // sparsity for S(x)^T = f'(x)^T * R^T is same as sparsity for R^T 76 for(size_t i = 0; i < p; i++) 77 st[i] = rt[i]; 78 79 return true; 80 } 81 // reverse Jacobian set sparsity routine called by CppAD 82 virtual bool rev_sparse_jac( 83 size_t p , 84 const vector< std::set<size_t> >& rt , 85 vector< std::set<size_t> >& st ) 86 { // This function needed if using RevSparseJac or optimize 87 // with afun.option( CppAD::atomic_base<double>::set_sparsity_enum ) 88 size_t n = st.size(); 89 size_t m = rt.size(); 90 assert( n == 1 ); 91 assert( m == 1 ); 92 93 // sparsity for S(x)^T = f'(x)^T * R^T is same as sparsity for R^T 94 st[0] = rt[0]; 95 96 return true; 97 } 98 }; 99 20 100 21 101 int main(){
Note: See TracChangeset
for help on using the changeset viewer.