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

gh-236: make Result container not array subclass #237

Merged
merged 1 commit into from
Feb 13, 2025
Merged

gh-236: make Result container not array subclass #237

merged 1 commit into from
Feb 13, 2025

Conversation

ntessore
Copy link
Contributor

This changes the Result class to be a container holding an array, but not be an array subclass itself. Having it be an array subclass leads to problems such as #236.

The container forwards basic operations such as result[...], result.ndim, result.shape to the array (more could be added). So users can still do

# cl_sheshe is a result of shape (3, lmax + 1)
plt.plot(ell, cl_sheshe[0])  # plot EE spectrum

The result also has an __array__() method that returns the contained array in a numpy context, so this works even if result is no longer an array itself:

# any numpy function will do
np.multiply(result, 1)

@ntessore ntessore requested a review from JaimeRZP February 12, 2025 09:47
@ntessore ntessore linked an issue Feb 12, 2025 that may be closed by this pull request
Copy link
Contributor

@JaimeRZP JaimeRZP left a comment

Choose a reason for hiding this comment

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

LGTM

@JaimeRZP JaimeRZP merged commit 5b2b59e into main Feb 13, 2025
9 checks passed
@JaimeRZP JaimeRZP deleted the nt/236 branch February 13, 2025 10:11
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.

Result not always understood as array
2 participants