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

rm function.replace, add deep and shallow variants #863

Merged
3 commits merged into from
Mar 21, 2024
Merged

rm function.replace, add deep and shallow variants #863

3 commits merged into from
Mar 21, 2024

Conversation

gertjanvanzwieten
Copy link
Contributor

This PR removes the general function.replace decorator and replaces it with the specialized deep_replace_property (used for simplified and optimized_for_numpy) and shallow_replace (used for replace_arguments, _deep_flatten_constants and _combine_loop_concatenates). The differences between the two constructs are as follows:

@deep_replace_property

  • property
  • intermediate values cached in object attribute
  • depth first
  • recursive

@shallow_replace

  • function
  • intermediate values cached only during replacement
  • depth last
  • non recursive

nutils/_util.py Outdated Show resolved Hide resolved
nutils/_util.py Outdated Show resolved Hide resolved
nutils/_util.py Show resolved Hide resolved
nutils/_util.py Outdated Show resolved Hide resolved
nutils/_util.py Outdated Show resolved Hide resolved
nutils/_util.py Outdated Show resolved Hide resolved
Gertjan van Zwieten added 3 commits March 21, 2024 10:49
This patch adds the deep_replace_property and shallow_replace
decorators to _util. The differences between the two constructs are as
follows:

@_util.deep_replace_property
- property
- intermediate values cached in object attribute
- depth first
- recursive

@_util.shallow_replace
- function
- intermediate values cached only during replacement
- depth last
- non recursive
This patch removes the function.replace decorator and replaces it with
_util.deep_replace_property (for simplified and optimized_for_numpy) and
_util.shallow_replace (for replace_arguments, _deep_flatten_constants
and _combine_loop_concatenates). The specialized variants are faster,
use less memory, and offer better cache reuse.
@gertjanvanzwieten gertjanvanzwieten closed this pull request by merging all changes into master in 2444961 Mar 21, 2024
gertjanvanzwieten pushed a commit that referenced this pull request Mar 21, 2024
This PR removes the general function.replace decorator and replaces it
with the specialized deep_replace_property (used for simplified and
optimized_for_numpy) and shallow_replace (used for replace_arguments,
_deep_flatten_constants and _combine_loop_concatenates). The differences
between the two constructs are as follows:

@deep_replace_property
- property
- intermediate values cached in object attribute
- depth first
- recursive

@shallow_replace
- function
- intermediate values cached only during replacement
- depth last
- non recursive
@joostvanzwieten joostvanzwieten deleted the replace branch March 31, 2024 20:56
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