[SyneRBI/SIRF] Extends SIRF data algebra possible operands to numpy arrays (PR #1358)

10 views
Skip to first unread message

Evgueni Ovtchinnikov

unread,
Nov 17, 2025, 12:56:39 PM11/17/25
to SyneRBI/SIRF, Subscribed

Changes in this pull request

Testing performed

Related issues

fixes #1357

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/1358

Commit Summary

File Changes

(1Ā file)

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/1358@github.com>

Kris Thielemans

unread,
Nov 18, 2025, 10:24:25 AM11/18/25
to SyneRBI/SIRF, Subscribed

@KrisThielemans requested changes on this pull request.

clone() will make a copy, which fill will then change again. I assume using get_uniform_copy() will be a bit faster as it avoids reading the data. Or do we have an allocator/constructor that doesn't initialise the data at all?

—
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/1358/review/3478379124@github.com>

Evgueni Ovtchinnikov

unread,
Nov 18, 2025, 12:25:07 PM11/18/25
to SyneRBI/SIRF, Subscribed
evgueni-ovtchinnikov left a comment (SyneRBI/SIRF#1358)

Actually, get_uniform_copy cannot be any faster as it calls clone to make a copy and then fills it with the specified value:

    def get_uniform_copy(self, value=1.0):
        '''Initialises an instance of DataContainer based on the template'''
        y = self.clone() # SIRF uses `DiscretisedDensity.clone()` to make a copy of `self` data
        y.fill(value)
        return y

—
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/1358/c3548759694@github.com>

Kris Thielemans

unread,
Nov 18, 2025, 1:05:42 PM11/18/25
to SyneRBI/SIRF, Subscribed
KrisThielemans left a comment (SyneRBI/SIRF#1358)

ah. :-)

—
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/1358/c3548923772@github.com>

Kris Thielemans

unread,
Nov 18, 2025, 1:06:49 PM11/18/25
to SyneRBI/SIRF, Subscribed
KrisThielemans left a comment (SyneRBI/SIRF#1358)

unrelated HDF5 linking error

—
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/1358/c3548928919@github.com>

Kris Thielemans

unread,
Nov 18, 2025, 1:08:05 PM11/18/25
to SyneRBI/SIRF, Subscribed

@KrisThielemans approved this pull request.

Before merging, can you add a line to CHANGES.md? ("Restored functionality for algebraic operations mixing STIR.ImageData and numpy arrays." or something like that.)

—
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/1358/review/3479119656@github.com>

Edoardo Pasca

unread,
Nov 20, 2025, 5:35:06 AM11/20/25
to SyneRBI/SIRF, Subscribed
paskino left a comment (SyneRBI/SIRF#1358)

I'll test with MaGeZ as soon as I can.

—
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/1358/c3557174660@github.com>

Edoardo Pasca

unread,
Nov 21, 2025, 12:06:42 PM11/21/25
to SyneRBI/SIRF, Subscribed

@paskino commented on this pull request.


In src/xSTIR/pSTIR/STIR.py:

> @@ -625,6 +625,56 @@ def as_array(self):
         try_calling(pystir.cSTIR_getImageData(self.handle, array.ctypes.data))
         return array
 
+    def dot(self, other):
+        '''
+        Returns the dot product of the container data with another container
+        data or numpy array viewed as vectors.
+        other: DataContainer
+        '''
+        if not (issubclass(type(other), type(self))):
+            other = self.clone().fill(other)

This sounds like a bad idea. It will double the memory usage.

—
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/1358/review/3493661495@github.com>

Evgueni Ovtchinnikov

unread,
Nov 24, 2025, 6:04:58 AM11/24/25
to SyneRBI/SIRF, Push

@evgueni-ovtchinnikov pushed 2 commits.

  • c53d80b added to User Guide a subsection on SIRF/numpy data algebra peculiarities [ci skip]
  • 9f2ecf8 updated CHANGES.md [ci skip]

—
View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/pull/1358/before/a164114f5683154e838a10b16043b68855f7cd91/after/9f2ecf8ad39b98f2b80301d501fc1c45ff74a2bd@github.com>

Kris Thielemans

unread,
Nov 24, 2025, 1:31:25 PM11/24/25
to SyneRBI/SIRF, Subscribed

@KrisThielemans commented on this pull request.


In src/xSTIR/pSTIR/STIR.py:

> @@ -625,6 +625,56 @@ def as_array(self):
         try_calling(pystir.cSTIR_getImageData(self.handle, array.ctypes.data))
         return array
 
+    def dot(self, other):
+        '''
+        Returns the dot product of the container data with another container
+        data or numpy array viewed as vectors.
+        other: DataContainer
+        '''
+        if not (issubclass(type(other), type(self))):
+            other = self.clone().fill(other)

yes, but it seems we have no alternative at the moment.

—
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/1358/review/3501713374@github.com>

Kris Thielemans

unread,
Nov 24, 2025, 1:31:59 PM11/24/25
to SyneRBI/SIRF, Subscribed

@KrisThielemans approved this pull request.

I'm fine with the doc. I'd still prefer to have a test before we merge though.

—
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/1358/review/3501715101@github.com>

Evgueni Ovtchinnikov

unread,
Nov 25, 2025, 12:07:35 PM11/25/25
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/1358/before/9f2ecf8ad39b98f2b80301d501fc1c45ff74a2bd/after/80b3c0767eef65029abe9e9f4b42c6568aa19d88@github.com>

Evgueni Ovtchinnikov

unread,
Nov 25, 2025, 1:06:34 PM11/25/25
to SyneRBI/SIRF, Push

@evgueni-ovtchinnikov pushed 1 commit.

  • 57d9e15 attended to Codacy issues

—
View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/pull/1358/before/80b3c0767eef65029abe9e9f4b42c6568aa19d88/after/57d9e157fd32626dd597d3f87aff3444a4dc8090@github.com>

Kris Thielemans

unread,
Nov 25, 2025, 3:22:09 PM11/25/25
to SyneRBI/SIRF, Subscribed

@KrisThielemans commented on this pull request.


In src/xGadgetron/pGadgetron/Gadgetron.py:

> @@ -437,6 +437,56 @@ def get_ISMRMRD_info(self, par):
     def get_info(self, par):
         return self.get_ISMRMRD_info(par)
 
+    def dot(self, other):
+        '''
+        Returns the dot product of the container data with another container
+        data or numpy array viewed as vectors.
+        other: ImageData or numpy array or scalar
+        '''
+        if not (issubclass(type(other), type(self))):
+            other = self.clone().fill(other)
+        return super(ImageData, self).dot(other)

according to doc, since Python 3.0, you can write

ā¬‡ļø Suggested change
-        return super(ImageData, self).dot(other)
+        return super().dot(other)

which is a nicer, and in fact seems to say that we can write this only once somewhere, as opposed to for Gadgetron/STIR/Reg etc. No idea how to do that though.

—
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/1358/review/3506681258@github.com>

Evgueni Ovtchinnikov

unread,
Nov 27, 2025, 10:01:16 AM11/27/25
to SyneRBI/SIRF, Push

@evgueni-ovtchinnikov pushed 1 commit.

  • 0477cc0 simpliied mixed data algebra

—
View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <SyneRBI/SIRF/pull/1358/before/57d9e157fd32626dd597d3f87aff3444a4dc8090/after/0477cc06e0f6a6384f1dcea6620c61e647cdc584@github.com>

Reply all
Reply to author
Forward
0 new messages