Skip to content

Commit 9174ccb

Browse files
authored
Shorter sparse AD tests (#579)
* Shorter sparse AD tests * Make test sets verbose at file level
1 parent 43bb14a commit 9174ccb

3 files changed

Lines changed: 18 additions & 13 deletions

File tree

DifferentiationInterface/test/runtests.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ GROUP = get(ENV, "JULIA_DI_TEST_GROUP", "All")
2828
isdir(joinpath(@__DIR__, category)) || continue
2929
@testset verbose = true for folder in readdir(joinpath(@__DIR__, category))
3030
isdir(joinpath(@__DIR__, category, folder)) || continue
31-
@testset "$file" for file in readdir(joinpath(@__DIR__, category, folder))
31+
@testset verbose = true "$file" for file in readdir(
32+
joinpath(@__DIR__, category, folder)
33+
)
3234
endswith(file, ".jl") || continue
3335
@info "Testing $category/$folder/$file"
3436
include(joinpath(@__DIR__, category, folder, file))
@@ -39,7 +41,9 @@ GROUP = get(ENV, "JULIA_DI_TEST_GROUP", "All")
3941
category, folder = split(GROUP, '/')
4042
@testset verbose = true "$category" begin
4143
@testset verbose = true "$folder" begin
42-
@testset "$file" for file in readdir(joinpath(@__DIR__, category, folder))
44+
@testset verbose = true "$file" for file in readdir(
45+
joinpath(@__DIR__, category, folder)
46+
)
4347
endswith(file, ".jl") || continue
4448
@info "Testing $category/$folder/$file"
4549
include(joinpath(@__DIR__, category, folder, file))

DifferentiationInterfaceTest/src/scenarios/sparse.jl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,10 @@ end
214214

215215
## Various matrices
216216

217-
function banded_matrix(m, n, b)
218-
pairs = [k => rand(min(m, n) - k) for k in 0:b]
219-
return spdiagm(m, n, pairs...)
217+
function banded_matrix(::Type{T}, n, b) where {T}
218+
@assert b <= n
219+
pairs = [k => rand(T, n - k) for k in 0:b]
220+
return spdiagm(n, n, pairs...)
220221
end
221222

222223
### Linear map
@@ -245,7 +246,7 @@ end
245246
function squarelinearmap_scenarios(x::AbstractVector, band_sizes)
246247
n = length(x)
247248
scens = Scenario[]
248-
for A in vcat(banded_matrix.(2n, n, band_sizes), banded_matrix.(n ÷ 2, n, band_sizes))
249+
for A in banded_matrix.(eltype(x), n, band_sizes)
249250
f = SquareLinearMap(A)
250251
f! = f
251252
y = f(x)
@@ -305,7 +306,7 @@ end
305306
function squarequadraticform_scenarios(x::AbstractVector, band_sizes)
306307
n = length(x)
307308
scens = Scenario[]
308-
for A in banded_matrix.(n, n, band_sizes)
309+
for A in banded_matrix.(eltype(x), n, band_sizes)
309310
f = SquareQuadraticForm(A)
310311
grad = squarequadraticform_gradient(x, A)
311312
hess = sparse(squarequadraticform_hessian(x, A))
@@ -324,7 +325,7 @@ end
324325
Create a vector of [`Scenario`](@ref)s with sparse array types, focused on sparse Jacobians and Hessians.
325326
"""
326327
function sparse_scenarios(
327-
rng::AbstractRNG=default_rng(); band_sizes=0:4:36, include_constantified=false
328+
rng::AbstractRNG=default_rng(); band_sizes=[5, 10, 20], include_constantified=false
328329
)
329330
scens = vcat(
330331
sparse_vec_to_vec_scenarios(rand(rng, 6)),
@@ -335,8 +336,8 @@ function sparse_scenarios(
335336
sparse_mat_to_num_scenarios(rand(rng, 2, 3)),
336337
)
337338
if !isempty(band_sizes)
338-
append!(scens, squarelinearmap_scenarios(rand(rng, 100), band_sizes))
339-
append!(scens, squarequadraticform_scenarios(rand(rng, 100), band_sizes))
339+
append!(scens, squarelinearmap_scenarios(rand(rng, 50), band_sizes))
340+
append!(scens, squarequadraticform_scenarios(rand(rng, 50), band_sizes))
340341
end
341342
include_constantified && append!(scens, constantify(scens))
342343
return scens

DifferentiationInterfaceTest/test/runtests.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ GROUP = get(ENV, "JULIA_DIT_TEST_GROUP", "All")
1717
end
1818

1919
if GROUP == "Zero" || GROUP == "All"
20-
@testset verbose = false "Zero" begin
20+
@testset verbose = true "Zero" begin
2121
include("zero_backends.jl")
2222
end
2323
end
2424

2525
if GROUP == "Standard" || GROUP == "All"
26-
@testset verbose = false "Standard" begin
26+
@testset verbose = true "Standard" begin
2727
include("standard.jl")
2828
end
2929
end
3030

3131
if GROUP == "Weird" || GROUP == "All"
32-
@testset verbose = false "Weird" begin
32+
@testset verbose = true "Weird" begin
3333
include("weird.jl")
3434
end
3535
end

0 commit comments

Comments
 (0)