Skip to content

Commit

Permalink
Merge pull request #413 from MilesCranmer/fix-colors-tuple-bound
Browse files Browse the repository at this point in the history
fix: max of 6 expressions bug
  • Loading branch information
MilesCranmer authored Feb 13, 2025
2 parents ea13e3d + 69abc94 commit 1badff4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SymbolicRegression"
uuid = "8254be44-1295-4e6a-a16d-46603ac705cb"
authors = ["MilesCranmer <[email protected]>"]
version = "1.7.1"
version = "1.7.2"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down
2 changes: 1 addition & 1 deletion examples/parameterized_function.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@ ypred2 = predict(mach, (data=X, idx=idx2))
loss2 = sum(i -> abs2(ypred2[i] - y[i]), eachindex(y)) / length(y)

# Should get better:
@test loss1 > loss2
@test loss1 >= loss2
2 changes: 1 addition & 1 deletion src/TemplateExpression.jl
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ end
# Rather than using iterator with repeat, just make a tuple:
function _colors(::Val{n}) where {n}
return ntuple(
(i -> (:magenta, :green, :red, :blue, :yellow, :cyan)[mod1(i, n)]), Val(n)
(i -> (:magenta, :green, :red, :blue, :yellow, :cyan)[mod1(i, 6)]), Val(n)
)
end
_color_string(s::AbstractString, c::Symbol) = styled"{$c:$s}"
Expand Down
22 changes: 22 additions & 0 deletions test/test_template_expression_string.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
@testitem "template expression color function" tags = [:part1, :template_colors] begin
using SymbolicRegression.TemplateExpressionModule: _colors

# Test empty case
@test _colors(Val(0)) == ()

# Test n <= 6 cases
@test _colors(Val(1)) == (:magenta,)
@test _colors(Val(2)) == (:magenta, :green)
@test _colors(Val(6)) == (:magenta, :green, :red, :blue, :yellow, :cyan)

# Test n > 6 cases to verify color cycling
colors_7 = _colors(Val(7))
@test length(colors_7) == 7
@test colors_7[1:6] == (:magenta, :green, :red, :blue, :yellow, :cyan)
@test colors_7[7] == :magenta # Should cycle back to first color

colors_8 = _colors(Val(8))
@test length(colors_8) == 8
@test colors_8[7:8] == (:magenta, :green) # Should cycle colors properly
end

@testitem "template expression string representation" tags = [:part1, :template_string] begin
using SymbolicRegression
using StyledStrings: @styled_str, annotatedstring, AnnotatedString
Expand Down

2 comments on commit 1badff4

@MilesCranmer
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/125050

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.7.2 -m "<description of version>" 1badff4e6f7f1b58bd42ca88b21cbd4eab357d9f
git push origin v1.7.2

Please sign in to comment.