MCPcopy Create free account
hub / github.com/coin-or/CppAD / Integer

Function Integer

example/general/integer.cpp:23–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21# include <cppad/cppad.hpp>
22
23bool Integer(void)
24{ bool ok = true;
25 using CppAD::AD;
26 using CppAD::Integer;
27
28 // domain space vector
29 size_t n = 2;
30 CPPAD_TESTVECTOR(AD<double>) x(n);
31 x[0] = 3.5;
32 x[1] = 4.5;
33
34 // check integer before recording
35 ok &= (Integer(x[0]) == 3);
36 ok &= (Integer(x[1]) == 4);
37
38 // start recording
39
40 // declare independent variables and start tape recording
41 CppAD::Independent(x);
42
43 // check integer during recording
44 ok &= (Integer(x[0]) == 3);
45 ok &= (Integer(x[1]) == 4);
46
47 // check integer for VecAD element
48 CppAD::VecAD<double> v(1);
49 AD<double> zero(0);
50 v[zero] = 2;
51 ok &= (Integer(v[zero]) == 2);
52
53 // range space vector
54 size_t m = 1;
55 CPPAD_TESTVECTOR(AD<double>) y(m);
56 y[0] = - x[1];
57
58 // create f: x -> y and stop recording
59 CppAD::ADFun<double> f(x, y);
60
61 // check integer after recording
62 ok &= (Integer(x[0]) == 3.);
63 ok &= (Integer(x[1]) == 4.);
64 ok &= (Integer(y[0]) == -4.);
65
66 return ok;
67}
68// END C++

Callers 8

SolveFunction · 0.70
check_digits10Function · 0.70
string2signedFunction · 0.50
string2unsignedFunction · 0.50
base_requireFunction · 0.50
for_sparse_jacMethod · 0.50
rev_sparse_jacMethod · 0.50
rev_sparse_hesMethod · 0.50

Calls 1

IndependentFunction · 0.70

Tested by

no test coverage detected