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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add convenience method for getting slices from a view #596

Open
tskisner opened this issue Oct 19, 2022 · 0 comments
Open

Add convenience method for getting slices from a view #596

tskisner opened this issue Oct 19, 2022 · 0 comments

Comments

@tskisner
Copy link
Member

This issue was spawned by discussion in #593

Originally, the "view" concept (i.e. returning a list of detdata / shared views) seemed like a nice shorthand way of accessing the underlying data- especially when working interactively. However, depending on the underlying data, there can be a performance penalty looping over views first and then detectors within a view (since this is jumping around in memory). The operators where we have ported the internals to C++ / OpenMP or Jax now always loop over detectors and then elements of the intervals list (which is now just a numpy array with a custom dtype). This keeps the memory access contiguous.

As suggested in the other thread, it would be convenient to have a quick way of getting the sample slices associated with an interval list / view. The intervals object is the plain numpy array of intervals, and the view object would not only provide the current list of detdata / shared views (which it implements via Sequence.__getitem__), but also have a method that returns a list of actual slice objects.

So the pattern would look something like:

for det in dets:
    for vslice in ob.view["intervals_name"].slices:
        nsample = vslice.stop - vslice.start
        ob.detdata["signal"][det, vslice] += 1.0

Instead of

for det in dets:
    for intrvl in ob.intervals["intervals_name"]:
        vslice = slice(intrvl.first, intrvl.last + 1)
        nsample = intrvl.last - intrvl.first + 1
        ob.detdata["signal"][det, vslice] += 1.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant