Exemplo n.º 1
0
def test_jacobian():
    ns = NameSpace(2)
    x = ns.Symbol('x')
    y = ns.Symbol('y')
    my = ns.Matrix(2, 1, [x + y, x * y])
    mx = ns.Matrix(1, 2, [x, y])
    assert my.shape == (2, 1)
    assert mx.shape == (1, 2)
    J = my.jacobian(mx)
    out = J.eval_float(np.array([2., 3.]))
    assert np.allclose(out, [[1, 1], [3, 2]])
Exemplo n.º 2
0
def test_Matrix():
    ns = NameSpace(2)
    x = ns.Symbol('x')
    y = ns.Symbol('y')
    matrix = ns.Matrix(2, 2, [[x + 1, y - 2], [x - y, x * y]])
    out = matrix.eval_float(np.array([2., 3.]))
    assert np.allclose(out, [[3, 1], [-1, 6]])