Skip to content

New codec contribution guide #125

Closed
Closed

Description

@jkmacc-LANL

Hi, all. If I were interested in contributing a new codec, is there a concise guide to follow, or should I just take a crack at imitating an existing one? I have no problems attempting the latter, but I feel like I might be missing part of the project docs that describes this explicitly, and I'd want to follow project best practices.

Many thanks!

Activity

  1. alimanfoo commented on Nov 12, 2018

    @alimanfoo
    Member

    Hi @jkmacc-LANL, thanks for getting in touch. There are no specific guideline as such, except for the documentation on the Codec abstract base class which is what you'd have to implement. Other than that, imitating any of the existing codecs is a fine way to go. If you have any questions while working on an implementation, please feel free to raise an issue to discuss.

    One point of detail maybe worth mentioning, generally the encode() and decode() methods should accept any object implementing the new-style buffer protocol. There are some exceptions to this rule, where you may be more specific in what type of object can be passed to encode(). You may notice this when looking at the existing codecs. But on decode() you should be prepared to accept anything exposing the new-style buffer protocol. Hope that makes sense.

  2. jakirkham commented on Nov 12, 2018

    @jakirkham
    Member

    ...generally the encode() and decode() methods should accept any object implementing the new-style buffer protocol

    FWIW we have been doing some work in PR ( #121 ), which should make this pretty trivial.

  3. jkmacc-LANL commented on Nov 12, 2018

    @jkmacc-LANL
    Author

    Thanks, @alimanfoo ! I've not worked with the buffer protocol directly before. I may have questions, but I'll try to follow your existing examples. @jakirkham So, pay attention to opportunities to use to_buffer and ndarray_to_buffer?

  4. alimanfoo commented on Nov 12, 2018

    @alimanfoo
    Member
  5. jakirkham commented on Nov 12, 2018

    @jakirkham
    Member

    So, pay attention to opportunities to use to_buffer and ndarray_to_buffer?

    Definitely.

    We will hopefully come up with a better name than to_buffer (maybe to_encodable_ndarray?).

    Currently ndarray_to_buffer exists, but it will be generalized a bit after that PR lands. So should handle the buffer protocol details for the user returning an ndarray that views the original data with shape and type intact.

  6. jkmacc-LANL commented on Nov 12, 2018

    @jkmacc-LANL
    Author

    @jakirkham I suspect I wouldn't get to this until after your PR, so I'll just follow examples that use it.

    @alimanfoo I'd try to contribute and wrap some C code. Some of it does things like differencing before compression, so I may need some guidance about how to use what you've already done instead of adding duplicative code.

  7. alimanfoo commented on Nov 13, 2018

    @alimanfoo
    Member
  8. jkmacc-LANL commented on Nov 13, 2018

    @jkmacc-LANL
    Author

    Thanks. It's the compress/decompress functions from this C code, which I currently have wrapped using ctypes. The format is called "e1" compression, which encodes groups of int32 values into variable-sized chunks of bytes. It's not well represented online, but is a common form of compression for geophysical time series.

  9. jkmacc-LANL commented on Nov 14, 2018

    @jkmacc-LANL
    Author

    Alternately, I'm finding a lot of similarities with existing compressors and filters; a gentle nudge towards any in particular for benchmark testing is also welcomed.

  10. jakirkham commented on Nov 19, 2018

    @jakirkham
    Member

    Yeah, there's a lot of boilerplate that we can cutdown on. There also are copies occurring in a few places too. Those are the other thing we are trying to address with PR ( #121 ). This should keep the code in compressors light.

  11. jkmacc-LANL commented on Nov 24, 2018

    @jkmacc-LANL
    Author

    Closing for now. Thanks, all!

  12. jakirkham commented on Nov 28, 2018

    @jakirkham
    Member

    So PR ( #128 ) just went in, which should make this a bit easier.

    The key additions are a few utility functions. These are ensure_ndarray and ensure_contiguous_ndarray. These create a NumPy ndarray from the data without copying by leveraging the buffer protocol. The latter, ensure_contiguous_ndarray, is intended for serializable data; so, it performs some checks along those lines.

    Also added is ensure_bytes, which will do at most 1 copy as that is required to create a bytes object. An existing function was renamed, now called ndarray_copy, and largely reimplemented internally to copy data to an output buffer.

    In the process of doing this work, codecs were revamped internally to use these functions. So there should be lots of examples. Please let us know if you have questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions