MAINT: minor cython cleanup in align/vector_fields.pyx #1049
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
These are minor changes to remove python interaction from within some of the loops present in
vector_fields.pyx
.It is easiest to verify the reduction in Python interaction via observing the reduction in yellow lines in the annotated HTML files generated by
cython -a vector_fields.pyx
in this PR vs master.The following four functions receive approximately 3 orders of magnitude speedup by avoiding calls to np.cos, np.arctan2 and/or np.sqrt:
create_circle
,create_sphere
,create_harmonic_fields_2d
,create_harmonic_fields_3d
For the rest, there is negligable difference in performance. I have also looked at enabling parallel processing via prange in some of these functions and plan to submit that as a separate future PR. (In the multithreaded case, the change of
_interpolate_vector_2d
and_interpolate_vector_3d
to usefloating* out
instead offloating[:] out
makes a huge difference to some of the routines that were passing a view of a memoryview which was causing things to actually become slower if multithreaded)