fix: use eltype(x0) instead of T for randn in constant optimization (backport to release-v1)#571
Conversation
6197459 to
d448f27
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## release-v1 #571 +/- ##
==============================================
- Coverage 92.67% 92.65% -0.03%
==============================================
Files 41 41
Lines 3660 3662 +2
==============================================
+ Hits 3392 3393 +1
- Misses 268 269 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
9b6e5bf to
0516756
Compare
…backport to release-v1) Issue astroautomata#568: When using custom types with constant optimization and optimizer_nrestarts > 0, the code incorrectly used T (the custom type) instead of the scalar element type when calling randn(). This caused a MethodError because randn() only works with scalar types. The fix uses eltype(x0) which returns the scalar type (e.g., Float64) rather than T which could be a custom type like AbstractVector. Also adds a regression test to prevent this bug from recurring. Fixes astroautomata#568
0516756 to
784db51
Compare
|
Hey @MilesCranmer, is this PR likely to be merged any time soon? I noticed that the PR for the current version (not the backport) was merged a little while ago: #570 |
|
Hey, sorry, I just forgot about it (teaching this term so twice as busy as normal). @MilesCranmerBot can you figure out why the CI is failing and fix it? Maybe merge in the latest changes from release-v1 as well. |
|
Thank you! |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Hi @MilesCranmer just following up again, looks like all checks have passed here so this one should be good to go? |
|
@codex review |
|
Codex Review: Didn't find any major issues. 👍 ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
sorry for the delay! |
…release-v1--components--SymbolicRegression chore(release-v1): release 1.13.1
|
No worries, thanks for all your work on this package! |
Backport of #570 to release-v1
Fixes #568
Bug Description
When using custom types (e.g.,
AbstractVector{<:Number}) with constant optimization andoptimizer_nrestarts > 0, the code incorrectly usedT(the custom type from the PopMember type parameter) instead of the scalar element type when callingrandn(). This caused aMethodErrorbecauserandn()only works with scalar types likeFloat64, not custom types.Fix
Changed
src/ConstantOptimization.jlto useeltype(x0)instead ofTin the restart loop:x0is always aVector{<:Number}(the scalar constants extracted from the expression)eltype(x0)returns the scalar type (e.g.,Float64)Tcould be a custom type likeMyVec2 <: AbstractVector{Float64}Changes
_optimize_constantsto useeltype(x0)forrandn()and type conversionstest/unit/evolution-core/test_custom_type_constant_optimization.jl