|
Prev | Next | a_fun_abort_xam.py | Headings |
def a_fun_abort_xam() :
#
# load the Cppad Swig library
import py_cppad
#
# initialize return variable
ok = True
# ---------------------------------------------------------------------
n_ind = 2
#
# create ax
x = py_cppad.vec_double(n_ind)
for i in range( n_ind ) :
x[i] = i + 1.0
#
ax = py_cppad.independent(x)
#
# preform some a_double operations
ax0 = ax[0]
ax1 = ax[1]
ay = ax0 + ax1
#
# check that ay is a variable; its value depends on the value of ax
ok = ok and ay.variable()
#
# abort this recording
py_cppad.abort_recording()
#
# check that ay is now a parameter, no longer a variable.
ok = ok and ay.parameter()
#
# since it is a parameter, we can retrieve its value
y = ay.value()
#
# its value should be x0 + x1
ok = ok and y == x[0] + x[1]
#
# an abort when not recording has no effect
py_cppad.abort_recording()
#
return( ok )
#