|
Prev | Next | a_double_cond_assign_xam.py | Headings |
def a_double_cond_assign_xam() :
#
# load the Cppad Swig library
import py_cppad
#
# initialize return variable
ok = True
# ---------------------------------------------------------------------
n_ind = 4
n_dep = 1
#
# create ax (value of independent variables does not matter)
x = py_cppad.vec_double(n_ind)
x[0] = 0.0
x[1] = 1.0
x[2] = 2.0
x[3] = 3.0
ax = py_cppad.independent(x)
#
# arguments to conditional assignment
left = ax[0]
right = ax[1]
if_true = ax[2]
if_false = ax[3]
#
# assignment
target = py_cppad.a_double()
target.cond_assign(
"<",
left,
right,
if_true,
if_false
)
#
# f(x) = taget
ay = py_cppad.vec_a_double(n_dep)
ay[0] = target
af = py_cppad.a_fun(ax, ay)
#
# assignment with different independent variable values
x[0] = 9.0 # left
x[1] = 8.0 # right
x[2] = 7.0 # if_true
x[3] = 6.0 # if_false
p = 0
y = af.forward(p, x)
ok = ok and y[0] == 6.0
#
return( ok )
#