simonsobs / pixell

A rectangular pixel map manipulation and harmonic analysis library derived from Sigurd Naess' enlib.
Other
42 stars 32 forks source link

Force numpy arrays to Allreduce #251

Closed iparask closed 9 months ago

iparask commented 9 months ago

This PR fixes #250.

The existing code passed the input to Allreduce without any checks. As a consequence, when a scalar was passed at the input, it failed. This function is heavily used from the methods in sotodlib mapmaking utilities.

The solution is to add a check, and whenever Allreduce gets a scalar as input, change it to a NumPy array if 1 element and pass it. Since res is res = np.zeros_like(a), then it is a scalar when the input is one. As a result, the fix selects the first element of the result to return.

Also, sorry for the huge diff. I changed all tabs to 4 spaces. This is Python, after all.

The actual fix is in lines 1236-1249.

codecov[bot] commented 9 months ago

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (f412f41) 43.72% compared to head (7878201) 43.71%.

Files Patch % Lines
pixell/utils.py 0.00% 4 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #251 +/- ## ========================================== - Coverage 43.72% 43.71% -0.01% ========================================== Files 34 34 Lines 10939 10941 +2 ========================================== Hits 4783 4783 - Misses 6156 6158 +2 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

amaurea commented 9 months ago

I pushed a fix for this. It does basically the same thing except: