Beispiel #1
0
def test_hook_args_and_cmd_signature_malleability():
    """Challenge the hook_arg module with methods used with different signatures"""
    a = syft.LoggingTensor().on(torch.tensor([1.0, 2]))
    b = syft.LoggingTensor().on(torch.tensor([1.0, 2]))

    r1 = a + b
    assert (r1 == syft.LoggingTensor().on(torch.tensor([2.0, 4]))).all()

    r2 = a + 1
    assert (r2 == syft.LoggingTensor().on(torch.tensor([2.0, 3]))).all()

    r3 = a + b
    assert (r3 == syft.LoggingTensor().on(torch.tensor([2.0, 4]))).all()
Beispiel #2
0
def test_method_on_attribute(workers):

    bob = workers["bob"]

    # create remote object with children
    x = torch.Tensor([1, 2, 3])
    x = syft.LoggingTensor().on(x).send(bob)

    # call method on data tensor directly
    x.child.point_to_attr = "child.child"
    y = x.add(x)
    assert isinstance(y.get(), torch.Tensor)

    # call method on loggingtensor directly
    x.child.point_to_attr = "child"
    y = x.add(x)
    y = y.get()
    assert isinstance(y.child, syft.LoggingTensor)

    # # call method on zeroth attribute
    # x.child.point_to_attr = ""
    # y = x.add(x)
    # y = y.get()
    #
    # assert isinstance(y, torch.Tensor)
    # assert isinstance(y.child, syft.LoggingTensor)
    # assert isinstance(y.child.child, torch.Tensor)

    # call .get() on pinter to attribute (should error)
    x.child.point_to_attr = "child"
    try:
        x.get()
    except syft.exceptions.CannotRequestObjectAttribute as e:
        assert True