def draw_table():
            plot_graph2 = tk.Toplevel(graph_window)
            plot_graph2.title("Computational Table")
            plot_graph2.geometry("600x600")
            #         fig = ADgraph.gen_table(function_output)

            f = tk.Frame(plot_graph2)
            f.pack(side=tk.TOP, fill=tk.BOTH, expand=1)
            df = ADgraph.gen_table(
                function_output(ADnum(value_x.get(), ins=6, ind=0),
                                ADnum(value_y.get(), ins=6, ind=1),
                                ADnum(value_z.get(), ins=6, ind=2),
                                ADnum(value_m.get(), ins=6, ind=3),
                                ADnum(value_n.get(), ins=6, ind=4),
                                ADnum(value_k.get(), ins=6, ind=5)))
            table = pt = Table(f,
                               dataframe=df,
                               showtoolbar=True,
                               showstatusbar=True)
            pt.show()
def test_ADnum_valtype():
    with pytest.raises(ValueError):
        z = ADnum('zoo', der=1)
def test_ADnum_radd():
    x = ADnum(3.0, der=1)
    f = 2.0 + x
    assert f.val == 5.0
    assert f.der == 1.0
    assert len(f.graph) == 2
def test_neg():
    x = ADnum(4, der=1)
    f = -x
    assert f.val == -4.0
    assert f.der == -1.0
    assert len(f.graph) == 1
def test_ADnum_derconsistent():
    with pytest.raises(ValueError):
        z = ADnum(3, der=np.array([1, 3]), ins=5)
def test_draw_graph():
    X = ADnum(1, der=1)
    Y = ADmath.sin(X) + 3
    fig = ADgraph.draw_graph(Y)
    assert type(fig) == matplotlib.figure.Figure
def test_ADnum_nodernothing():
    with pytest.raises(Exception):
        z = ADnum(3)
def test_vecinput():
    x = ADnum([1, 2, 3], ins=1, ind=0)
    assert np.array_equal(x.val, np.array([1., 2., 3.]))
    assert np.array_equal(x.der, np.array([1., 1., 1.]))
def test_ADnum_dertype():
    with pytest.raises(ValueError):
        z = ADnum(3.0, der='zebra')
def test_ADmath_log():
    f = ADmath.log(ADnum(72, der=1))
    assert f.val == np.log(72)
    assert f.der == 1 / 72
    assert len(f.graph) == 1
def test_ADmath_exp():
    f = ADmath.exp(ADnum(-3, der=1))
    assert f.val == np.exp(-3)
    assert f.der == np.exp(-3)
    assert len(f.graph) == 1
def test_ADmath_tanh():
    f = ADmath.tanh(ADnum(-5, der=1))
    assert f.val == np.tanh(-5)
    assert f.der == 1 / (np.cosh(-5)**2)
    assert len(f.graph) == 1
def test_ADmath_cosh():
    f = ADmath.cosh(ADnum(3, der=1))
    assert f.val == np.cosh(3)
    assert f.der == np.sinh(3)
    assert len(f.graph) == 1
def test_ADmath_arctan():
    f = ADmath.arctan(ADnum(1, der=1))
    assert f.val == np.arctan(1)
    assert f.der == .5
    assert len(f.graph) == 1
def test_ADmath_arccos():
    f = ADmath.arccos(ADnum(.3, der=1))
    assert f.val == np.arccos(.3)
    assert f.der == -1 / (np.sqrt(1 - .3**2))
    assert len(f.graph) == 1
def test_2xe2x():
    x = ADnum(2, der=1)
    f = 2 * x * ADmath.exp(2 * x)
    assert f.val == 4 * np.exp(4)
    assert f.der == 2 * np.exp(4.0) + 8 * np.exp(4)
def test_multivar():
    x = ADnum(3, ins=2, ind=0)
    y = ADnum(4, ins=2, ind=1)
    f = 2 * y + 2 * x**2
    assert f.val == 2 * 4 + 2 * 3**2
    assert f.der.all() == np.all(np.array([12, 2]))
def test_ADmath_logistic():
    f = ADmath.logistic(ADnum(0, der=1))
    assert f.val == .5
    assert f.der == .25
def test_vecinput_multi():
    x = ADnum([1, 2, 3], ins=2, ind=0)
    assert np.array_equal(x.der, np.array([[1., 1., 1.], [0., 0., 0.]]))
def test_ADmath_sqrt():
    f = ADmath.sqrt(ADnum(40, der=1))
    assert f.val == np.sqrt(40)
    assert f.der == 1 / (2 * np.sqrt(40))
    assert len(f.graph) == 1
def test_reverse_graph():
    d = {'y': [('x', 'test')]}
    rd = {'x': [('y', 'test')]}
    Y = ADnum(1, der=1, graph=d)
    rg = ADgraph.reverse_graph(Y)
    assert rd == rg
def test_12x():
    x = ADnum(1, der=1)
    f = 1 / (1 - 2 * x)
    assert f.val == 1 / (1 - 2)
    assert f.der == 2 / (1 - 2)**2
def test_gen_table():
    X = ADnum(1, der=1)
    Y = ADmath.sin(X) + 3
    dat = ADgraph.gen_table(Y)
    assert type(dat) == pandas.core.frame.DataFrame
def test_ADnum_nodernoind():
    with pytest.raises(Exception):
        z = ADnum(4, ins=3)
def test_graphiput():
    z = ADnum(1, der=1, graph={'a': 1})
    assert z.graph == {'a': 1}
def test_xex():
    x = ADnum(2, der=1)
    f = x * ADmath.exp(x)
    assert f.val == 2.0 * np.exp(2.0)
    assert f.der == np.exp(2.0) + 2.0 * np.exp(2.0)
def test_ADnum_rmul():
    x = ADnum(3.0, der=1)
    f = 2.0 * x
    assert f.val == 6.0
    assert f.der == 2.0
    assert len(f.graph) == 2
def test_5x2lnx():
    x = ADnum(1, der=1)
    f = 5 * x**2 * ADmath.log(x)
    assert f.val == 0.0
    assert f.der == 10 * 1.0 * np.log(1.0) + 5 * 1.0
def test_ADnum_sub():
    x = ADnum(5.0, der=1)
    f = x - 2.0
    assert f.val == 3.0
    assert f.der == 1.0
    assert len(f.graph) == 2
def test_sinxcosx():
    x = ADnum(0, der=1)
    f = ADmath.sin(x) * ADmath.cos(x)
    assert f.val == np.sin(0) * np.cos(0)
    assert f.der == -(np.sin(0)**2) + np.cos(0)**2