Skip to content

Commit

Permalink
Change get_tournament_selection_weights function signature (#395)
Browse files Browse the repository at this point in the history
* Change `get_tournament_selection_weights` options type to AbstractOptions

`get_tournament_selection_weights`, presently, only accepts `options::Options`. This created a bottleneck for LaSR (or any other SymbolicRegression.jl customization) that relies on multiple dispatch of subtypes of `AbstractOptions` type. Changing the function signature doesn't impact the test cases in SymbolicRegression.jl.

* refactor: improve type instability in `get_tournament_selection_weights`

---------

Co-authored-by: Miles Cranmer <miles.cranmer@gmail.com>
  • Loading branch information
atharvas and MilesCranmer authored Dec 27, 2024
1 parent 2cd4c1a commit f73670f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Population.jl
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ const CACHED_WEIGHTS =
PerThreadCache{Dict{Tuple{Int,Float32},typeof(test_weights)}}()
end

@unstable function get_tournament_selection_weights(@nospecialize(options::Options))
n = options.tournament_selection_n
p = options.tournament_selection_p
@unstable function get_tournament_selection_weights(@nospecialize(options::AbstractOptions))
n = options.tournament_selection_n::Int
p = options.tournament_selection_p::Float32
# Computing the weights for the tournament becomes quite expensive,
return get!(CACHED_WEIGHTS, (n, p)) do
k = collect(0:(n - 1))
Expand Down

0 comments on commit f73670f

Please sign in to comment.