Skip to content

Commit ed347c3

Browse files
committed
test: fix formatting
1 parent 40dc916 commit ed347c3

7 files changed

Lines changed: 62 additions & 49 deletions

File tree

test/integration/ad/test_derivatives.jl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
sin(
1818
custom_cos(
1919
sin(1.2926733 - 1.6606787) / sin(
20-
((0.14577048 * x1) + ((0.111149654 + x1) - -0.8298334)) - -1.2071426
20+
((0.14577048 * x1) + ((0.111149654 + x1) - -0.8298334)) -
21+
-1.2071426,
2122
),
2223
) * (custom_cos(x3 - 2.3201916) + ((x1 - (x1 * x2)) / x2)),
2324
) / (0.14854191 - ((custom_cos(x2) * -1.6047639) - 0.023943262))
@@ -64,14 +65,16 @@
6465
@test array_test(predicted_output, true_output)
6566

6667
true_grad = gradient(
67-
(x1, x2, x3) -> sum(equation.(x1, x2, x3)), [X[i, :] for i in 1:nfeatures]...
68+
(x1, x2, x3) -> sum(equation.(x1, x2, x3)),
69+
[X[i, :] for i in 1:nfeatures]...,
6870
)
6971
# Convert tuple of vectors to matrix:
7072
true_grad = reduce(hcat, true_grad)'
7173
predicted_grad = eval_grad_tree_array(tree, X, options; variable=true)[2]
7274
predicted_grad2 =
7375
reduce(
74-
hcat, [eval_diff_tree_array(tree, X, options, i)[2] for i in 1:nfeatures]
76+
hcat,
77+
[eval_diff_tree_array(tree, X, options, i)[2] for i in 1:nfeatures],
7578
)'
7679

7780
# Print largest difference between predicted_grad, true_grad:

test/integration/ad/test_tree_construction.jl

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
using SymbolicRegression: eval_loss, eval_cost, Dataset
66
using ForwardDiff
77
include(joinpath(@__DIR__, "..", "..", "test_params.jl"))
8-
8+
99
x1 = 2.0
10-
10+
1111
function make_options_maker(binop, unaop; kw...)
1212
@nospecialize binop unaop kw
1313
return Options(;
@@ -19,37 +19,41 @@
1919
kw...,
2020
)
2121
end
22-
22+
2323
# Initialize functions in Base....
2424
for unaop in
2525
[cos, exp, safe_log, safe_log2, safe_log10, safe_sqrt, relu, gamma, safe_acosh],
2626
binop in [sub]
27-
27+
2828
let
2929
make_options = Fix{1}(Fix{2}(make_options_maker, unaop), binop)
3030
options = make_options()
3131
@extend_operators options
32-
32+
3333
# for unaop in
3434
f_true = (x,) -> binop(abs(3.0 * unaop(x))^2.0, -1.2)
35-
35+
3636
# binop at outside:
3737
const_tree = Node(
38-
5, (^)(Node(2, Node(; val=3.0) * Node(1, Node("x1"))), 2.0), Node(; val=-1.2)
38+
5,
39+
(^)(Node(2, Node(; val=3.0) * Node(1, Node("x1"))), 2.0),
40+
Node(; val=-1.2),
3941
)
4042
const_tree_bad = Node(
41-
5, (^)(Node(2, Node(; val=3.0) * Node(1, Node("x1"))), 2.1), Node(; val=-1.3)
43+
5,
44+
(^)(Node(2, Node(; val=3.0) * Node(1, Node("x1"))), 2.1),
45+
Node(; val=-1.3),
4246
)
4347
n = count_nodes(const_tree)
44-
48+
4549
true_result = f_true(x1)
46-
50+
4751
result = eval(Meta.parse(string_tree(const_tree, options)))
48-
52+
4953
# Test Basics
5054
@test n == 9
5155
@test result == true_result
52-
56+
5357
types_to_test = [Float32, Float64, BigFloat]
5458
if unaop == cos
5559
# Other unary operators produce numbers too large
@@ -62,10 +66,10 @@
6266
else
6367
zero_tolerance = 1e-6
6468
end
65-
69+
6670
tree = convert(Node{T}, const_tree)
6771
tree_bad = convert(Node{T}, const_tree_bad)
68-
72+
6973
Random.seed!(0)
7074
N = 100
7175
if unaop in [safe_log, safe_log2, safe_log10, safe_acosh, safe_sqrt]
@@ -77,40 +81,41 @@
7781
if unaop == safe_acosh
7882
X = X .+ T(1.0)
7983
end
80-
84+
8185
y = T.(f_true.(X[1, :]))
8286
dataset = Dataset(X, y)
8387
test_y, complete = eval_tree_array(tree, X, make_options())
8488
test_y2, complete2 = differentiable_eval_tree_array(tree, X, make_options())
85-
89+
8690
# Test Evaluation
8791
@test complete == true
8892
@test all(abs.(test_y .- y) / N .< zero_tolerance)
8993
@test complete2 == true
9094
@test all(abs.(test_y2 .- y) / N .< zero_tolerance)
91-
95+
9296
# Test loss:
9397
@test abs(eval_loss(tree, dataset, make_options())) < zero_tolerance
9498
@test eval_loss(tree, dataset, make_options()) ==
9599
eval_cost(dataset, tree, make_options())[2]
96-
100+
97101
#Test Scoring
98102
@test abs(eval_cost(dataset, tree, make_options(; parsimony=0.0))[1]) <
99103
zero_tolerance
100104
@test eval_cost(dataset, tree, make_options(; parsimony=1.0))[1] > 1.0
101105
@test eval_cost(dataset, tree, make_options())[1] <
102106
eval_cost(dataset, tree_bad, make_options())[1]
103-
107+
104108
dataset_with_larger_baseline = deepcopy(dataset)
105109
dataset_with_larger_baseline.baseline_loss = one(T) * 10
106110
@test eval_cost(dataset_with_larger_baseline, tree_bad, make_options())[1] <
107111
eval_cost(dataset, tree_bad, make_options())[1]
108-
112+
109113
# Test gradients:
110114
df_true = x -> ForwardDiff.derivative(f_true, x)
111115
dy = T.(df_true.(X[1, :]))
112116
test_dy = ForwardDiff.gradient(
113-
_x -> sum(differentiable_eval_tree_array(tree, _x, make_options())[1]), X
117+
_x -> sum(differentiable_eval_tree_array(tree, _x, make_options())[1]),
118+
X,
114119
)
115120
test_dy = test_dy[1, 1:end]
116121
@test all(abs.(test_dy .- dy) / N .< zero_tolerance)

