-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests for no alloc and reduced calls in (sparse) ForwardDiff
- Loading branch information
Showing
6 changed files
with
86 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
@testset verbose = false "ForwardDiff" begin | ||
# derivative and gradient for `f(x)` | ||
|
||
results1 = benchmark_differentiation( | ||
[AutoForwardDiff()]; | ||
outofplace=false, | ||
twoarg=false, | ||
input_type=Union{Number,AbstractVector}, | ||
output_type=Number, | ||
second_order=false, | ||
excluded=[PullbackScenario], | ||
logging=get(ENV, "CI", "false") == "false", | ||
) | ||
|
||
# derivative and jacobian for f!(x, y) | ||
|
||
results2 = benchmark_differentiation( | ||
[AutoForwardDiff()]; | ||
outofplace=false, | ||
onearg=false, | ||
input_type=Union{Number,AbstractVector}, | ||
output_type=AbstractVector, | ||
second_order=false, | ||
excluded=[PullbackScenario], | ||
logging=get(ENV, "CI", "false") == "false", | ||
) | ||
|
||
data = vcat(DataFrame(results1), DataFrame(results2)) | ||
|
||
useless_rows = | ||
startswith.(string.(data[!, :operator]), Ref("prepare")) .| | ||
startswith.(string.(data[!, :operator]), Ref("value_and")) | ||
|
||
useful_data = data[.!useless_rows, :] | ||
|
||
@testset "$(row[:operator]) - $(row[:func]) : $(row[:input_type]) -> $(row[:output_type])" for row in | ||
eachrow( | ||
useful_data | ||
) | ||
@test row[:allocs] == 0 | ||
end | ||
end | ||
|
||
@testset verbose = false "Sparse ForwardDiff" begin | ||
# sparse jacobian for f!(x, y) | ||
|
||
b_sparse = AutoSparse( | ||
AutoForwardDiff(; chunksize=1); | ||
sparsity_detector=DI.SymbolicsSparsityDetector(), | ||
coloring_algorithm=DI.GreedyColoringAlgorithm(), | ||
) | ||
|
||
results1 = benchmark_differentiation( | ||
[b_sparse], | ||
sparse_scenarios(); | ||
input_type=AbstractVector, | ||
output_type=AbstractVector, | ||
outofplace=false, | ||
onearg=false, | ||
second_order=false, | ||
logging=get(ENV, "CI", "false") == "false", | ||
) | ||
|
||
data = vcat(DataFrame(results1)) | ||
|
||
useless_rows = startswith.(string.(data[!, :operator]), Ref("prepare")) | ||
|
||
useful_data = data[.!useless_rows, :] | ||
|
||
@testset "$(row[:operator]) - $(row[:func]) : $(row[:input_type]) -> $(row[:output_type])" for row in | ||
eachrow( | ||
useful_data | ||
) | ||
@test row[:allocs] == 0 | ||
@test row[:calls] < prod(row[:input_size]) | ||
end | ||
end |
File renamed without changes.
File renamed without changes.
This file contains 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
This file contains 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