本文整理汇总了C++中CppAD::Integer方法的典型用法代码示例。如果您正苦于以下问题:C++ CppAD::Integer方法的具体用法?C++ CppAD::Integer怎么用?C++ CppAD::Integer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CppAD
的用法示例。
在下文中一共展示了CppAD::Integer方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Integer
bool Integer(void)
{ bool ok = true;
using CppAD::AD;
using CppAD::Integer;
// domain space vector
size_t n = 2;
CPPAD_TESTVECTOR(AD<double>) x(n);
x[0] = 3.5;
x[1] = 4.5;
// check integer before recording
ok &= (Integer(x[0]) == 3);
ok &= (Integer(x[1]) == 4);
// start recording
// declare independent variables and start tape recording
CppAD::Independent(x);
// check integer during recording
ok &= (Integer(x[0]) == 3);
ok &= (Integer(x[1]) == 4);
// check integer for VecAD element
CppAD::VecAD<double> v(1);
AD<double> zero(0);
v[zero] = 2;
ok &= (Integer(v[zero]) == 2);
// range space vector
size_t m = 1;
CPPAD_TESTVECTOR(AD<double>) y(m);
y[0] = - x[1];
// create f: x -> y and stop recording
CppAD::ADFun<double> f(x, y);
// check integer after recording
ok &= (Integer(x[0]) == 3.);
ok &= (Integer(x[1]) == 4.);
ok &= (Integer(y[0]) == -4.);
return ok;
}