test/integration/ext/json3_recorder/test_recorder.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
using SymbolicRegression.UtilsModule: recursive_merge
44
using JSON3
55
include(joinpath(@__DIR__, "..", "..", "..", "test_params.jl"))
6-
6+
77
base_dir = mktempdir()
88
recorder_file = joinpath(base_dir, "pysr_recorder.json")
99
X = 2 .* randn(Float32, 2, 1000)
1010
y = 3 * cos.(X[2, :]) + X[1, :] .^ 2 .- 2
11-
11+
1212
options = SymbolicRegression.Options(;
1313
binary_operators=(+, *, /, -),
1414
unary_operators=(cos,),
@@ -19,24 +19,24 @@
1919
maxsize=20,
2020
complexity_of_operators=[cos => 2],
2121
)
22-
22+
2323
hall_of_fame = equation_search(
2424
X, y; niterations=5, options=options, parallelism=:multithreading
2525
)
26-
26+
2727
data = open(options.recorder_file, "r") do io
2828
JSON3.read(io; allow_inf=true)
2929
end
30-
30+
3131
@test haskey(data, :options)
3232
@test haskey(data, :out1_pop1)
3333
@test haskey(data, :out1_pop2)
3434
@test haskey(data, :mutations)
35-
35+
3636
# Test that "Options" is part of the string in `data.options`:
3737
@test contains(data.options, "Options")
3838
@test length(data.mutations) > 1000
39-
39+
4040
# Check whether 10 random elements have the right properties:
4141
for (i, key) in enumerate(keys(data.mutations))
4242
@test haskey(data.mutations[key], :events)
@@ -48,6 +48,6 @@
4848
break
4949
end
5050
end
51-
51+
5252
@test_throws ErrorException recursive_merge()
5353
end

