Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed-up kwavearray functions #533

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

faberno
Copy link
Contributor

@faberno faberno commented Dec 26, 2024

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_points all at once, which saves many calls to off_grid_points and 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_find is used to find the non-zero voxels. Instead off_grid_points can 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_points return a function that can quickly return the weights of an element without all the other stuff that happens in off_grid_points. This could be useful in the element loop of combine_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.

@faberno faberno marked this pull request as draft December 26, 2024 00:59
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.

1 participant