Skip to content

Implement vnorm for xarray with dask support #735

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

Closed
deanpospisil opened this issue Jan 30, 2016 · 4 comments
Closed

Implement vnorm for xarray with dask support #735

deanpospisil opened this issue Jan 30, 2016 · 4 comments
Labels

Comments

@deanpospisil
Copy link

Similarly to #723 I'd like to see if I can port vnorm from Dask into xarray. This a useful quick operation to have handy for linear models.
Previously as I work around I tried:
n = da.reduce(np.linalg.norm, ['shapes', 'x'] )
but it quickly explodes (eats up all ram) for large DaskArrays

@shoyer
Copy link
Member

shoyer commented Jan 30, 2016

I would be OK adding a norm method, although I don't think there's a super strong need for it -- usually I've been happy writing expressions like (x ** 2).sum(['shapes', 'x']) ** 0.5 instead.

You would either need to implement this all in xarray, or preferably write da.linalg.norm in dask and use that take. Take a look at the scipy source code for this function -- I suspect you could port this almost directly to dask.

@deanpospisil
Copy link
Author

Note I mis-typed vecnorm instead of vnorm previously.

I would be OK adding a norm method, although I don't think there's a super strong need for it -- usually I've been happy writing expressions like (x ** 2).sum(['shapes', 'x']) ** 0.5 instead.

When using large dask arrays that operation tended to fill up ram. I'm not sure why, but it made the dask objects very large, I don't have a good understanding of how those graphs are constructed so I was unable to track down the problem.

I tried out da.std(['shapes', 'x']) and it worked like a charm, but it felt a little silly rescaling it to get the norm.

You would either need to implement this all in xarray, or preferably write da.linalg.norm in dask and use that take. Take a look at the scipy source code for this function -- I suspect you could port this almost directly to dask.

dask has a vnorm,
http://dask.pydata.org/en/latest/array-api.html?highlight=norm#dask.array.core.Array.vnorm
which I am currently trying to make use of, using the very helpful:
ops._dask_or_eager_func('vnorm', n_array_args=1)
unfortunately numpy calls their norm norm as opposed to vnorm so I think I'll need to put in a switch depending on the array type before hitting _dask_or_eager_func

@deanpospisil deanpospisil changed the title Implement vecnorm for xarray with dask support Implement vnorm for xarray with dask support Jan 30, 2016
@shoyer
Copy link
Member

shoyer commented Jan 31, 2016

Looks like it would be worth writing a cross-compatible vnorm in xarray/core/ops.py. Take a look at that module for examples of how we wrote custom wrapper -- this should be pretty straightforward

@stale
Copy link

stale bot commented Jan 29, 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; otherwise it will be marked as closed automatically

@stale stale bot added the stale label Jan 29, 2019
@stale stale bot closed this as completed Feb 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants