Skip to content

Instantly share code, notes, and snippets.

@dhuynh95
Created June 19, 2020 09:29
Show Gist options
  • Save dhuynh95/98f77211ca060240c3ec4c5182426931 to your computer and use it in GitHub Desktop.
Save dhuynh95/98f77211ca060240c3ec4c5182426931 to your computer and use it in GitHub Desktop.
Markdium-Introduction to encoding in CKKS
@patch_to(CKKSEncoder)
def pi(self, z: np.array) -> np.array:
"""Projects a vector of H into C^{N/2}."""
N = self.M // 4
return z[:N]
@patch_to(CKKSEncoder)
def pi_inverse(self, z: np.array) -> np.array:
"""Expands a vector of C^{N/2} by expanding it with its
complex conjugate."""
z_conjugate = z[::-1]
z_conjugate = [np.conjugate(x) for x in z_conjugate]
return np.concatenate([z, z_conjugate])
# We can now initialize our encoder with the added methods
encoder = CKKSEncoder(M)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment