def test_arccos_ad_results():
	# positive real numbers
	x = AutoDiff(0.5, 2)
	f = ef.arccos(x)
	assert f.val == np.array([[np.arccos(0.5)]])
	assert f.der == np.array([[-2/np.sqrt(1-0.5**2)]])
	assert f.jacobian == np.array([[-1/np.sqrt(1-0.5**2)]])

	# out of bounds - negative sqrt
	with pytest.warns(RuntimeWarning):
		y = AutoDiff(-2, 2)
		f = ef.arccos(y)
		assert np.isnan(f.val[0][0])
		assert np.isnan(f.der[0][0])
		assert np.isnan(f.jacobian[0][0])

	# out of bounds - divide by 0
	with pytest.warns(RuntimeWarning):
		y = AutoDiff(1, 2)
		f = ef.arccos(y)
		assert f.val == np.array([[np.arccos(1)]])
		assert np.isneginf(f.der[0][0])
		assert np.isneginf(f.jacobian[0][0])

	# zero
	z = AutoDiff(0, 2)
	f = ef.arccos(z)
	assert f.val == np.array([[np.arccos(0)]])
	assert f.der == np.array([[-2/np.sqrt(1-0**2)]])
	assert f.jacobian == np.array([[-1/np.sqrt(1-0**2)]])
Example #2
0
def test_arccos_ad_results():
    # positive real numbers
    x = Dual(0.5, 2)
    f = ef.arccos(x)
    assert f.Real == np.array([[np.arccos(0.5)]])
    assert f.Dual == np.array([[-2 / np.sqrt(1 - 0.5**2)]])

    # out of bounds - negative sqrt
    with pytest.warns(RuntimeWarning):
        y = Dual(-2, 2)
        f = ef.arccos(y)
        assert np.isnan(f.Real)
        assert np.isnan(f.Dual)

    # out of bounds - divide by 0
    with pytest.warns(RuntimeWarning):
        y = Dual(1, 2)
        f = ef.arccos(y)
        assert f.Real == np.array([[np.arccos(1)]])
        assert np.isneginf(f.Dual)

    # zero
    z = Dual(0, 2)
    f = ef.arccos(z)
    assert f.Real == np.array([[np.arccos(0)]])
    assert f.Dual == np.array([[-2 / np.sqrt(1 - 0**2)]])
def test_arccos_constant_results():
	a = ef.arccos(0.7)
	assert a == np.arccos(0.7)

	b = ef.arccos(0)
	assert b == np.arccos(0)

	with pytest.warns(RuntimeWarning):
		c = ef.arccos(-5)
		assert np.isnan(c)
def test_arccos_types():
	with pytest.raises(TypeError):
		ef.arccos('x')
	with pytest.raises(TypeError):
		ef.arccos("1234")