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

Support more event-centric binary operations via sc.lookup #3332

Open
SimonHeybrock opened this issue Nov 27, 2023 · 2 comments
Open

Support more event-centric binary operations via sc.lookup #3332

SimonHeybrock opened this issue Nov 27, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@SimonHeybrock
Copy link
Member

SimonHeybrock commented Nov 27, 2023

Context

See Event-centric arithmetic, in particular multiplication and division. Currently this only supports multiplication and division.

Suggestion

I suggest to extend this for addition and subtraction.

Motivation

For WFM stitching we are currently using an approach where we bin the data, apply a bin-centric operation, then concat. This is actually quite slow, and I think it can be done much simpler using time_of_flight = da.bins.coords['time_offset'].bins + sc.lookup(subframe_offset). This also appears to be faster (on synthetic data).

What needs to be done

  1. Add support for + and -. This should be simple.
  2. Add support for operating on Variable instead of DataArray. Currently we use the coord to lookup the bin in the lookup table and operate on the data values. In this case we want to use the variable for lookup as well as the operation. This could be done in the Python layer by creating a temporary data array (no copy needed).

2.) is probably optional, since this can be done on the user side.

@SimonHeybrock SimonHeybrock added the enhancement New feature or request label Nov 27, 2023
@SimonHeybrock
Copy link
Member Author

Actually, one can relatively easily achieve the same using sc.lookup to create a temporary. For example, to shift the y-coord:

lut = sc.lookup(myshifts, dim='time')
time = da.bins.coords['time']
time -= lut[time]

With the suggestion from the original message one could:

lut = sc.lookup(myshifts, dim='time')
time = da.bins.coords['time']
time.bins -= lut

In theory the second option (suggested in the initial post) might be a bit faster, but it actually looks less intuitive.

@jl-wynen
Copy link
Member

If it turns out that the second option is faster, could the first operation be implemented in terms of the second in appropriate cases?

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

No branches or pull requests

2 participants