Open Croydon-Brixton opened 3 years ago
I did some tests and it looks like numpy does not short-circuit:
This issue seems to confirm it: https://github.com/numpy/numpy/issues/3446
However, there may be performance improvements by switching to np.where
or bigger ones from using numba
, as tested here https://stackoverflow.com/questions/58422690/filtering-a-numpy-array-what-is-the-best-approach
If numpy does short-circuit evaluation on these things this it'd be slightly faster to combine boolean masks.
Does anyone know how numpy handles these type of cases (below)?
Case: Case
select_from_array[np.logical_or(condition_array1, condition_array2)]
Does it first evaluate bothcondition_array1
andcondition_array2
in the slice[ ... ]
and thenor
the conditions (in which case it'd probably be slower bc we would calculate the geometry overlaps for shapes which won't agree in class label). Or does it calculate the first element ofcondition_array1
and then short-circuit decide if that element ofcondition_array2
even needs to be calculated? (in which case I think it should be slightly faster)_Originally posted by @Croydon-Brixton in https://github.com/ai4er-cdt/gtc-biodiversity/pull/28#discussion_r586369067_