File: base2ad.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 (51 lines) | stat: -rw-r--r-- 1,264 bytes parent folder | download
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
// 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
// ----------------------------------------------------------------------------

// Tests corresponding to some base2ad bug fixes; i.e., regression test

# include <cppad/cppad.hpp>

namespace { // BEGIN_EMPTY_NAMESPACE
   //
   // my_integer
   double my_integer(const double& x)
   {  return std::floor(x); }
   CPPAD_DISCRETE_FUNCTION(double, my_integer);
   //
   // discrete
   bool discrete(void)
   {  bool ok = true;
      using CppAD::AD;
      //
      // af
      CPPAD_TESTVECTOR( AD<double> ) ax(1), ay(1);
      ax[0] = 2.5;
      Independent( ax );
      ay[0] = my_integer( ax[0] );
      CppAD::ADFun<double> f(ax, ay);
      CppAD::ADFun< AD<double>, double> af = f.base2ad();
      //
      // g
      Independent( ax );
      ay = af.Forward(0, ax);
      CppAD::ADFun<double> g(ax, ay);
      //
      // ok
      CPPAD_TESTVECTOR(double) x(1), y(1);
      x[0] = 5.5;
      y    = g.Forward(0, x);
      ok &= y[0] == std::floor( x[0] );
      //
      return ok;
   }
} // END_EMPTY_NAMESPACE

bool base2ad(void)
{  bool ok = true;

   ok &= discrete();

   return ok;
}