File: log10.cpp

package info (click to toggle)
cppad 2026.00.00.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,584 kB
  • sloc: cpp: 112,960; sh: 6,146; ansic: 179; python: 71; sed: 12; makefile: 10
file content (54 lines) | stat: -rw-r--r-- 1,595 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
// SPDX-FileCopyrightText: Bradley M. Bell <bradbell@seanet.com>
// SPDX-FileContributor: 2003-22 Bradley M. Bell
// ----------------------------------------------------------------------------

/*
Old example now used just for validation testing.
*/
# include <cppad/cppad.hpp>

bool log10(void)
{  bool ok = true;
   using CppAD::log10;
   using CppAD::log;
   using namespace CppAD;
   double eps99 = 99.0 * std::numeric_limits<double>::epsilon();

   // independent variable vector, indices, values, and declaration
   CPPAD_TESTVECTOR(AD<double>) U(1);
   size_t s = 0;
   U[s]     = 10.;
   Independent(U);

   // dependent variable vector, indices, and values
   CPPAD_TESTVECTOR(AD<double>) Z(2);
   size_t x = 0;
   size_t y = 1;
   Z[x]     = log10(U[s]);
   Z[y]     = log10(Z[x]);

   // define f : U -> Z and vectors for derivative calculations
   ADFun<double> f(U, Z);
   CPPAD_TESTVECTOR(double) v( f.Domain() );
   CPPAD_TESTVECTOR(double) w( f.Range() );

   // check values
   ok &= NearEqual(Z[x] , 1.,  eps99 , eps99);
   ok &= NearEqual(Z[y] , 0.,  eps99 , eps99);

   // forward computation of partials w.r.t. s
   double l10 = log(10.);
   v[s] = 1.;
   w    = f.Forward(1, v);
   ok &= NearEqual(w[x], 1./(U[s]*l10)         , eps99 , eps99); // dx/ds
   ok &= NearEqual(w[y], 1./(U[s]*Z[x]*l10*l10), eps99 , eps99); // dy/ds

   // reverse computation of partials of y
   w[x] = 0.;
   w[y] = 1.;
   v    = f.Reverse(1,w);
   ok &= NearEqual(v[s], 1./(U[s]*Z[x]*l10*l10), eps99 , eps99); // dy/ds

   return ok;
}