Пример #1
0
    def _private_mul(self, other, equation: str):
        """Abstractly Multiplies two tensors

        Args:
            self: an AdditiveSharingTensor
            other: another AdditiveSharingTensor
            equation: a string representation of the equation to be computed in einstein
                summation form
        """
        # check to see that operation is either mul or matmul
        assert equation == "mul" or equation == "matmul"
        cmd = getattr(torch, equation)

        assert isinstance(other, AdditiveSharingTensor)

        assert len(self.child) == len(other.child)

        if self.crypto_provider is None:
            raise AttributeError(
                "For multiplication a crypto_provider must be passed.")

        shares = spdz.spdz_mul(cmd, self, other, self.crypto_provider,
                               self.field, self.dtype)

        return shares
Пример #2
0
    def _private_mul(self, other, equation: str):
        """Abstractly Multiplies two tensors

        Args:
            self: an AdditiveSharingTensor
            other: another AdditiveSharingTensor
            equation: a string representation of the equation to be computed in einstein
                summation form
        """
        # check to see that operation is either mul or matmul
        if equation != "mul" and equation != "matmul":
            raise NotImplementedError(
                f"Operation({equation}) is not possible, only mul or matmul are allowed"
            )
        cmd = getattr(torch, equation)

        if not isinstance(other, AdditiveSharingTensor):
            raise TypeError("other is not an AdditiveSharingTensor")

        if self.crypto_provider is None:
            raise AttributeError(
                "For multiplication a crypto_provider must be passed.")

        shares = spdz.spdz_mul(equation, self, other, self.crypto_provider,
                               self.dtype, self.torch_dtype, self.field)

        return shares