GalSim icon indicating copy to clipboard operation
GalSim copied to clipboard

Construct images without sanity checks in `_convertMask` function in the HSM module

Open arunkannawadi opened this issue 2 years ago • 4 comments

When measuring the moments using FindAdaptiveMom, I find that a significant chunk of time is taken by the _convertMask function, which arises from various Image instantiations. Given that this is an internal function, I expect that the inputs provided to create an Image instance would always pass these checks and can directly use the _Image.

For reference, 38 out of 186 seconds is spend in _convertMask when calling FindAdaptiveMom.

arunkannawadi avatar Dec 05 '23 15:12 arunkannawadi

I think the main thing is probably that there are a couple of checks currently that the mask is sane (no negative values and not all zero). So probably adding an option to skip those will speed this up a lot.

rmjarvis avatar Dec 05 '23 15:12 rmjarvis

Probably simplest would be to add a leading underscore version of this _FindAdaptiveMom that skips all the sanity checks and requires that object_image and weight are already the right dtype and everything.

rmjarvis avatar Dec 05 '23 15:12 rmjarvis

That sounds like the least disruptive approach to me (not saying that modifying _convertMask would have been), but I could see a user potentially calling FindAdaptiveMom with inconsistent inputs. I'm happy to code this up, quantify the performance improvements and raise a PR here.

arunkannawadi avatar Dec 05 '23 15:12 arunkannawadi

An additional public interface to observed_e1 and observed_e2 would also be nice. And the current return for observed_shape should probably use the optimized _Shape rather than Shape.

erykoff avatar Dec 06 '23 23:12 erykoff

Closing this issue as completed.

arunkannawadi avatar Mar 30 '24 23:03 arunkannawadi