File: ad_input.cpp

package info (click to toggle)
cppad 2025.00.00.2-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 11,552 kB
  • sloc: cpp: 112,594; sh: 5,972; ansic: 179; python: 71; sed: 12; makefile: 10
file content (52 lines) | stat: -rw-r--r-- 1,184 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
// 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
// ----------------------------------------------------------------------------

/*
{xrst_begin ad_input.cpp}

AD Output Operator: Example and Test
####################################

{xrst_literal
   // BEGIN C++
   // END C++
}

{xrst_end ad_input.cpp}
*/
// BEGIN C++

# include <cppad/cppad.hpp>

# include <sstream>  // std::istringstream
# include <string>   // std::string

bool ad_input(void)
{  bool ok = true;

   // create the input string stream is.
   std::string str ("123 456");
   std::istringstream is(str);

   // start and AD<double> recording
   CPPAD_TESTVECTOR( CppAD::AD<double> ) x(1), y(1);
   x[0] = 1.0;
   CppAD::Independent(x);
   CppAD::AD<double> z = x[0];
   ok &= Variable(z);

   // read first number into z and second into y[0]
   is >> z >> y[0];
   ok   &= Parameter(z);
   ok   &= (z == 123.);
   ok   &= Parameter(y[0]);
   ok   &= (y[0] == 456.);
   //
   // terminate recording starting by call to Independent
   CppAD::ADFun<double> f(x, y);

   return ok;
}
// END C++