Exemple #1
0
    def test_sin_reverse(self):
        x = FADiff()
        x.set_mode('reverse')
        x = x.new_scal(3)

        a = Elems.sin(x)
        assert a.val == pytest.approx(0.1411200080598672)
        assert a.der == pytest.approx(-0.9899924966004454)

        y = 2
        assert Elems.sin(y) == np.sin(y)
Exemple #2
0
      f'{x.der}')              #   derivatives for input vars used in calculation
print(f'y.val --> '                  
      f'{y.val}')              # Should be [5]
print(f'y._der --> '           # '_der' is a dictionary containing the 
      f'{y._der}')             #   partial derivatives for a var
print(f'y.der --> '
      f'{y.der}')              # Should be [1]
print(f'z.val --> '                  
      f'{z.val}')              # Should be [3]
print(f'z._der --> '           # '_der' is a dictionary containing the 
      f'{z._der}')             #   partial derivatives for a var
print(f'z.der --> '
      f'{z.der}')              # Should be [1]

print(f'\ncheck = x * y + ef.sin(x)')
check = x * y + ef.sin(x)
print(f'check.val --> '
      f'{check.val}')                    # Should be [10.909...]
print(f'check.der --> '
      f'{check.der}')                 # Should be [4.583..., 2]
print(f'check._der.get(x) --> '
      f'{check._der.get(x)}')         # Should be 4.583...
print(f'check._der.get(y) --> '  
      f'{check._der.get(y)}')         # Should be 2

print(f'\ncheck = ef.sin(x + y)')
check = ef.sin(x + y)
print(f'check.val --> ' 
      f'{check.val}')                    # Should be [0.656...]
print(f'check.der --> '
      f'{check.der}')