示例#1
0
def test_share_convert(workers):
    """
    This is a light test as share_convert is not used for the moment
    """
    alice, bob, james = workers["alice"], workers["bob"], workers["james"]
    L = 2 ** 64
    a_sh = (
        torch.LongTensor([-13, 3567, 2 ** 60])
        .share(alice, bob, crypto_provider=james, field=L)
        .child
    )

    res = share_convert(a_sh)
    assert res.dtype == "custom"
    assert res.field == L - 1
    assert (res.get() == torch.LongTensor([-13, 3567, 2 ** 60])).all()

    # With dtype int
    L = 2 ** 32
    a_sh = (
        torch.IntTensor([13, -3567, 2 ** 30])
        .share(alice, bob, crypto_provider=james, field=L)
        .child
    )

    res = share_convert(a_sh)
    assert res.dtype == "custom"
    assert res.field == L - 1
    assert (res.get() == torch.IntTensor([13, -3567, 2 ** 30])).all()
示例#2
0
def test_share_convert(workers):
    alice, bob, james = (
        workers["alice"],
        workers["bob"],
        workers["james"],
    )
    tensorA = (torch.tensor([10, 20, 30]).share(alice,
                                                bob,
                                                crypto_provider=james,
                                                dtype="long").child)
    tensorB = securenn.share_convert(tensorA)

    assert (tensorA.get() == tensorB.get()).all()
示例#3
0
def test_share_convert(workers):
    """
    This is a light test as share_convert is not used for the moment
    """
    alice, bob, james = workers["alice"], workers["bob"], workers["james"]
    L = 2**62
    x_bit_sh = (torch.LongTensor([13, 3567,
                                  2**60]).share(alice,
                                                bob,
                                                crypto_provider=james,
                                                field=L).child)

    res = share_convert(x_bit_sh)
    assert res.field == L - 1
    assert (res.get() % L == torch.LongTensor([13, 3567, 2**60])).all()