def test_division(workers): alice, bob, james = workers["alice"], workers["bob"], workers["james"] x0 = torch.tensor(10).share(alice, bob, crypto_provider=james, dtype="long").child y0 = torch.tensor(2).share(alice, bob, crypto_provider=james, dtype="long").child res0 = division(x0, y0, bit_len_max=5) x1 = ( torch.tensor([[25, 9], [10, 30]]) .share(alice, bob, crypto_provider=james, dtype="long") .child ) y1 = ( torch.tensor([[5, 12], [2, 7]]).share(alice, bob, crypto_provider=james, dtype="long").child ) res1 = division(x1, y1, bit_len_max=5) assert res0.get() == torch.tensor(5) assert (res1.get() == torch.tensor([[5, 0], [5, 4]])).all() # With dtype int x0 = torch.tensor(10).share(alice, bob, crypto_provider=james, dtype="int").child y0 = torch.tensor(2).share(alice, bob, crypto_provider=james, dtype="int").child res0 = division(x0, y0, bit_len_max=5) x1 = ( torch.tensor([[25, 9], [10, 30]]) .share(alice, bob, crypto_provider=james, dtype="int") .child ) y1 = torch.tensor([[5, 12], [2, 7]]).share(alice, bob, crypto_provider=james, dtype="int").child res1 = division(x1, y1, bit_len_max=5) assert res0.get() == torch.tensor(5) assert (res1.get() == torch.tensor([[5, 0], [5, 4]])).all()
def test_division(workers): alice, bob, james = ( workers["alice"], workers["bob"], workers["james"], ) tensorA = (torch.tensor([[0, 10, 10, 20, 20]]).share(alice, bob, crypto_provider=james, dtype="long").child) tensorB = (torch.tensor([[1, 2, 3, 4, 5]]).share(alice, bob, crypto_provider=james, dtype="long").child) division = securenn.division(tensorA, tensorB) assert (division.get() == torch.tensor([[0, 5, 3, 5, 4]])).all()
def _private_div(self, divisor): return securenn.division(self, divisor)
def _private_div(self, divisor): print("guaguaguaguagua") return securenn.division(self, divisor)