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

einsum for xarray #1951

Closed
fujiisoup opened this issue Mar 2, 2018 · 1 comment
Closed

einsum for xarray #1951

fujiisoup opened this issue Mar 2, 2018 · 1 comment

Comments

@fujiisoup
Copy link
Member

fujiisoup commented Mar 2, 2018

Code Sample, a copy-pastable example if possible

I sometimes want to make more flexible dot product of two data arrays,
where we sum up along a part of common dimensions.

# Your code here
da_vals = np.arange(6 * 5 * 4).reshape((6, 5, 4))
da = DataArray(da_vals, dims=['x', 'y', 'z'])
dm_vals = np.arange(6 * 4).reshape((6, 4))
dm = DataArray(dm_vals, dims=['x', 'z'])

# I want something like this
da.dot(dm, 'z')  # -> dimensions of the output array: ['x', 'y']

It's an intermediate path of np.matmul and np.tensordot.

Is this feature sufficiently universal?

EDIT:
I just noticed dask does not have einsum yet (dask/dask#732).
We maybe need to wait or decide to support only numpy arrays.

@fujiisoup fujiisoup changed the title Specify dimensions for dot einsum for xarray Mar 2, 2018
@shoyer
Copy link
Member

shoyer commented Mar 2, 2018

I like the idea of an einsum wrapper for xarray. This would probably be straightforward to build on top of the apply_ufunc machinery. I wouldn't worry about the lack of einsum for dask yet -- the linked dask issue already has several implementations, so we could easily add that later if desired.

There are at least two versions of this:

  • A dim argument for DataArray.dot that indicates which dimension(s) to sum over.
  • A function for applying this to many arrays simultaneously. Maybe xarray.dot(da1, da2, da3, dims=['x', 'y'])? This would use einsum internally but we don't need to specify the input dimensions again because we already have them on the DataArray objects.

@fujiisoup fujiisoup mentioned this issue Mar 6, 2018
4 tasks
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

2 participants