Speed-up kwavearray functions
Currently the get_array_binary_mask and combine_sensor_data of the kWaveArray are pretty slow for a large number of array elements.
They would benefit from
- a general refactor such that expensive functions are called more efficiently
- parallized loops, as all element calculations are independent from each other
This (draft) PR implements a few ideas for the refactoring part.
get_array_binary_mask:
- we first compute the combined integration points of all elements and then hand them to
off_grid_pointsall at once, which saves many calls tooff_grid_pointsand avoids or'ing the final mask
combine_sensor_data
-
added options to input the sensor_mask, so it doesn't have to be calculated a second time
-
added an option to return the grid_weights sparsely. Currently the weights are collected in an array, then
matlab_findis used to find the non-zero voxels. Insteadoff_grid_pointscan compute the grid_weights in a collections.Counter, so that we don't have to additionally find them in a large array. -
additional idea: make
off_grid_pointsreturn a function that can quickly return the weights of an element without all the other stuff that happens inoff_grid_points. This could be useful in the element loop ofcombine_sensor_data, where we have to compute the weights of each element individually.
Regarding parallelization: I think joblib would probably be a good choice, but I don't have a lot of experience with that.