⚡️ Speed up function sensor_vals_to_temp by 13%#24
Open
codeflash-ai[bot] wants to merge 1 commit intomasterfrom
Open
⚡️ Speed up function sensor_vals_to_temp by 13%#24codeflash-ai[bot] wants to merge 1 commit intomasterfrom
sensor_vals_to_temp by 13%#24codeflash-ai[bot] wants to merge 1 commit intomasterfrom
Conversation
The optimization achieves a **13% speedup** by eliminating redundant expensive calculations: **Key optimizations:** 1. **Eliminated duplicate tau2 calculation**: The original code computed the same complex exponential expression for both `tau1` and `tau2`. The optimized version simply assigns `tau2 = tau1`, saving ~150ms of computation time (5.2% → 0.5% of total runtime). 2. **Reused identical Planck radiance calculations**: - `raw_refl2` now reuses `raw_refl1` instead of recalculating the same Planck equation with identical `ReflectedApparentTemperature` - `raw_atm2` now reuses `raw_atm1` instead of recalculating with the same `AtmosphericTemperature` 3. **Reduced expensive numpy operations**: These changes eliminate multiple calls to `np.exp()` with complex expressions involving `PlanckB` divisions and temperature conversions. **Performance impact by test case:** - **Scalar inputs**: 18-25% faster (most benefit from reduced overhead) - **Small arrays**: 14-20% faster (good balance of computation reduction) - **Large arrays (1000+ elements)**: 5-9% faster (numpy vectorization dominates, but still measurable gains) - **Edge cases with extreme parameters**: 10-37% faster (parameter-dependent calculations benefit most) The optimizations are mathematically equivalent since `tau1` and `tau2` use identical formulas, and the Planck radiance calculations use the same temperature inputs. The speedup comes from recognizing and exploiting these mathematical redundancies in the thermal sensor calibration equations.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
📄 13% (0.13x) speedup for
sensor_vals_to_tempinopendm/thermal_tools/thermal_utils.py⏱️ Runtime :
1.39 milliseconds→1.23 milliseconds(best of129runs)📝 Explanation and details
The optimization achieves a 13% speedup by eliminating redundant expensive calculations:
Key optimizations:
Eliminated duplicate tau2 calculation: The original code computed the same complex exponential expression for both
tau1andtau2. The optimized version simply assignstau2 = tau1, saving ~150ms of computation time (5.2% → 0.5% of total runtime).Reused identical Planck radiance calculations:
raw_refl2now reusesraw_refl1instead of recalculating the same Planck equation with identicalReflectedApparentTemperatureraw_atm2now reusesraw_atm1instead of recalculating with the sameAtmosphericTemperatureReduced expensive numpy operations: These changes eliminate multiple calls to
np.exp()with complex expressions involvingPlanckBdivisions and temperature conversions.Performance impact by test case:
The optimizations are mathematically equivalent since
tau1andtau2use identical formulas, and the Planck radiance calculations use the same temperature inputs. The speedup comes from recognizing and exploiting these mathematical redundancies in the thermal sensor calibration equations.✅ Correctness verification report:
🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-sensor_vals_to_temp-mh5gn58qand push.