numcodecs icon indicating copy to clipboard operation
numcodecs copied to clipboard

Refactor decode implementation in vlen codecs

Open alimanfoo opened this issue 7 years ago • 4 comments

As noticed in #81, there is a lot of code duplication in the implementation of the decode() methods in the vlen codecs. Would be good to refactor and remove code duplication.

alimanfoo avatar Nov 29 '18 12:11 alimanfoo

I had a quick crack at this, and it mostly works (we just need a def _decode_item(self, data, size) method defined in sub classes). However, there's some Cython trickiness involved and this didn't work as expected for the Array version. I don't know enough about Cython to dig into it I'm afraid, and I really must stop procrastinating from what I'm actually supposed to be doing!

jeromekelleher avatar Nov 29 '18 13:11 jeromekelleher

I had a quick crack at this, and it mostly works (we just need a def _decode_item(self, data, size) method defined in sub classes). However, there's some Cython trickiness involved and this didn't work as expected for the Array version. I don't know enough about Cython to dig into it I'm afraid, and I really must stop procrastinating from what I'm actually supposed to be doing!

Yeah, don't you have a proposal deadline :smiley:

Would be cool if you could whack whatever you have in a PR, just to take a look.

alimanfoo avatar Nov 29 '18 14:11 alimanfoo

Ack, I nuked it all. It's very simple though, just adding a VlenBase class, putting the decode method in there and then having an implementation of def _decode_item(self, data, size) in each subclass. Worked fine for the non-array subclasses.

jeromekelleher avatar Nov 29 '18 15:11 jeromekelleher

:smile: no worries, thanks for the info.

alimanfoo avatar Nov 29 '18 15:11 alimanfoo