|
| 1 | +@testset verbose = false "ForwardDiff" begin |
| 2 | + # derivative and gradient for `f(x)` |
| 3 | + |
| 4 | + results1 = benchmark_differentiation( |
| 5 | + [AutoForwardDiff()]; |
| 6 | + outofplace=false, |
| 7 | + twoarg=false, |
| 8 | + input_type=Union{Number,AbstractVector}, |
| 9 | + output_type=Number, |
| 10 | + second_order=false, |
| 11 | + excluded=[PullbackScenario], |
| 12 | + logging=get(ENV, "CI", "false") == "false", |
| 13 | + ) |
| 14 | + |
| 15 | + # derivative and jacobian for f!(x, y) |
| 16 | + |
| 17 | + results2 = benchmark_differentiation( |
| 18 | + [AutoForwardDiff()]; |
| 19 | + outofplace=false, |
| 20 | + onearg=false, |
| 21 | + input_type=Union{Number,AbstractVector}, |
| 22 | + output_type=AbstractVector, |
| 23 | + second_order=false, |
| 24 | + excluded=[PullbackScenario], |
| 25 | + logging=get(ENV, "CI", "false") == "false", |
| 26 | + ) |
| 27 | + |
| 28 | + data = vcat(DataFrame(results1), DataFrame(results2)) |
| 29 | + |
| 30 | + useless_rows = |
| 31 | + startswith.(string.(data[!, :operator]), Ref("prepare")) .| |
| 32 | + startswith.(string.(data[!, :operator]), Ref("value_and")) |
| 33 | + |
| 34 | + useful_data = data[.!useless_rows, :] |
| 35 | + |
| 36 | + @testset "$(row[:operator]) - $(row[:func]) : $(row[:input_type]) -> $(row[:output_type])" for row in |
| 37 | + eachrow( |
| 38 | + useful_data |
| 39 | + ) |
| 40 | + @test row[:allocs] == 0 |
| 41 | + end |
| 42 | +end |
| 43 | + |
| 44 | +@testset verbose = false "Sparse ForwardDiff" begin |
| 45 | + # sparse jacobian for f!(x, y) |
| 46 | + |
| 47 | + b_sparse = AutoSparse( |
| 48 | + AutoForwardDiff(; chunksize=1); |
| 49 | + sparsity_detector=DI.SymbolicsSparsityDetector(), |
| 50 | + coloring_algorithm=DI.GreedyColoringAlgorithm(), |
| 51 | + ) |
| 52 | + |
| 53 | + results1 = benchmark_differentiation( |
| 54 | + [b_sparse], |
| 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 | + @testset "$(row[:operator]) - $(row[:func]) : $(row[:input_type]) -> $(row[:output_type])" for row in |
| 71 | + eachrow( |
| 72 | + useful_data |
| 73 | + ) |
| 74 | + @test row[:allocs] == 0 |
| 75 | + @test row[:calls] < prod(row[:input_size]) |
| 76 | + end |
| 77 | +end |
0 commit comments