Пример #1
0
    def truediv(
            self, y: Union["MPCTensor", torch.Tensor, float,
                           int]) -> "MPCTensor":
        """Apply the "div" operation between "self" and "y".

        Args:
            y (Union["MPCTensor", torch.Tensor, float, int]): Denominator.

        Returns:
            MPCTensor: Result of the operation.

        Raises:
            ValueError: If parties are more than two.
        """
        is_private = isinstance(y, MPCTensor)

        # TODO: Implement support for more than two parties.
        if is_private:
            if len(self.session.session_ptrs) > 2:
                raise ValueError(
                    "Private division currently works with a maximum of two parties only."
                )

            reciprocal = APPROXIMATIONS["reciprocal"]
            return self.mul(reciprocal(y))

        from sympc.protocol.spdz import spdz

        result = spdz.public_divide(self, y)
        return result
Пример #2
0
    def div(self, y: Union["MPCTensor", torch.Tensor, float,
                           int]) -> "MPCTensor":
        """Apply the "div" operation between "self" and "y".

        Args:
            y (Union["MPCTensor", torch.Tensor, float, int]: self / y

        Returns:
            MPCTensor. Result of the operation.
        """

        is_private = isinstance(y, MPCTensor)
        if is_private:
            raise NotImplementedError("Not implemented for MPCTensor")

        from sympc.protocol.spdz import spdz

        result = spdz.public_divide(self, y)
        return result