|
| 1 | +using DifferentiationInterface, DifferentiationInterfaceTest |
| 2 | +using ForwardDiff: ForwardDiff |
| 3 | +using DataFrames: DataFrame |
| 4 | + |
| 5 | +@testset verbose = false "Dense efficiency" begin |
| 6 | + # derivative and gradient for `f(x)` |
| 7 | + |
| 8 | + results1 = benchmark_differentiation( |
| 9 | + [AutoForwardDiff()], |
| 10 | + default_scenarios(); |
| 11 | + outofplace=false, |
| 12 | + twoarg=false, |
| 13 | + input_type=Union{Number,AbstractVector}, |
| 14 | + output_type=Number, |
| 15 | + second_order=false, |
| 16 | + excluded=[PullbackScenario], |
| 17 | + logging=get(ENV, "CI", "false") == "false", |
| 18 | + ) |
| 19 | + |
| 20 | + # derivative and jacobian for f!(x, y) |
| 21 | + |
| 22 | + results2 = benchmark_differentiation( |
| 23 | + [AutoForwardDiff()], |
| 24 | + default_scenarios(); |
| 25 | + outofplace=false, |
| 26 | + onearg=false, |
| 27 | + input_type=Union{Number,AbstractVector}, |
| 28 | + output_type=AbstractVector, |
| 29 | + second_order=false, |
| 30 | + excluded=[PullbackScenario], |
| 31 | + logging=get(ENV, "CI", "false") == "false", |
| 32 | + ) |
| 33 | + |
| 34 | + data = vcat(DataFrame(results1), DataFrame(results2)) |
| 35 | + |
| 36 | + useless_rows = |
| 37 | + startswith.(string.(data[!, :operator]), Ref("prepare")) .| |
| 38 | + startswith.(string.(data[!, :operator]), Ref("value_and")) |
| 39 | + |
| 40 | + useful_data = data[.!useless_rows, :] |
| 41 | + |
| 42 | + for row in eachrow(useful_data) |
| 43 | + scen = row[:scenario] |
| 44 | + @testset "$(row[:operator]) - $(string(scen.f)) : $(typeof(scen.x)) -> $(typeof(scen.y))" begin |
| 45 | + @test row[:allocs] == 0 |
| 46 | + end |
| 47 | + end |
| 48 | +end |
| 49 | + |
| 50 | +@testset verbose = false "Sparse efficiency" begin |
| 51 | + # sparse jacobian for f!(x, y) |
| 52 | + |
| 53 | + results1 = benchmark_differentiation( |
| 54 | + [MyAutoSparse(AutoForwardDiff(; chunksize=1);)], |
| 55 | + sparse_scenarios(); |
| 56 | + input_type=AbstractVector, |
| 57 | + output_type=AbstractVector, |
| 58 | + outofplace=false, |
| 59 | + onearg=false, |
| 60 | + second_order=false, |
| 61 | + logging=get(ENV, "CI", "false") == "false", |
| 62 | + ) |
| 63 | + |
| 64 | + data = vcat(DataFrame(results1)) |
| 65 | + |
| 66 | + useless_rows = startswith.(string.(data[!, :operator]), Ref("prepare")) |
| 67 | + |
| 68 | + useful_data = data[.!useless_rows, :] |
| 69 | + |
| 70 | + for row in eachrow(useful_data) |
| 71 | + scen = row[:scenario] |
| 72 | + @testset "$(row[:operator]) - $(string(scen.f)) : $(typeof(scen.x)) -> $(typeof(scen.y))" begin |
| 73 | + @test row[:allocs] == 0 |
| 74 | + @test row[:calls] < prod(size(scen.x)) |
| 75 | + end |
| 76 | + end |
| 77 | +end |
0 commit comments