-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added optional argument out in all gradient-computing methods #1246
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would work, and we can merge as-is.
However, it doesn't really provide an optimisation for the user. For instance, checking
SIRF/src/xSTIR/cSTIR/cstir.cpp
Lines 1246 to 1252 in 2c66faf
Prior3DF& prior = objectFromHandle<Prior3DF>(ptr_p); | |
STIRImageData& id = objectFromHandle<STIRImageData>(ptr_i); | |
Image3DF& image = id.data(); | |
shared_ptr<STIRImageData> sptr(new STIRImageData(image)); | |
Image3DF& grad = sptr->data(); | |
prior.compute_gradient(grad, image); | |
return newObjectHandle(sptr); |
we will be creating a new image, then filling
out
with its content. Better would be to directly call STIR's compute_gradient
with the out
image. This could possibly be done like this
if out is None:
out = ImageData()
grad.handle = pystir.cSTIR_priorGradient(self.handle, image.handle, out.handle)
check_status(grad.handle)
return out
accompanied by a check in the wrapper if the handle points to an "empty" image and if so, create a new one. Easy?
By the way, shared_ptr<STIRImageData> sptr(new STIRImageData(image));
creates a copy, while actually we only need a zero image, which would be faster to construct. Do we have get_uniform_copy(0)
or similar on the C++ side?
I fixed it this way:
|
How does this remove the copy? The C function will still do the fill into a temporary object (as it doesn't get the grad handle)? |
I got rid of |
I might misunderstand the handle details, but as far as I can see
gets essentially rid of any allocated memory that SIRF/src/xSTIR/cSTIR/cstir.cpp Line 1249 in 2c66faf
still has allocation of a new object, as opposed to reusing whatever was in out .
So, while this doesn't have the |
ok, see your point now, thanks! trying this now:
not sure I could manage to avoid copies with |
can't check right now, but unfortunate to have the duplication. Cannot pass 0 or an empty handle (or default constructed one)? we do need a test though. |
Something like
Of course, there's large scope for using |
|
Thanks! Please create an issue such that we don't forget to add tests, as well as reduce code duplication. |
Changes in this pull request
Added optional argument
out
in all gradient-computing methods for compatibility with CIL.Testing performed
Related issues
Fixes #1242.
Checklist before requesting a review
Contribution Notes
Please read and adhere to the contribution guidelines.
Please tick the following: