<commit_before># stdlib
import operator
import time

# third party
import numpy as np
import pytest

# syft absolute
import syft as sy
from syft.core.tensor.smpc.mpc_tensor import MPCTensor

sy.logger.remove()

PORT = 9082

PARTIES = 2
clients = []
for i in range(PARTIES):
    client = sy.login(
        email="<EMAIL>", password="<PASSWORD>", port=(PORT + i)
    )
    clients.append(client)


@pytest.mark.integration
def test_secret_sharing() -> None:
    data = np.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]], dtype=np.int32)
    value_secret = clients[0].syft.core.tensor.tensor.Tensor(data)
    mpc_tensor = MPCTensor(secret=value_secret, shape=(2, 5), parties=clients)

    res = mpc_tensor.reconstruct()
    assert (res == data).all()


@pytest.mark.integration
@pytest.mark.parametrize("op_str", ["add", "sub"])
def test_mpc_private_private_op(op_str: str) -> None:
    value_1 = np.array([[1, 2, 3, 4, -5]], dtype=np.int32)
    value_2 = np.array([42], dtype=np.int32)

    remote_value_1 = clients[0].syft.core.tensor.tensor.Tensor(value_1)
    remote_value_2 = clients[1].syft.core.tensor.tensor.Tensor(value_2)

    mpc_tensor_1 = MPCTensor(parties=clients, secret=remote_value_1, shape=(1, 5))

    mpc_tensor_2 = MPCTensor(parties=clients, secret=remote_value_2, shape=(1,))

    op = getattr(operator, op_str)

    res = op(mpc_tensor_1, mpc_tensor_2)

    res = res.reconstruct()
    expected = op(value_1, value_2)

    assert (res == expected).all()


@pytest.mark.integration
@pytest.mark.parametrize("op_str", ["add", "sub", "mul"])
def test_mpc_public_private_op(op_str: str) -> None:
    value_1 = np.array([[1, 2, 3, 4, -5]], dtype=np.int32)

    remote_value_1 = clients[0].syft.core.tensor.tensor.Tensor(value_1)

    mpc_tensor_1 = MPCTensor(parties=clients, secret=remote_value_1, shape=(1, 5))

    public_value = 42

    op = getattr(operator, op_str)

    res = op(mpc_tensor_1, public_value)
    time.sleep(2)
    res = res.reconstruct()<commit_msg>reverted sleep for public_private<commit_after># stdlib
import operator

# third party
import numpy as np
import pytest

# syft absolute
import syft as sy
from syft.core.tensor.smpc.mpc_tensor import MPCTensor

sy.logger.remove()

PORT = 9082

PARTIES = 2
clients = []
for i in range(PARTIES):
    client = sy.login(
        email="<EMAIL>", password="<PASSWORD>", port=(PORT + i)
    )
    clients.append(client)


@pytest.mark.integration
def test_secret_sharing() -> None:
    data = np.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]], dtype=np.int32)
    value_secret = clients[0].syft.core.tensor.tensor.Tensor(data)
    mpc_tensor = MPCTensor(secret=value_secret, shape=(2, 5), parties=clients)

    res = mpc_tensor.reconstruct()
    assert (res == data).all()


@pytest.mark.integration
@pytest.mark.parametrize("op_str", ["add", "sub"])
def test_mpc_private_private_op(op_str: str) -> None:
    value_1 = np.array([[1, 2, 3, 4, -5]], dtype=np.int32)
    value_2 = np.array([42], dtype=np.int32)

    remote_value_1 = clients[0].syft.core.tensor.tensor.Tensor(value_1)
    remote_value_2 = clients[1].syft.core.tensor.tensor.Tensor(value_2)

    mpc_tensor_1 = MPCTensor(parties=clients, secret=remote_value_1, shape=(1, 5))

    mpc_tensor_2 = MPCTensor(parties=clients, secret=remote_value_2, shape=(1,))

    op = getattr(operator, op_str)

    res = op(mpc_tensor_1, mpc_tensor_2)

    res = res.reconstruct()
    expected = op(value_1, value_2)

    assert (res == expected).all()


@pytest.mark.integration
@pytest.mark.parametrize("op_str", ["add", "sub", "mul"])
def test_mpc_public_private_op(op_str: str) -> None:
    value_1 = np.array([[1, 2, 3, 4, -5]], dtype=np.int32)

    remote_value_1 = clients[0].syft.core.tensor.tensor.Tensor(value_1)

    mpc_tensor_1 = MPCTensor(parties=clients, secret=remote_value_1, shape=(1, 5))

    public_value = 42

    op = getattr(operator, op_str)

    res = op(mpc_tensor_1, public_value)

    res = res.reconstruct()
{'fraction_non_alphanumeric': 0.1516071880536573, 'fraction_numerical': 0.035180966843837, 'mean_word_length': 4.234437086092715, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2475524', 'n_tokens_mistral': 1599, 'n_tokens_neox': 1513, 'n_words': 295}