[SyneRBI/SIRF] sirf.Reg.ImageData.asarray() fix (PR #1376)

0 views
Skip to first unread message

Evgueni Ovtchinnikov

unread,
Feb 17, 2026, 12:05:37 PMFeb 17
to SyneRBI/SIRF, Subscribed

Changes in this pull request

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.

You can view, comment on, or merge this pull request online at:

  https://github.com/SyneRBI/SIRF/pull/1376

Commit Summary

File Changes

(5 files)

Patch Links:


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/pull/1376@github.com>

Kris Thielemans

unread,
Feb 17, 2026, 4:17:45 PMFeb 17
to SyneRBI/SIRF, Subscribed

@KrisThielemans requested changes on this pull request.

Need to say something about the Reg fix in CHANGES.md.

As the new functionality actually tested? As I don't think it's correct.

Also, in #1373 I suggested to duplicate tests with as_array() and asarray(), but maybe that isn't necessary.

Final comment, this is currently on top of #1373. Are we abandoning that one? The history here is rather awful, but a squash merge if the Reg fix and the algebra fix seems rather weird. Would then need some rebasing. Alternatively, we squash merge #1373 first, and then merge master here etc. No easy solutions... @casperdcl, we'll need your help I think.


In src/common/SIRF.py:

> @@ -141,6 +146,9 @@ def __sub__(self, other):
         '''
         return self.subtract(other)
 
+    def __rsub__(self, other):
+        return -other + self

I believe this is incorrect, as y.__rsub__(x) == x-y, so shouldn't it be -self + other?

I have no idea about overloads, but both implementations seem to first multiply with -1 and then add, which is normally wasteful. I guess if we have a constructor that doesn't do any work, we could do something like

try
    ret = self.allocate()
    ret.asarray() = other.asarray() - self.asarray()
    return ret
except someExceptionStuffHere:
    return -self + other

In src/common/SIRF.py:

> @@ -171,6 +179,9 @@ def __truediv__(self, other):
         '''
         return self.divide(other)
 
+    def __rtruediv__(self, other):
+        return other*self.power(-1)

similar comments as for __rsub__


In src/Registration/pReg/Reg.py:

> @@ -567,7 +567,14 @@ def __array_interface__(self):
         """As per https://numpy.org/doc/stable/reference/arrays.interface.html"""
         if not self.supports_array_view:
             raise ContiguousError("please make an array-copy first with `asarray(copy=True)` or `as_array()`")
-        return {'shape': self.shape, 'typestr': '<f4', 'version': 3,
+        shape = self.shape
+        dims = len(shape)
+        strides = ()
+        stride = 4

please add some comment on why this is the case


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/pull/1376/review/3816195032@github.com>

Evgueni Ovtchinnikov

unread,
Feb 18, 2026, 4:11:44 AMFeb 18
to SyneRBI/SIRF, Push

@evgueni-ovtchinnikov pushed 1 commit.

  • 608074e made corrections required by replacing as_array with asarray in data algebra tests


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/pull/1376/before/7ce286d6c259bec0d256fad98d5a60e8f5f26a78/after/608074e98154d13e1a7878ceddcb9137b452bdf2@github.com>

Evgueni Ovtchinnikov

unread,
Feb 18, 2026, 7:32:37 AMFeb 18
to SyneRBI/SIRF, Push

@evgueni-ovtchinnikov pushed 1 commit.

  • 1e65fb5 [ci skip] explained strides setting in sirf.Reg.ImageData.__array_interface__


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/pull/1376/before/608074e98154d13e1a7878ceddcb9137b452bdf2/after/1e65fb53c9305840c8d10fd0affcfb28e5223d31@github.com>

Evgueni Ovtchinnikov

unread,
Feb 18, 2026, 7:41:44 AMFeb 18
to SyneRBI/SIRF, Subscribed

@evgueni-ovtchinnikov commented on this pull request.


In src/common/SIRF.py:

> @@ -141,6 +146,9 @@ def __sub__(self, other):
         '''
         return self.subtract(other)
 
+    def __rsub__(self, other):
+        return -other + self

I believe this is incorrect, as y.__rsub__(x) == x-y, so shouldn't it be -self + other?

apparently not, otherwise respective data container algebra tests would fail (also in CIL, from which this approach was adopted)

ret.asarray() = other.asarray() - self.asarray()

would not work for MR data, I am afraid


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/pull/1376/review/3819694311@github.com>

Evgueni Ovtchinnikov

unread,
Feb 18, 2026, 7:42:59 AMFeb 18
to SyneRBI/SIRF, Subscribed

@evgueni-ovtchinnikov commented on this pull request.


In src/Registration/pReg/Reg.py:

> @@ -567,7 +567,14 @@ def __array_interface__(self):
         """As per https://numpy.org/doc/stable/reference/arrays.interface.html"""
         if not self.supports_array_view:
             raise ContiguousError("please make an array-copy first with `asarray(copy=True)` or `as_array()`")
-        return {'shape': self.shape, 'typestr': '<f4', 'version': 3,
+        shape = self.shape
+        dims = len(shape)
+        strides = ()
+        stride = 4

added here and in CHANGES.md


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/pull/1376/review/3819701531@github.com>

Evgueni Ovtchinnikov

unread,
Mar 12, 2026, 8:28:29 AMMar 12
to SyneRBI/SIRF, Subscribed
evgueni-ovtchinnikov left a comment (SyneRBI/SIRF#1376)

@KrisThielemans To clean up the history, I suggest we merge #1373 before #1376.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/pull/1376/c4046373823@github.com>

Evgueni Ovtchinnikov

unread,
Mar 26, 2026, 9:12:44 AM (12 days ago) Mar 26
to SyneRBI/SIRF, Push

@evgueni-ovtchinnikov pushed 4 commits.


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/pull/1376/before/1e65fb53c9305840c8d10fd0affcfb28e5223d31/after/ff2a60ba5f4a1874504b9d3a53fa1340f9ad156b@github.com>

Evgueni Ovtchinnikov

unread,
Mar 26, 2026, 9:28:29 AM (12 days ago) Mar 26
to SyneRBI/SIRF, Push

@evgueni-ovtchinnikov pushed 1 commit.


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/pull/1376/before/ff2a60ba5f4a1874504b9d3a53fa1340f9ad156b/after/6bce97520a27d424911129e7b223cd7c86e8cb7f@github.com>

Kris Thielemans

unread,
Mar 26, 2026, 9:39:31 AM (12 days ago) Mar 26
to SyneRBI/SIRF, Subscribed

@KrisThielemans commented on this pull request.


In src/Registration/pReg/Reg.py:

> +        """NiftiImageData stores voxels values in a 3D Fortran-style array,
+        hence strides need to be arranged accordingly (default is C-style)."""

Codacy complains because of a string. I guess you intended this as a docstring, in which case it would have be moved up. However, I think it's fine to just have it as a comment (no string).


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/pull/1376/review/4014245816@github.com>

Evgueni Ovtchinnikov

unread,
Mar 26, 2026, 9:44:23 AM (12 days ago) Mar 26
to SyneRBI/SIRF, Push

@evgueni-ovtchinnikov pushed 1 commit.

  • 0ab9500 Merge branch 'master' into reg-asarray-fix


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/pull/1376/before/6bce97520a27d424911129e7b223cd7c86e8cb7f/after/0ab9500d2b1be25b65b6c04950c6ebc2b0fa5ef9@github.com>

Kris Thielemans

unread,
Mar 26, 2026, 9:47:06 AM (12 days ago) Mar 26
to SyneRBI/SIRF, Subscribed
KrisThielemans left a comment (SyneRBI/SIRF#1376)

ok, this is now a very small PR. Great! Once ready, please use squash-merge.

Question: is the output of the old as_array() and new asarray() (and presumably therefore new as_array(), as you're testing that) the same? (i.e. do they use the same order). I guess so, as you haven't touched Reg.ImageData.as_array(), which is currently
https://github.com/SyneRBI/SIRF/blob/24483dc77942a5ac683b8d55809a43c7b8862a7b/src/Registration/pReg/Reg.py#L372

We cannot change that, as otherwise, we'll get into trouble with the registration tools and geometry.

This does explain some choices that Richard made in the geometric info code (which don't work for STIR, but that's another PR)


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/pull/1376/c4134970970@github.com>

Evgueni Ovtchinnikov

unread,
Mar 26, 2026, 12:47:56 PM (12 days ago) Mar 26
to SyneRBI/SIRF, Subscribed
evgueni-ovtchinnikov left a comment (SyneRBI/SIRF#1376)

yes, as_array returns the same data as asarray

@KrisThielemans please approve, I cannot merge until you approve


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/pull/1376/c4136543871@github.com>

Kris Thielemans

unread,
Mar 26, 2026, 7:02:53 PM (11 days ago) Mar 26
to SyneRBI/SIRF, Subscribed

@KrisThielemans commented on this pull request.


In src/Registration/pReg/Reg.py:

> +        """NiftiImageData stores voxels values in a 3D Fortran-style array,
+        hence strides need to be arranged accordingly (default is C-style)."""
⬇️ Suggested change
-        """NiftiImageData stores voxels values in a 3D Fortran-style array,
-        hence strides need to be arranged accordingly (default is C-style)."""
+        # NiftiImageData stores voxels values in a 3D Fortran-style array,
+        # hence strides need to be arranged accordingly (default is C-style).


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/pull/1376/review/4017906927@github.com>

Kris Thielemans

unread,
Mar 26, 2026, 7:03:37 PM (11 days ago) Mar 26
to SyneRBI/SIRF, Push

@KrisThielemans pushed 1 commit.

  • 0c7707c Replace string with comment


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/pull/1376/before/0ab9500d2b1be25b65b6c04950c6ebc2b0fa5ef9/after/0c7707c957e582d206d024b689c8be1d9501acdc@github.com>

Kris Thielemans

unread,
Mar 26, 2026, 7:10:28 PM (11 days ago) Mar 26
to SyneRBI/SIRF, Subscribed

@KrisThielemans requested changes on this pull request.

All fine, except that CHANGES.md was based on an old version, so you lost some lines.


In CHANGES.md:

> @@ -4,13 +4,10 @@
 
 * SIRF/STIR
   - The implementation of the creation of `sirf.STIR.ImageData` from `sirf.STIR.AcquisitionData` has been revised to ensure compatibility of `ImageData` dimensions and voxel sizes with `AcquisitionData`.
-  - Missing `__del__` added to sirf.STIR.AcquisitionModel.
+* SIR/Registration
⬇️ Suggested change
-* SIR/Registration
+* SIRF/Registration

However, was Reg.ImageData.__array_interface__ already in 3.9.0? If not, this comment should just say that we added it.


In CHANGES.md:

> @@ -4,13 +4,10 @@
 
 * SIRF/STIR
   - The implementation of the creation of `sirf.STIR.ImageData` from `sirf.STIR.AcquisitionData` has been revised to ensure compatibility of `ImageData` dimensions and voxel sizes with `AcquisitionData`.
-  - Missing `__del__` added to sirf.STIR.AcquisitionModel.

seems this line shouldn't have been deleted. (Note the wrong - - though)


In CHANGES.md:

> -  - Error raised if `AcquisitionModel.adjoint` ran when the model is not linear.
-* SIRF
-  - `common/SIRF.py` adding adjoint operator

should not have been deleted


In CHANGES.md:

> @@ -30,8 +27,6 @@
   - Error raised in `AcquisitionSensitivityModel.[un]normalise` methods applied to a read-only object.
   - SIRF interfaces (C++ and Python) for STIR Poisson noise generation utilities provided.
   - Python:
-    - allow in-place call of `ObjectiveFunction` `gradient` in Python. Added unit test for new functionality in `gradient` and for the `out` parameter.

should not have been deleted


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/pull/1376/review/4017924128@github.com>

Evgueni Ovtchinnikov

unread,
Mar 27, 2026, 7:58:07 AM (11 days ago) Mar 27
to SyneRBI/SIRF, Push

@evgueni-ovtchinnikov pushed 3 commits.


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/pull/1376/before/0c7707c957e582d206d024b689c8be1d9501acdc/after/df9feae027bfbf810c490ae91f52a53a6713a92c@github.com>

Evgueni Ovtchinnikov

unread,
Mar 27, 2026, 8:02:02 AM (11 days ago) Mar 27
to SyneRBI/SIRF, Subscribed

@evgueni-ovtchinnikov commented on this pull request.


In CHANGES.md:

> -  - Error raised if `AcquisitionModel.adjoint` ran when the model is not linear.
-* SIRF
-  - `common/SIRF.py` adding adjoint operator

restored, rephrased


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/pull/1376/review/4020708496@github.com>

Evgueni Ovtchinnikov

unread,
Mar 27, 2026, 8:39:55 AM (11 days ago) Mar 27
to SyneRBI/SIRF, Subscribed

@evgueni-ovtchinnikov commented on this pull request.


In CHANGES.md:

> @@ -4,13 +4,10 @@
 
 * SIRF/STIR
   - The implementation of the creation of `sirf.STIR.ImageData` from `sirf.STIR.AcquisitionData` has been revised to ensure compatibility of `ImageData` dimensions and voxel sizes with `AcquisitionData`.
-  - Missing `__del__` added to sirf.STIR.AcquisitionModel.
+* SIR/Registration

Yes, it was added 9 month ago, and 3.9.0 was released in Oct 2025.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/pull/1376/review/4020901439@github.com>

Evgueni Ovtchinnikov

unread,
Mar 27, 2026, 8:40:42 AM (11 days ago) Mar 27
to SyneRBI/SIRF, Subscribed

@evgueni-ovtchinnikov commented on this pull request.


In CHANGES.md:

> @@ -4,13 +4,10 @@
 
 * SIRF/STIR
   - The implementation of the creation of `sirf.STIR.ImageData` from `sirf.STIR.AcquisitionData` has been revised to ensure compatibility of `ImageData` dimensions and voxel sizes with `AcquisitionData`.
-  - Missing `__del__` added to sirf.STIR.AcquisitionModel.

restored


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/pull/1376/review/4020906743@github.com>

Evgueni Ovtchinnikov

unread,
Mar 27, 2026, 8:41:00 AM (11 days ago) Mar 27
to SyneRBI/SIRF, Subscribed

@evgueni-ovtchinnikov commented on this pull request.


In CHANGES.md:

> @@ -30,8 +27,6 @@
   - Error raised in `AcquisitionSensitivityModel.[un]normalise` methods applied to a read-only object.
   - SIRF interfaces (C++ and Python) for STIR Poisson noise generation utilities provided.
   - Python:
-    - allow in-place call of `ObjectiveFunction` `gradient` in Python. Added unit test for new functionality in `gradient` and for the `out` parameter.

restored


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/pull/1376/review/4020908546@github.com>

Kris Thielemans

unread,
Mar 27, 2026, 10:38:49 AM (11 days ago) Mar 27
to SyneRBI/SIRF, Subscribed

@KrisThielemans commented on this pull request.


In CHANGES.md:

>    - Error raised if `AcquisitionModel.adjoint` ran when the model is not linear.
-* SIRF
-  - `common/SIRF.py` adding adjoint operator
-  - addition of initial pytorch wrappers and examples, check `torch/README.md`

This (important!) line still disappeared!


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/pull/1376/review/4021633965@github.com>

Evgueni Ovtchinnikov

unread,
Mar 27, 2026, 1:04:37 PM (11 days ago) Mar 27
to SyneRBI/SIRF, Push

@evgueni-ovtchinnikov pushed 1 commit.

  • eb7d1de [ci skip] restored the last (hopefully) couple of lines in CHANGES.md


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/pull/1376/before/df9feae027bfbf810c490ae91f52a53a6713a92c/after/eb7d1de2eb2a3c5dfa197effa1372c2fba0d8cd7@github.com>

Evgueni Ovtchinnikov

unread,
Mar 27, 2026, 1:15:40 PM (11 days ago) Mar 27
to SyneRBI/SIRF, Subscribed

@evgueni-ovtchinnikov commented on this pull request.


In CHANGES.md:

>    - Error raised if `AcquisitionModel.adjoint` ran when the model is not linear.
-* SIRF
-  - `common/SIRF.py` adding adjoint operator
-  - addition of initial pytorch wrappers and examples, check `torch/README.md`

restored (according to Files changed)


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/pull/1376/review/4022557365@github.com>

Evgueni Ovtchinnikov

unread,
Mar 27, 2026, 1:18:35 PM (11 days ago) Mar 27
to SyneRBI/SIRF, Push

@evgueni-ovtchinnikov pushed 1 commit.

  • 5f4e227 Merge branch 'master' into reg-asarray-fix


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/pull/1376/before/eb7d1de2eb2a3c5dfa197effa1372c2fba0d8cd7/after/5f4e227afa007afe642bb193ab86dccbae87f8e2@github.com>

Kris Thielemans

unread,
Mar 27, 2026, 1:30:07 PM (11 days ago) Mar 27
to SyneRBI/SIRF, Subscribed

@KrisThielemans approved this pull request.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/pull/1376/review/4022629905@github.com>

Kris Thielemans

unread,
Mar 27, 2026, 1:31:23 PM (11 days ago) Mar 27
to SyneRBI/SIRF, Subscribed

Merged #1376 into master.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/pull/1376/issue_event/23980007603@github.com>

Reply all
Reply to author
Forward
0 new messages