home / github / issues

Menu
  • Search all tables
  • GraphQL API

issues: 1452291042

This data as json

id node_id number title user state locked assignee milestone comments created_at updated_at closed_at author_association active_lock_reason draft pull_request body reactions performed_via_github_app state_reason repo type
1452291042 I_kwDOAMm_X85WkDPi 7295 einops integration? 5635139 closed 0     5 2022-11-16T21:23:03Z 2023-06-14T18:20:05Z 2023-06-14T18:20:05Z MEMBER      

Is your feature request related to a problem?

I've been following https://github.com/arogozhnikov/einops with interest, and thought it would be worth raising whether we could offer an xarray integration, eventually inspired by the reshape discussion at https://github.com/pydata/xarray/discussions/7217#discussioncomment-4150613. (I thought there might have been a discussion / issue already, but couldn't find one).

Einops offers a string query to do common array operations. There's a good intro at https://github.com/arogozhnikov/einops/blob/master/docs/1-einops-basics.ipynb

The

Describe the solution you'd like

Because our dimension names are full names, it wouldn't be quite as terse, and it has lots of overlap with our existing operations. But I find string queries are often easy to understand, particularly for those who have less experience with xarray but are familiar with einsum & frends [^1].

Applying einops to xarray

The einops example, (no xarray yet):

python rearrange(ims, 'b h w c -> h (b w) c')

This could likely be something like, noting that we don't need the string before the ->, as our names are already defined:

python rearrange(ims, '-> height (batch width) color')

...or, if we wanted to name the new dimension rather than take an implicit dimension name like batch_width, at the cost of new einops syntax:

python rearrange(ims, '-> height width=(batch width) color')

...or if we wanted a method on a DataArray:

python ims.einops.rearrange('height width=(batch width) color')

Sometimes we would want the lvalue; e.g. to unstack:

python rearrange(ims, 'batch (height height2) color -> height (batch width) color', height2=2)

...and the same principles apply for reductions such as mean, for example

python ims.einops.reduce('-> height width color', 'mean')

...would be equivalent to:

```python ims.mean('batch')

or

ims.groupby(['height', 'width', 'color']).mean(...) ```

[^1]: I frequently find myself using .query, or pd.eval, also string queries, and these are great with tools that take user input and folks can pass a string

Describe alternatives you've considered

No response

Additional context

This probably needs a champion to drive, and realistically that's probably not me for quite a while. But if we can get consensus that this would be interesting, and someone is up for doing it, I think this could be a v cool feature.

I'll also tag @arogozhnikov for info

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/7295/reactions",
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed 13221727 issue

Links from other tables

  • 1 row from issues_id in issues_labels
  • 4 rows from issue in issue_comments
Powered by Datasette · Queries took 0.794ms · About: xarray-datasette