def einsum(self, other: 'FixedPointTensor', einsum_expr, target_name=None): spdz = self.get_spdz() target_name = target_name or spdz.name_service.next() def _dot_func(_x, _y): return np.einsum(einsum_expr, _x, _y, optimize=True) a, b, c = beaver_triplets(a_tensor=self.value, b_tensor=other.value, dot=_dot_func, q_field=self.q_field, he_key_pair=(spdz.public_key, spdz.private_key), communicator=spdz.communicator, name=target_name) x_add_a = self._raw_add(a).rescontruct(f"{target_name}_confuse_x") y_add_b = other._raw_add(b).rescontruct(f"{target_name}_confuse_y") cross = c - _dot_func(a, y_add_b) - _dot_func(x_add_a, b) if spdz.party_idx == 0: cross += _dot_func(x_add_a, y_add_b) cross = cross % self.q_field cross = self.endec.truncate(cross, self.get_spdz().party_idx) share = self._boxed(cross) return share
def dot(self, other: 'FixedPointTensor', target_name=None): spdz = self.get_spdz() if target_name is None: target_name = NamingService.get_instance().next() a, b, c = beaver_triplets(a_tensor=self.value, b_tensor=other.value, dot=table_dot, q_field=self.q_field, he_key_pair=(spdz.public_key, spdz.private_key), communicator=spdz.communicator, name=target_name) x_add_a = (self + a).rescontruct(f"{target_name}_confuse_x") y_add_b = (other + b).rescontruct(f"{target_name}_confuse_y") cross = c - table_dot_mod(a, y_add_b, self.q_field) - table_dot_mod( x_add_a, b, self.q_field) if spdz.party_idx == 0: cross += table_dot_mod(x_add_a, y_add_b, self.q_field) cross = cross % self.q_field cross = self.endec.truncate(cross, self.get_spdz().party_idx) share = fixedpoint_numpy.FixedPointTensor(cross, self.q_field, self.endec, target_name) return share