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

Implementation of std and var. #327

Closed
wants to merge 3 commits into from
Closed

Implementation of std and var. #327

wants to merge 3 commits into from

Conversation

alxmrs
Copy link
Contributor

@alxmrs alxmrs commented Nov 21, 2023

Fixes #29. Here, I use existing cubed operations to implement var and std. Please let me know if I should reimplement the primitives as pure reductions.

cubed/array_api/__init__.py Outdated Show resolved Hide resolved
@tomwhite
Copy link
Member

Thank you for submitting a PR for this @alxmrs!

Please let me know if I should reimplement the primitives as pure reductions.

That's how I envisaged doing this (similar to Dask). The way you have it at the moment has two separate reductions which will be less efficient than one (and reductions in Cubed are quite inefficient at the moment, something we want to remedy in e.g. #284). Also I'm not sure if there are any differences in numerical stability between the two approaches.

@tomwhite
Copy link
Member

It would be good to get std/var into Cubed. I found an implementation that we could try here (see #29 (comment)) - would you be interested in having a go at that @alxmrs?

I wonder whether we should merge this in the meantime though?

@@ -152,3 +153,12 @@ def sum(x, /, *, axis=None, dtype=None, keepdims=False):
keepdims=keepdims,
extra_func_kwargs=extra_func_kwargs,
)


def var(x, /, *, axis=None, keepdims=False):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't match the signature in the specification since it's missing a correction parameter. Similarly for std.

@@ -563,6 +563,74 @@ def test_sum_axis_0(spec, executor):
assert_array_equal(b.compute(executor=executor), np.array([12, 15, 18]))


def test_var(spec, executor):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you parameterize all these tests for var for different axes, and for keepdims? There are other tests in the test suite that do this.

@alxmrs
Copy link
Contributor Author

alxmrs commented Sep 24, 2024 via email

@tomwhite
Copy link
Member

Thanks Alex - that sounds like a good plan!

(Sorry I didn't suggest how to move forward on this before - you weren't blocking me!)

alxmrs and others added 3 commits September 26, 2024 22:21
Fixes cubed-dev#29. Here, I use existing cubed operations to implement `var` and `std`. Please let me know if I should reimplement the primitives as pure reductions.
@tomwhite
Copy link
Member

Fixed in #596

@tomwhite tomwhite closed this Oct 29, 2024
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

Successfully merging this pull request may close these issues.

Implement var and std
2 participants