test/integration/ext/loopvectorization/test_nan_detection.jl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
println("Testing NaN detection.")
33
using SymbolicRegression
44
using LoopVectorization
5-
5+
66
for T in [Float16, Float32, Float64], turbo in [true, false]
77
T == Float16 && turbo && continue
88
local options, tree, X
9-
9+
1010
options = Options(;
11-
binary_operators=(+, *, /, -, ^), unary_operators=(cos, sin, exp, sqrt), turbo=turbo
11+
binary_operators=(+, *, /, -, ^),
12+
unary_operators=(cos, sin, exp, sqrt),
13+
turbo=turbo,
1214
)
1315
@extend_operators options
1416
# Creating a NaN via computation.
@@ -17,27 +19,27 @@
1719
X = fill(T(100), 1, 10)
1820
output, flag = eval_tree_array(tree, X, options)
1921
@test !flag
20-
22+
2123
# Creating a NaN/Inf via division by constant zero.
2224
tree = cos(Node(T; feature=1) / zero(T))
2325
tree = convert(Node{T}, tree)
2426
output, flag = eval_tree_array(tree, X, options)
2527
@test !flag
26-
28+
2729
# Creating a NaN via sqrt(-1):
2830
tree = safe_sqrt(Node(T; feature=1) - 1)
2931
tree = convert(Node{T}, tree)
3032
X = fill(T(0), 1, 10)
3133
output, flag = eval_tree_array(tree, X, options)
3234
@test !flag
33-
35+
3436
# Creating a NaN via pow(-1, 0.5):
3537
tree = (^)(Node(T; feature=1) - 1, 0.5)
3638
tree = convert(Node{T}, tree)
3739
X = fill(T(0), 1, 10)
3840
output, flag = eval_tree_array(tree, X, options)
3941
@test !flag
40-
42+
4143
# Having a NaN/Inf constants:
4244
tree = cos(Node(T; feature=1) + T(Inf))
4345
tree = convert(Node{T}, tree)
@@ -48,6 +50,6 @@
4850
output, flag = eval_tree_array(tree, X, options)
4951
@test !flag
5052
end
51-
53+
5254
println("Passed.")
5355
end

test/integration/ext/loopvectorization/test_turbo_nan.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
@testitem "Test turbo NaN with LoopVectorization" begin
22
using SymbolicRegression
33
using LoopVectorization
4-
4+
55
bad_op(x::T) where {T} = (x >= 0) ? x : T(0)
6-
6+
77
options = Options(;
88
unary_operators=(sin, exp, sqrt, bad_op),
99
binary_operators=(+, *),
@@ -14,19 +14,19 @@
1414
# ^ Leave as deprecated param, just to test.
1515
parsimony=0.01,
1616
)
17-
17+
1818
tree = Node(3, Node(1, Node(; val=-π / 2)))
19-
19+
2020
# Should still be safe against domain errors:
2121
try
2222
tree([0.0]', options)
2323
@test true
2424
catch e
2525
@test false
2626
end
27-
27+
2828
tree = Node(3, Node(1, Node(; feature=1)))
29-
29+
3030
try
3131
tree([-π / 2]', options)
3232
@test true

test/integration/ext/symbolicutils/test_simplification.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@
6363
((x2 + x2) * ((-0.5982493 / pow_abs2(x1, x2)) / -0.54734415)) + (
6464
sin(
6565
custom_cos2(
66-
sin(1.2926733 - 1.6606787) /
67-
sin(((0.14577048 * x1) + ((0.111149654 + x1) - -0.8298334)) - -1.2071426),
66+
sin(1.2926733 - 1.6606787) / sin(
67+
((0.14577048 * x1) + ((0.111149654 + x1) - -0.8298334)) - -1.2071426
68+
),
6869
) * (custom_cos2(x3 - 2.3201916) + ((x1 - (x1 * x2)) / x2)),
6970
) / (0.14854191 - ((custom_cos2(x2) * -1.6047639) - 0.023943262))
7071
)

test/runtests.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ ENV["SYMBOLIC_REGRESSION_TEST"] = "true"
3434
end
3535

3636
# Run all test items in the integration directory
37-
@run_package_tests(filter = ti -> startswith(ti.filename, integration_dir), verbose = true)
37+
@run_package_tests(
38+
filter = ti -> startswith(ti.filename, integration_dir), verbose = true
39+
)
3840
else
3941
# Unit tests
4042
test_dir = joinpath(@__DIR__, TEST_GROUP)

0 commit comments

Comments
 (0)