Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow dynamic function creation for dtype copy #395

Merged

Conversation

JoranAngevaare
Copy link
Member

@JoranAngevaare JoranAngevaare commented Feb 6, 2021

What is the problem / what does the code in this PR do
Add a function to more easily numbafy the copy from dtype to dtype. Also see XENONnT/straxen#353

Can you briefly describe how it works?
Numba magic 馃

Rather than writing each time a cumbersome function that has to get the dtype write, why not code this. The annoying thing about numba is that it does not allow you to use strings to loop over. This is a workaround.

Can you give a minimal working example (or illustrate with a figure)?

r = np.ones(1000, dtype=strax.raw_record_dtype()
def test_raw_to_records(r):
    buffer = np.zeros(len(r), r.dtype)
    strax.copy_to_buffer(r, buffer, "_test_r_to_buffer")
    if len(r):
        assert np.all(buffer == r)

Special thanks to
Daniel for helping writing this up nicely and Jim Pivarski for showing such functionality in numba.

Copy link
Collaborator

@WenzDaniel WenzDaniel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot Joran for this awesome idea. It makes copying data much less tedious.

strax/dtypes.py Show resolved Hide resolved
@JoranAngevaare JoranAngevaare merged commit cf3dacc into AxFoundation:master Feb 7, 2021
@JoranAngevaare JoranAngevaare deleted the dynamic_njit_copy branch February 7, 2021 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants