Skip to content

Updates for mixed data algebra based on __array_priority__.#1373

Merged
evgueni-ovtchinnikov merged 18 commits intomasterfrom
mda-priority-fix
Mar 12, 2026
Merged

Updates for mixed data algebra based on __array_priority__.#1373
evgueni-ovtchinnikov merged 18 commits intomasterfrom
mda-priority-fix

Conversation

@evgueni-ovtchinnikov
Copy link
Copy Markdown
Contributor

@evgueni-ovtchinnikov evgueni-ovtchinnikov commented Feb 10, 2026

Changes in this pull request

Replaces quick fix in #1357 with a proper fix employing __array_priority__ feature and adds more mixed algebra tests.

Testing performed

Related issues

Checklist before requesting a review

  • I have performed a self-review of my code
  • I have added docstrings/doxygen in line with the guidance in the developer guide
  • I have implemented unit tests that cover any new or modified functionality
  • The code builds and runs on my machine
  • CHANGES.md has been updated with any functionality change

Contribution Notes

Please read and adhere to the contribution guidelines.

Please tick the following:

  • The content of this Pull Request (the Contribution) is intentionally submitted for inclusion in SIRF (the Work) under the terms and conditions of the Apache-2.0 License.

Copy link
Copy Markdown
Member

@KrisThielemans KrisThielemans left a comment

Choose a reason for hiding this comment

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

As I don't know anything about __array_priority__, I'll leave it to @paskino and @casperdcl to review.

BTW, what happens if the sizes are wrong? Shouldn't we add some check?

This will have to be squash merged (after modifying CHANGES and the user's guide appropriately), due to the somewhat horrible history.

test.check_if_zero_within_tolerance(s, eps * t)

z = ay*x
az = z.as_array()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

are we sure we really want to use as_array() for these tests? Obviously, if replacing it with asarray() we'd have to be very careful for any operatoins that modify the object.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

better safe than sorry IMHO

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

BTW, what happens if the sizes are wrong?

assert_validities would raise AssertionError

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

better safe than sorry IMHO

not necessarily for tests. Probably a good idea to do at least some of the tests with asarray() as well, as the future, it's what is must likely to hit us.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually, replacing every as_array use with that of asarray is perfectly safe as asarray defaults to copy - to get a view, you need asarray(copy=False) (we probably should keep as_array method in our data container classes for backward compatibility). However, this needs a separate PR I believe, this one just fixes #1357.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

asarray defaults to copy

no it doesn't. it defaults to view (if the container supports it).

Whatever, I still feel we need to test with the most used function, even if you know in the end it gives the same results (but at some point, it might not)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

deleting as_array will break compatibility with CIL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

backwards incompatibility: algebraic operations with numpy arrays/scalars on the "left" return a numpy array

4 participants