Open jason-s opened 6 years ago
Shorter example, without my helper functions:
import unireedsolomon as rs
rs4 = rs.RSCoder(15,11,generator=2,prim=0x13,fcr=0,c_exp=4)
print repr(rs4.encode('\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b'))
rs8 = rs.RSCoder(255,239,generator=2,prim=0x11d,fcr=0,c_exp=8)
print repr(rs4.encode('\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b'))
which prints
'\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x03\x03\x0c\x0c'
'\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\xbb\x06\xe6['
The creation of rs8
somehow causes rs4
to behave incorrectly.
Oh, I see the problem, they're using a singleton lookup table:
# Initialize the look-up tables for logarithm and anti-log
init_lut(generator=generator, prim=prim, c_exp=self.gf2_c_exp)
Bad.
@jason-s Yes this is a leftover of the original implementation that I did not make. I can't remember exactly why I did not factor this directly into the RSCoder class, but I think I tried and it led to duplicated code and a performance drop...
Anyway, this library is mostly for educational usage, as I think the object-oriented approach is more intuitive to tackle error correction codes. If you want a library for practical use, with good enough (for a pure python) performances and the possibility to use multiple codecs at the same time, you can checkout this library that share the exact same features as unireedsolomon:
GF2int
is a a global singleton and does not allow multiple RSCoder instances with different field generator polynomials.results in: