Prev Next vector_set_get_xam.py Headings

@(@\newcommand{\B}[1]{ {\bf #1} } \newcommand{\R}[1]{ {\rm #1} }@)@
Python: Setting and Getting Vector Elements: Example and Test
def vector_set_get_xam() :
     #
     # load the Cppad Swig library
     import py_cppad
     #
     # initialize return variable
     ok = True
     # ---------------------------------------------------------------------
     n = 4
     bv = py_cppad.vec_bool(n)
     iv = py_cppad.vec_int(n)
     dv = py_cppad.vec_double(n)
     av = py_cppad.vec_a_double(n)
     #
     # setting elements
     for i in range( n  ) :
          bv[i] = i > n / 2
          iv[i] = 2 * i
          dv[i] = 3.0 * i
          av[i] = py_cppad.a_double(4.0 * i)
     #
     #
     for i in range( n  ) :
          be = bv[i]
          ok = ok and be == (i > n / 2) 
          #
          ie = iv[i]
          ok = ok and ie == 2 * i 
          #
          de = dv[i]
          ok = ok and de == 3.0 * i 
          #
          ae = av[i]
          ok = ok and ae.value() == 4.0 * i 
     #
     #
     return( ok )
#

Input File: build/lib/example/python/vector_set_get_xam.py