File: from_base.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 (50 lines) | stat: -rw-r--r-- 1,136 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
// 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 FromBase example now used just for valiadation testing
*/
# include <cppad/cppad.hpp>

bool FromBase(void)
{  bool ok = true;

   using namespace CppAD;

   // construct directly form Base where Base = double
   AD<double> x(1.);
   AD<double> y = 2.;

   // construct from a type that can be converted to Base
   // where Base = AD<double>
   AD< AD<double> > X(1.);
   AD< AD<double> > Y(2);

   // check that resulting objects are parameters
   ok &= Parameter(x);
   ok &= Parameter(y);

   ok &= Parameter(X);
   ok &= Parameter(Y);

   // check values of objects
   ok &= (x == 1.);
   ok &= (X == x);

   ok &= (y == 2.);
   ok &= (Y == y);

   // user constructor through the static_cast template function
   x   = static_cast < AD<double> >( 4 );
   X   = static_cast < AD< AD<double> > >( 4 );

   ok &= (x == 4.);
   ok &= (X == x);

   return ok;
}

// END PROGRAM