python - Numpy Namespace Issue -


i have following function:

def add_bch(compressed):     k = 16 #input blocks of 16 bits.      prim_poly = poly([1, 0, 1, 0, 0, 1]) # x^5+x^2+1     prim_poly_3 = poly([1, 0, 1, 1, 1, 1]) #prim_poly^3 -> x^5+x^4+x^3+x^2+1     prim_poly_5 = poly([1, 1, 1, 0, 1, 1]) #prim_poly^5 -> x^5+x^4+x^2+x+1      gen_poly = npp.polymul(npp.polymul(prim_poly, prim_poly_3), prim_poly_5)[0]      compressed = add_padding(compressed, k)      compressed_with_ecc = []     in range(len(compressed)/k):         block = compressed[(k*i):(k*(i+1))]         block_poly = bitstr_to_poly(block)         quotient, remainder = npp.polydiv(block_poly, gen_poly)         compressed_with_ecc.append(poly_to_bitstr(block. remainder))      return bits().join(compressed_with_ecc) 

where relevant import statements are:

from bitstring import bitarray, bits import numpy.polynomial.polynomial npp numpy.polynomial import polynomial poly 

when run code, error:

bash-4.2$ python send_mess < pg2600.txt traceback (most recent call last):   file "send_mess", line 113, in <module>     encoded = add_bch(compressed)   file "send_mess", line 105, in add_bch     quotient, remainder = npp.polydiv(block_poly, gen_poly)   file "/usr/lib64/python2.7/site-packages/numpy/polynomial/polynomial.py", line 408, in polydiv     return c1/c2[-1], c1[:1]*0   file "<string>", line 373, in __rtruediv__ unboundlocalerror: local variable 'quo' referenced before assignment 

i know numpy imports can cause namespace issues, try might can't figure out problem here. 1 thing occurred me 2 numpy import statements might clash, seems me should separate each other, should be:

numpy   ...   polynomial      ...      polynomial      polynomial         ...         polymul         polydiv         ...      ...   ... 

however did try:

from bitstring import bitarray, bits import numpy.polynomial npp 

with relevant name changes, no avail. tried directly importing everything, so:

from bitstring import bitarray, bits numpy.polynomial.polynomial import polymul, polydiv numpy.polynomial import polynomial poly 

which did not work. @ no point in function (or program in general) refer variable "quo", , don't see of code have stepped on numpy's toes.

it's bug in numpy. in implementation of __rtruediv__ @ https://github.com/numpy/numpy/blob/master/numpy/polynomial/_polybase.py#l421, can see if len(self.coef) not 1, statement

    return self.__class__(quo, self.domain, self.window) 

is executed, quo not defined.

here's simple example generates error:

in [1]: import numpy.polynomial.polynomial npp  in [2]: p1 = npp.polynomial([1,2])  in [3]: p2 = npp.polynomial([3,4])  in [4]: npp.polydiv(p1, p2) --------------------------------------------------------------------------- unboundlocalerror                         traceback (most recent call last) <ipython-input-4-00c25f56fb20> in <module>() ----> 1 npp.polydiv(p1, p2)      /users/warren/anaconda/lib/python2.7/site-packages/numpy/polynomial/polynomial.pyc in polydiv(c1, c2)     406     len2 = len(c2)     407     if len2 == 1 : --> 408         return c1/c2[-1], c1[:1]*0     409     elif len1 < len2 :     410         return c1[:1]*0, c1  /users/warren/anaconda/lib/python2.7/site-packages/numpy/polynomial/polynomial.pyc in __rtruediv__(self, other)  unboundlocalerror: local variable 'quo' referenced before assignment 

i reported issue here: https://github.com/numpy/numpy/issues/4631.


Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -