Changeset 936 for trunk/test_more


Ignore:
Timestamp:
May 5, 2007 11:10:09 AM (13 years ago)
Author:
bradbell
Message:

trunk: Add openmp/sum_i_inv test.

svn_commit.sh: file that made this commit.
whats_new_07.omh: user's view of the changes.
sqrt.cpp: test higher order derivatives (make sure correct).
exp_eps.omh: improve description of return values in forward mode.
exp_2.omh: improve description of return values in forward mode.
sqrt_reverse.omh: change summation index and fix a sign error.
reverse_identity.omh: fix dimension for X.
run.sh: fix OMhelp spelling error.
check_include_omh.sh: special code for shell scripts.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test_more/sqrt.cpp

    r683 r936  
    11/* --------------------------------------------------------------------------
    2 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-06 Bradley M. Bell
     2CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-07 Bradley M. Bell
    33
    44CppAD is distributed under multiple licenses. This distribution is under
     
    138138        return ok;
    139139}
     140bool SqrtTestThree(void)
     141{       bool ok = true;
     142
     143        using CppAD::sqrt;
     144        using CppAD::exp;
     145        using namespace CppAD;
     146
     147        // independent variable vector, indices, values, and declaration
     148        double x = 4.;
     149        CppADvector< AD<double> > X(1);
     150        X[0]     = x;
     151        Independent(X);
     152
     153        // dependent variable vector, indices, and values
     154        CppADvector< AD<double> > Y(1);
     155        Y[0]     = sqrt( exp(X[0]) );
     156
     157        // define f : X -> Y and vectors for derivative calculations
     158        ADFun<double> f(X, Y);
     159
     160        // forward computation of first Taylor coefficient
     161        CppADvector<double> x1( f.Domain() );
     162        CppADvector<double> y1( f.Range() );
     163        x1[0] = 1.;
     164        y1    = f.Forward(1, x1);
     165        ok   &= NearEqual(y1[0], exp(x/2.)/2.,   1e-10 , 1e-10);
     166
     167        // forward computation of second Taylor coefficient
     168        CppADvector<double> x2( f.Domain() );
     169        CppADvector<double> y2( f.Range() );
     170        x2[0] = 0.;
     171        y2    = f.Forward(2, x2);
     172        ok   &= NearEqual(2.*y2[0] , exp(x/2.)/4., 1e-10 , 1e-10 );
     173
     174        // forward computation of third Taylor coefficient
     175        CppADvector<double> x3( f.Domain() );
     176        CppADvector<double> y3( f.Range() );
     177        x3[0] = 0.;
     178        y3    = f.Forward(3, x3);
     179        ok   &= NearEqual(6.*y3[0] , exp(x/2.)/8., 1e-10 , 1e-10 );
     180
     181        // reverse computation of deritavitve of Taylor coefficients
     182        CppADvector<double> r( f.Domain() * 4 );
     183        CppADvector<double> w(1);
     184        w[0] = 1.;
     185        r    = f.Reverse(4, w);
     186        ok   &= NearEqual(r[0], exp(x/2.)/2., 1e-10 , 1e-10);
     187        ok   &= NearEqual(r[1], exp(x/2.)/4., 1e-10 , 1e-10 );
     188        ok   &= NearEqual(2.*r[2], exp(x/2.)/8., 1e-10 , 1e-10 );
     189        ok   &= NearEqual(6.*r[3], exp(x/2.)/16., 1e-10 , 1e-10 );
     190
     191        return ok;
     192
     193}
    140194
    141195} // END empty namespace
     
    145199        ok &= SqrtTestOne();
    146200        ok &= SqrtTestTwo();
    147         return ok;
    148 }
     201        ok &= SqrtTestThree();
     202        return ok;
     203}
Note: See TracChangeset for help on using the changeset viewer.