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

apply_raw() for a simpler version of apply_ufunc() #1618

Open
shoyer opened this issue Oct 10, 2017 · 4 comments
Open

apply_raw() for a simpler version of apply_ufunc() #1618

shoyer opened this issue Oct 10, 2017 · 4 comments

Comments

@shoyer
Copy link
Member

shoyer commented Oct 10, 2017

apply_raw() would work like apply_ufunc(), but without the hard to understand broadcasting behavior and core dimensions.

The rule for apply_raw() would be that it directly unwraps its arguments and passes them on to the wrapped function, without any broadcasting. We would also include a dim argument that is automatically converted into the appropriate axis argument when calling the wrapped function.

Output dimensions would be determined from a simple rule of some sort:

  • Default output dimensions would either be copied from the first argument, or would take on the ordered union on all input dimensions.
  • Custom dimensions could either be set by adding a drop_dims argument (like dask.array.map_blocks), or require an explicit override output_dims.

This also could be suitable for defining as a method instead of a separate function. See #1251 and #1130 for related issues.

@jhamman
Copy link
Member

jhamman commented Nov 3, 2017

Would something like the following use case be covered by apply_raw:

def f(a, b, c):
    '''
    inputs: 3 1D Numpy arrays of differing lengths
    outputs: 1 1D Numpy array like `a`
    '''
    new = a + b.sum() + c.min()  # just an example using all three
    return new

The current apply_ufunc, when applied on NDarrays (eg time,x,y) cannot handle this since it tries to make sure all the inputs are broadcastable with each other.

@shoyer
Copy link
Member Author

shoyer commented Nov 3, 2017

@jhamman you could do that core dimensions, e.g., input_core_dims=[('time',), ('x',), ('y',)], output_core_dims=[('time',)]. But apply_raw would have the advantage that you don't need to think about core dimensions :).

@stale
Copy link

stale bot commented Oct 4, 2019

In order to maintain a list of currently relevant issues, we mark issues as stale after a period of inactivity

If this issue remains relevant, please comment here or remove the stale label; otherwise it will be marked as closed automatically

@stale stale bot added the stale label Oct 4, 2019
@dcherian dcherian removed the stale label Oct 4, 2019
@max-sixty max-sixty mentioned this issue Oct 29, 2019
4 tasks
@shoyer shoyer mentioned this issue Oct 6, 2020
3 tasks
@shoyer
Copy link
Member Author

shoyer commented Jan 1, 2021

More related discussion: #1074 (comment)

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

3 participants