add Array operator+ etc in C++ and Python, fix += in Python#1630
add Array operator+ etc in C++ and Python, fix += in Python#1630KrisThielemans merged 7 commits intoUCL:masterfrom
Conversation
Explicitly add operator+, operator+= in Array. This overrides the base-class implementations with functions that have the correct return type. This avoids surprising problems in python as well. In addition, we work around swig/swig#2634 by using %ignore all operator +=. This avoids a crash, but in fact allows Python to fall back to operator+. This might be a bit slow, but it does work. Added testing both in C++ and Python.
Let SWIG ignore VectorWithOffset/Array constructors that don't make sense to wrap, avoiding warnings.
Work around a SWIG bug by ignoring += (as that crashed). Python now auto-generates += in terms of +. That might be slower, but it works.
|
This isn't quite ready yet, as we need the same for |
- introduce type traits such as has_iterator<T> - use those to write assign() much more generically, independent STIR/std classes
As per previous changes for Array. WARNING: breaks backward compatibility for VoxelsOnCartesianGrid::operator-= and operator- when the lhs has smaller size than the rhs. Previously, behaviour was equivalent to first calling grow. Now it calls error().
|
@markus-jehl @danieldeidda @NikEfth this is now ready. We can now do fun things in python like with arrays, images and I'm hoping to merge this soon (if tests are ok!), so let me know if you want to check. There's some fancy C++ with type traits going on to get the
|
bin is a built-in object, so call our variable _bin
|
Additional "release notes"
|
|
Just tested it in python and it works very well - really nice feature! |
danieldeidda
left a comment
There was a problem hiding this comment.
nice thanks! so should I update the recon demo with this then?
[ci skip]
yes please. Merge |
|
What about multiplication? |
|
Should be available |
Summary: operator+, += etc now work as expected for
ArrayandProjDataInMemoryfor both C++ and PythonC++
Array::operator+etc explicitly, returning anArrayobject, whereas before it would return aNumericVectorWithOffsetobjectSWIG/Python
Array + ArrayandArray + numbernow also returns anArray(and same forVoxelsOnCartesianGrid)Array += Array,ProjDataInMemory += ProjDataInMemoryetc now works fine.Fixes #863