Prev Next assign_op.py Headings

@(@\newcommand{\B}[1]{{\bf #1}} \newcommand{\R}[1]{{\rm #1}}@)@
Computed Assignment Operators: Example and Test
 
# Example using a_float ------------------------------------------------------
from pycppad import *
def pycppad_test_assign_op() :
  x = 2.
  y = 3.
  #
  tmp  = ad(x)
  tmp += ad(y)
  assert tmp == x + y
  tmp  = ad(x)
  tmp += y
  assert tmp == x + y
  #
  tmp  = ad(x)
  tmp -= ad(y)
  assert tmp == x - y
  tmp  = ad(x)
  tmp -= y
  assert tmp == x - y
  #
  tmp  = ad(x)
  tmp *= ad(y)
  assert tmp == x * y
  tmp  = ad(x)
  tmp *= y
  assert tmp == x * y
  #
  tmp  = ad(x)
  tmp /= ad(y)
  assert tmp == x / y
  tmp  = ad(x)
  tmp /= y
  assert tmp == x / y

# Example using a2float ------------------------------------------------------
from pycppad import *
def pycppad_test_assign_op_a2() :
  x = 2.
  y = 3.
  #
  tmp  = ad(ad(x))
  tmp += ad(ad(y))
  assert tmp == x + y
  tmp  = ad(ad(x))
  tmp += y
  assert tmp == x + y
  #
  tmp  = ad(ad(x))
  tmp -= ad(ad(y))
  assert tmp == x - y
  tmp  = ad(ad(x))
  tmp -= y
  assert tmp == x - y
  #
  tmp  = ad(ad(x))
  tmp *= ad(ad(y))
  assert tmp == x * y
  tmp  = ad(ad(x))
  tmp *= y
  assert tmp == x * y
  #
  tmp  = ad(ad(x))
  tmp /= ad(ad(y))
  assert tmp == x / y
  tmp  = ad(ad(x))
  tmp /= y
  assert tmp == x / y

Input File: example/assign_op.py