Hashable problem with registration system for punctured codes' decoder

Issue #133 resolved
David Lucas repo owner created an issue

Punctured codes' decoder can take a decoder object as an optional parameter. Problem: a built decoder object is not hashable, and registration via @cached_method decorator fails...

I don't really see a clever way to fix this, if any of you has a clever idea, I'd be glad to hear it...

Comments (3)

  1. David Lucas reporter

    OK, I spent some time on this issue, and I think the best way to manage this is to implement __hash__ in any decoder class. Well, more specifically, I'm considering the following:

    • implement a default hash method in the abstract class, which returns a hash of the n-uple whose each entry is an argument of the constructor of the class XOR a hash of each of these entries, as advised in the Python doc

    • Of course, it won't be enough is one of the arguments to a decoder is itself unhashable... In that case, I'd say override __hash__ in the subclass.

    • And add a remark to decoder's docstring to explain this hash issues, and why we need hashes.

    Do you think it makes sense to do such a thing? And as encoder is still not yet positive reviewed, do you foresee an encoder which takes an encoder as construction argument? Or maybe it's better to not delay this anymore, and do the patch on the fly if the case happens one day...

  2. David Lucas reporter

    I finally came to something:

    implement a default hash method was in the end not possible. Plus, as many decoders have the same list of parameters (code, message space, associated encoder), two decoders over the same code (e.g. Gao and Berlekamp-Welch) will have the same hash according to the hash function described above.

    So, I implemented a hash function that does what's described above adding the string name of the decoder to the list of parameters.

    Problem: this function will have to be implemented in every decoder class...

    Maybe I'm overengineering things here, so if you see something smarter/easier, please tell me. For now, I'll stick to this as it's enough to test my Punctured Code's decoder.

  3. Log in to comment