Open KrisThielemans opened 4 years ago
ProjData::fill_from and ProjData::copy_to use explicit loops with SegmentByView etc. This is slow.
ProjData::fill_from
ProjData::copy_to
SegmentByView
For ProjDataInMemory we should be able to directly copy via the iterator from/to the buffer. This would currently not work however, as the segments are stored in the wrong order: fill_from and copy_to use order {0,1,-1,2,-2,...}. ProjDataInMemory uses the default order of ProjDataFromStream https://github.com/UCL/STIR/blob/29133a3ffa690b444894b4392aa710e8bb33a42e/src/buildblock/ProjDataFromStream.cxx#L114-L122 which is {....,-2,-1,0,1,2,...}. It seems to me that we should change the constructors https://github.com/UCL/STIR/blob/29133a3ffa690b444894b4392aa710e8bb33a42e/src/buildblock/ProjDataInMemory.cxx#L104-L105 and https://github.com/UCL/STIR/blob/29133a3ffa690b444894b4392aa710e8bb33a42e/src/buildblock/ProjDataInMemory.cxx#L115-L117 to use the {0,1,-1,...} sequence. We can do that by either:
ProjDataInMemory
fill_from
copy_to
{0,1,-1,2,-2,...}
ProjDataFromStream
{....,-2,-1,0,1,2,...}
{0,1,-1,...}
std::vector
{0,-1,1,...}
Doing this should speed-up SWIG's to_numpy and SIRF's as_array as it calls copy_to here.
to_numpy
as_array
We should expose the ProjDataInMemory iterators. That should be easy: copy lines from https://github.com/UCL/STIR/blob/7dc238f5ec228554f594f1f2228450eb4618472b/src/swig/stir.i#L1149-L1153
to_numpy for ProjData first creates a Array<3,float> https://github.com/UCL/STIR/blob/7dc238f5ec228554f594f1f2228450eb4618472b/src/swig/stirextra.py#L81-82 and then converts to numpy array. If we'd add a shape() to ProjDataInMemory, I believe that the "normal" lines will work already: https://github.com/UCL/STIR/blob/7dc238f5ec228554f594f1f2228450eb4618472b/src/swig/stirextra.py#L75-L77 However, probably Python won't do that if it's passed a ProjData object (even if it's ProjDataInMemory), so possibly we'd have to do a type-cast somehow.
ProjData
Array<3,float>
numpy
shape()
PR coming
Everything above except the last item (creating an Array first in SWIG) was addressed in #612
Array
C++
ProjData::fill_from
andProjData::copy_to
use explicit loops withSegmentByView
etc. This is slow.For
ProjDataInMemory
we should be able to directly copy via the iterator from/to the buffer. This would currently not work however, as the segments are stored in the wrong order:fill_from
andcopy_to
use order{0,1,-1,2,-2,...}
.ProjDataInMemory
uses the default order ofProjDataFromStream
https://github.com/UCL/STIR/blob/29133a3ffa690b444894b4392aa710e8bb33a42e/src/buildblock/ProjDataFromStream.cxx#L114-L122 which is{....,-2,-1,0,1,2,...}
. It seems to me that we should change the constructors https://github.com/UCL/STIR/blob/29133a3ffa690b444894b4392aa710e8bb33a42e/src/buildblock/ProjDataInMemory.cxx#L104-L105 and https://github.com/UCL/STIR/blob/29133a3ffa690b444894b4392aa710e8bb33a42e/src/buildblock/ProjDataInMemory.cxx#L115-L117 to use the{0,1,-1,...}
sequence. We can do that by either:ProjDataFromStream
. probably not a bad idea, but dangerous to rely on a defaultstd::vector
with that sequence (can steal code from https://github.com/UCL/STIR/blob/7dc238f5ec228554f594f1f2228450eb4618472b/src/IO/stir_ecat_common.cxx#L193, but note that this uses{0,-1,1,...}
).Doing this should speed-up SWIG's
to_numpy
and SIRF'sas_array
as it callscopy_to
here.SWIG
We should expose the
ProjDataInMemory
iterators. That should be easy: copy lines from https://github.com/UCL/STIR/blob/7dc238f5ec228554f594f1f2228450eb4618472b/src/swig/stir.i#L1149-L1153to_numpy
forProjData
first creates aArray<3,float>
https://github.com/UCL/STIR/blob/7dc238f5ec228554f594f1f2228450eb4618472b/src/swig/stirextra.py#L81-82 and then converts tonumpy
array. If we'd add ashape()
toProjDataInMemory
, I believe that the "normal" lines will work already: https://github.com/UCL/STIR/blob/7dc238f5ec228554f594f1f2228450eb4618472b/src/swig/stirextra.py#L75-L77 However, probably Python won't do that if it's passed aProjData
object (even if it'sProjDataInMemory
), so possibly we'd have to do a type-cast somehow.