Skip to content

Commit 675b4bd

Browse files
authored
refactor!: remove randomness in scenario creation (#623)
* Remove randomness in scenario creation * Typo
1 parent 1e012dc commit 675b4bd

9 files changed

Lines changed: 44 additions & 48 deletions

File tree

DifferentiationInterfaceTest/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DifferentiationInterfaceTest"
22
uuid = "a82114a7-5aa3-49a8-9643-716bb13727a3"
33
authors = ["Guillaume Dalle", "Adrian Hill"]
4-
version = "0.8.5"
4+
version = "0.9.0"
55

66
[deps]
77
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"

DifferentiationInterfaceTest/ext/DifferentiationInterfaceTestComponentArraysExt/DifferentiationInterfaceTestComponentArraysExt.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ using DifferentiationInterface
55
using DifferentiationInterfaceTest
66
import DifferentiationInterfaceTest as DIT
77
using LinearAlgebra: dot
8-
using Random: AbstractRNG, default_rng
98

109
## Vector to scalar
1110

@@ -49,11 +48,11 @@ end
4948

5049
## Gather
5150

52-
function DIT.component_scenarios(rng::AbstractRNG=default_rng())
53-
dy_ = rand(rng)
51+
function DIT.component_scenarios()
52+
dy_ = -1 / 12
5453

55-
x_comp = ComponentVector(; a=randn(rng, 4), b=randn(rng, 2))
56-
dx_comp = ComponentVector(; a=randn(rng, 4), b=randn(rng, 2))
54+
x_comp = ComponentVector(; a=float.(1:4), b=float.(5:6))
55+
dx_comp = ComponentVector(; a=float.(4:-1:1), b=float.(6:-1:5))
5756

5857
scens = vcat(
5958
# one argument

DifferentiationInterfaceTest/ext/DifferentiationInterfaceTestJLArraysExt/DifferentiationInterfaceTestJLArraysExt.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import DifferentiationInterface as DI
44
using DifferentiationInterfaceTest
55
import DifferentiationInterfaceTest as DIT
66
using JLArrays: JLArray, JLVector, JLMatrix, jl
7-
using Random: AbstractRNG, default_rng
87

98
myjl(f::Function) = f
109
function myjl(::DIT.NumToArr{A}) where {T,N,A<:AbstractArray{T,N}}

DifferentiationInterfaceTest/ext/DifferentiationInterfaceTestStaticArraysExt/DifferentiationInterfaceTestStaticArraysExt.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ module DifferentiationInterfaceTestStaticArraysExt
33
import DifferentiationInterface as DI
44
using DifferentiationInterfaceTest
55
import DifferentiationInterfaceTest as DIT
6-
using Random: AbstractRNG, default_rng
76
using SparseArrays: SparseArrays, SparseMatrixCSC, nnz, spdiagm
87
using StaticArrays: MArray, MMatrix, MVector, SArray, SMatrix, SVector
98

DifferentiationInterfaceTest/src/scenarios/allocfree.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,21 @@ function copyto!_scenarios(x::AbstractArray; dx::AbstractArray, dy::AbstractArra
4141
end
4242

4343
"""
44-
allocfree_scenarios(rng::AbstractRNG=default_rng())
44+
allocfree_scenarios()
4545
4646
Create a vector of [`Scenario`](@ref)s with functions that do not allocate.
4747
4848
!!! warning
4949
At the moment, second-order scenarios are excluded.
5050
"""
51-
function allocfree_scenarios(rng::AbstractRNG=default_rng())
52-
x_ = rand(rng)
53-
dx_ = rand(rng)
54-
dy_ = rand(rng)
51+
function allocfree_scenarios()
52+
x_ = 0.42
53+
dx_ = 3.14
54+
dy_ = -1 / 12
5555

56-
x_6 = rand(rng, 6)
57-
dx_6 = rand(rng, 6)
58-
dy_6 = rand(rng, 6)
56+
x_6 = float.(1:6)
57+
dx_6 = float.(-1:-1:-6)
58+
dy_6 = float.(-5:2:5)
5959

6060
scens = vcat(
6161
identity_scenarios(x_; dx=dx_, dy=dy_), #

DifferentiationInterfaceTest/src/scenarios/default.jl

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -448,33 +448,32 @@ end
448448
## Gather
449449

450450
"""
451-
default_scenarios(rng=Random.default_rng())
451+
default_scenarios()
452452
453453
Create a vector of [`Scenario`](@ref)s with standard array types.
454454
"""
455-
function default_scenarios(
456-
rng::AbstractRNG=default_rng();
455+
function default_scenarios(;
457456
linalg=true,
458457
include_normal=true,
459458
include_batchified=true,
460459
include_closurified=false,
461460
include_constantified=false,
462461
include_cachified=false,
463462
)
464-
x_ = rand(rng)
465-
dx_ = rand(rng)
466-
dy_ = rand(rng)
463+
x_ = 0.42
464+
dx_ = 3.14
465+
dy_ = -1 / 12
467466

468-
x_6 = rand(rng, 6)
469-
dx_6 = rand(rng, 6)
467+
x_6 = float.(1:6)
468+
dx_6 = float.(-1:-1:-6)
470469

471-
x_2_3 = rand(rng, 2, 3)
472-
dx_2_3 = rand(rng, 2, 3)
470+
x_2_3 = float.(reshape(1:6, 2, 3))
471+
dx_2_3 = float.(reshape(-1:-1:-6, 2, 3))
473472

474-
dy_6 = rand(rng, 6)
475-
dy_12 = rand(rng, 12)
476-
dy_2_3 = rand(rng, 2, 3)
477-
dy_6_2 = rand(rng, 6, 2)
473+
dy_6 = float.(-5:2:5)
474+
dy_12 = float.(-11:2:11)
475+
dy_2_3 = float.(reshape(-5:2:5, 2, 3))
476+
dy_6_2 = float.(reshape(-11:2:11, 6, 2))
478477

479478
V = Vector{Float64}
480479
M = Matrix{Float64}

DifferentiationInterfaceTest/src/scenarios/extensions.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
static_scenarios(rng=Random.default_rng())
2+
static_scenarios()
33
44
Create a vector of [`Scenario`](@ref)s with static array types from [StaticArrays.jl](https://github.com/JuliaArrays/StaticArrays.jl).
55
@@ -9,7 +9,7 @@ Create a vector of [`Scenario`](@ref)s with static array types from [StaticArray
99
function static_scenarios end
1010

1111
"""
12-
component_scenarios(rng=Random.default_rng())
12+
component_scenarios()
1313
1414
Create a vector of [`Scenario`](@ref)s with component array types from [ComponentArrays.jl](https://github.com/jonniedie/ComponentArrays.jl).
1515
@@ -19,7 +19,7 @@ Create a vector of [`Scenario`](@ref)s with component array types from [Componen
1919
function component_scenarios end
2020

2121
"""
22-
gpu_scenarios(rng=Random.default_rng())
22+
gpu_scenarios()
2323
2424
Create a vector of [`Scenario`](@ref)s with GPU array types from [JLArrays.jl](https://github.com/JuliaGPU/GPUArrays.jl/tree/master/lib/JLArrays).
2525

DifferentiationInterfaceTest/src/scenarios/sparse.jl

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -320,24 +320,26 @@ end
320320
## Gather
321321

322322
"""
323-
sparse_scenarios(rng=Random.default_rng())
323+
sparse_scenarios()
324324
325325
Create a vector of [`Scenario`](@ref)s with sparse array types, focused on sparse Jacobians and Hessians.
326326
"""
327-
function sparse_scenarios(
328-
rng::AbstractRNG=default_rng(); band_sizes=[5, 10, 20], include_constantified=false
329-
)
327+
function sparse_scenarios(; band_sizes=[5, 10, 20], include_constantified=false)
328+
x_6 = float.(1:6)
329+
x_2_3 = float.(reshape(1:6, 2, 3))
330+
x_50 = float.(1:50)
331+
330332
scens = vcat(
331-
sparse_vec_to_vec_scenarios(rand(rng, 6)),
332-
sparse_vec_to_mat_scenarios(rand(rng, 6)),
333-
sparse_mat_to_vec_scenarios(rand(rng, 2, 3)),
334-
sparse_mat_to_mat_scenarios(rand(rng, 2, 3)),
335-
sparse_vec_to_num_scenarios(rand(rng, 6)),
336-
sparse_mat_to_num_scenarios(rand(rng, 2, 3)),
333+
sparse_vec_to_vec_scenarios(x_6),
334+
sparse_vec_to_mat_scenarios(x_6),
335+
sparse_mat_to_vec_scenarios(x_2_3),
336+
sparse_mat_to_mat_scenarios(x_2_3),
337+
sparse_vec_to_num_scenarios(x_6),
338+
sparse_mat_to_num_scenarios(x_2_3),
337339
)
338340
if !isempty(band_sizes)
339-
append!(scens, squarelinearmap_scenarios(rand(rng, 50), band_sizes))
340-
append!(scens, squarequadraticform_scenarios(rand(rng, 50), band_sizes))
341+
append!(scens, squarelinearmap_scenarios(x_50, band_sizes))
342+
append!(scens, squarequadraticform_scenarios(x_50, band_sizes))
341343
end
342344
include_constantified && append!(scens, constantify(scens))
343345
return scens

DifferentiationInterfaceTest/test/standard.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ LOGGING = get(ENV, "CI", "false") == "false"
1111
## Dense
1212

1313
test_differentiation(
14-
AutoForwardDiff(),
15-
default_scenarios(Random.default_rng(); include_constantified=true);
16-
logging=LOGGING,
14+
AutoForwardDiff(), default_scenarios(; include_constantified=true); logging=LOGGING
1715
)
1816

1917
## Sparse

0 commit comments

Comments
 (0)