PyFHE
PyFHE copied to clipboard
Error in NTT.py
I created the profile folder and run "python3 Test_Ctxt.py". I get following error. Can you please help?
-----Homomorphic Operation-----
First multiplication done 17.053s
Traceback (most recent call last):
File "Test_Ctxt.py", line 76, in
I created the profile folder and run "python3 Test_Ctxt.py". I get following error. Can you please help?
-----Homomorphic Operation----- First multiplication done 17.053s Traceback (most recent call last): File "Test_Ctxt.py", line 76, in c_mul *= c_mul File "/root/PyFHE/Ctxt.py", line 62, in mul crt_c10 = CRTPoly(self.c[0], self.prime_set) File "/root/PyFHE/CRTPoly.py", line 19, in init self.initial_wo_crt(poly, primes) File "/root/PyFHE/CRTPoly.py", line 23, in initial_wo_crt self.crt_poly = self.crtPoly(poly) File "/root/PyFHE/CRTPoly.py", line 127, in crtPoly fft_crt_poly = NTT(crt_poly, prime, self.N) File "/root/PyFHE/NTT.py", line 30, in init self.initial_wo_ntt(poly, M, N, ideal, w, phi) File "/root/PyFHE/NTT.py", line 47, in initial_wo_ntt self.fft_poly = self.ntt(poly_bar) File "/root/PyFHE/NTT.py", line 168, in ntt rev_poly = self.orderReverse(poly, N_bit) File "/root/PyFHE/NTT.py", line 148, in orderReverse coeff ^= _poly[rev_i] TypeError: unsupported operand type(s) for ^=: 'float' and 'float'
Did you get any solution to this @rkarn ? Struggling with the same
I saw a solution to resolve this error, add a line in ntt.py:
def orderReverse(self, poly, N_bit):
_poly = list(poly)
_poly = list(np.array(_poly).astype(int))
for i, coeff in enumerate(_poly):
rev_i = self.bitReverse(i, N_bit)
if rev_i > i:
coeff ^= _poly[rev_i]
_poly[rev_i] ^= coeff
coeff ^= _poly[rev_i]
_poly[i] = coeff
return _poly
In this code , _poly = list(np.array(_poly).astype(int))
was added, but I don't know why and is it right. You can try it, and the code runs correctly in small parameter.