[SyneRBI/SIRF] get from buffer (#717)

3 views
Skip to first unread message

Richard Brown

unread,
Jun 12, 2020, 9:01:47 AM6/12/20
to SyneRBI/SIRF, Subscribed

Just an idea.

We can use numpy.frombuffer() to share data between C++ and python (e.g., for ProjDataInMemory). I think all that needs to be done is pass the address of begin to the python level. No idea how to do that with your wrapper, though, @evgueni-ovtchinnikov. Any ideas?


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

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

Commit Summary

  • get from buffer

File Changes

Patch Links:


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

Evgueni Ovtchinnikov

unread,
Jun 12, 2020, 11:23:16 AM6/12/20
to SyneRBI/SIRF, Subscribed

@evgueni-ovtchinnikov commented on this pull request.


In src/xSTIR/pSTIR/STIR.py.in:

> +            buffer = ?
+            try_calling(pystir.cSTIR_AcquisitionDataInMemory_get_buffer\
+                (self.handle, buffer))
+            array = numpy.frombuffer(buffer, dtype=numpy.float32)

I do not see how this can possibly work. However you define buffer, pystir.cSTIR_AcquisitionDataInMemory_get_buffer can only give you an address in memory, but numpy.frombuffer needs to know the size of memory represented by the buffer to be able to handle that memory as numpy array data.

Richard Brown

unread,
Jun 12, 2020, 12:37:16 PM6/12/20
to SyneRBI/SIRF, Subscribed

@rijobro commented on this pull request.


In src/xSTIR/pSTIR/STIR.py.in:

> +            buffer = ?
+            try_calling(pystir.cSTIR_AcquisitionDataInMemory_get_buffer\
+                (self.handle, buffer))
+            array = numpy.frombuffer(buffer, dtype=numpy.float32)

I haven't done it here, but you can give the number of elements with count:

numpy.frombuffer(buffer, dtype=float, count=-1, offset=0)

And obviously we know how many elements our sinogram contains.

Richard Brown

unread,
Jun 12, 2020, 12:40:04 PM6/12/20
to SyneRBI/SIRF, Subscribed

@rijobro commented on this pull request.


In src/xSTIR/pSTIR/STIR.py.in:

> +            buffer = ?
+            try_calling(pystir.cSTIR_AcquisitionDataInMemory_get_buffer\
+                (self.handle, buffer))
+            array = numpy.frombuffer(buffer, dtype=numpy.float32)

The problem is that the first argument to frombuffer should be of type buffer_like (see here). I have no idea how to do this, but the address to the first float in C++ somehow needs to be converted to this buffer_like object in Python. Searching online, it looks like it's possible with SWIG, but I'm not sure how to do it in SIRF's setup.

Kris Thielemans

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

Closed #717.


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/717/issue_event/23980047080@github.com>

Kris Thielemans

unread,
Mar 27, 2026, 1:32:52 PM (11 days ago) Mar 27
to SyneRBI/SIRF, Subscribed
KrisThielemans left a comment (SyneRBI/SIRF#717)

resolved by all our asarray() updates


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

Reply all
Reply to author
Forward
0 new messages