Reduce memory overhead and improve performance of normalize_colors_pca #328
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.
In this PR we change the following line:
to instead modify
conc_raw
in-place. Theconc_raw
array is an intermediate array of concentrations, so changing to an in-place operation will not effect user-facing code. The benefit is avoiding an extra copy of the concentrations array. It also avoids an unintended promotion to float64 due to multiplication by anormalization_factors
array that was potentially higher precision thanconc_raw
.For a fairly large uint8 input array of shape
(26420, 19920, 3)
, theconc_raw
array ends up as an ~4GB float32 array. Without the change in this PR there will be a new 8GB float64conc_norm
array created. By avoiding this we substantially reduce memory use.We also make sure the
ref_max_conc
andref_stain_coeff
inputs to_normalized_from_concentration
match the precision of the image. Due to this, a 25% improvement in performance was observed (due to float32 rather than float64 computations in the remainder of the_normalized_from_concentrations
function).