Skip to content

Remove unused np.where from rmsimage.py#315

Open
AlexKurek wants to merge 3 commits into
lofar-astron:masterfrom
AlexKurek:Remove-unused-np-where-from-rmsimage
Open

Remove unused np.where from rmsimage.py#315
AlexKurek wants to merge 3 commits into
lofar-astron:masterfrom
AlexKurek:Remove-unused-np-where-from-rmsimage

Conversation

@AlexKurek

@AlexKurek AlexKurek commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Since np.where turns out to be so slow (#311), it would be good to remove it where it is not needed.
.gaul files are identical, but currently the test will fail due to #314.

@AlexKurek AlexKurek changed the title Remove unused np_where from rmsimage.py Remove unused np.where from rmsimage.py Jun 16, 2026
@gmloose

gmloose commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

The function numpy.where() is also used in several other places, a quick grep reveals. I didn't look if some of these calls can also be removed safely, but it might be worth a check. If so, I have no objection if you extend this MR to cover the removal of all unnecessary calls to numpy.where().

@AlexKurek

AlexKurek commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

At the other places np.where has an actuall effect and is needed. Except this one:
https://github.com/lofar-astron/PyBDSF/blob/master/bdsf/rmsimage.py#L961
but I think there may also be a bug in this block (#317), so I think its safer to leave it for another PR.

@AlexKurek

Copy link
Copy Markdown
Contributor Author

Generally, np.where is redundant for boolean masking, checking element existence, or counting matching elements. Instead, directly use boolean indexing (arr[mask]), np.any(), or np.count_nonzero(). This avoids unnecessary memory overhead and improves speed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants