Skip to content

Commit 427b575

Browse files
authored
Enable generation of well-conditioned complex matrices (#47)
* Add complex well-conditioned matrices * Increment version number
1 parent 171ff19 commit 427b575

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ChainRulesTestUtils"
22
uuid = "cdddcdb0-9152-4a09-a978-84456f9df70a"
3-
version = "0.4.0"
3+
version = "0.4.1"
44

55
[deps]
66
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"

src/data_generation.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
# Useful for LinearAlgebra tests
2-
function generate_well_conditioned_matrix(rng, N)
3-
A = randn(rng, N, N)
2+
function generate_well_conditioned_matrix(rng::AbstractRNG, T, N)
3+
A = randn(rng, T, N, N)
44
return A * A' + I
55
end
66

7-
generate_well_conditioned_matrix(N) = generate_well_conditioned_matrix(Random.GLOBAL_RNG, N)
7+
function generate_well_conditioned_matrix(rng::AbstractRNG, N)
8+
return generate_well_conditioned_matrix(rng, Float64, N)
9+
end
10+
11+
generate_well_conditioned_matrix(N) = generate_well_conditioned_matrix(Random.GLOBAL_RNG, N)
12+
13+
function generate_well_conditioned_matrix(T, N)
14+
return generate_well_conditioned_matrix(Random.GLOBAL_RNG, T, N)
15+
end

test/data_generation.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,28 @@
22
function _is_well_conditioned(matrix)
33
@test !isempty(matrix)
44
@test isposdef(matrix)
5-
@assert length(matrix) 25
5+
@assert length(matrix) 25
66
@test cond(matrix) < 100
77
end
88

99

1010
@testset "Generate Well Conditioned Matrix" begin
11+
rng = MersenneTwister(1)
1112
@testset "Pass in RNG" begin
12-
rng = MersenneTwister(1)
1313
matrix = generate_well_conditioned_matrix(rng, 5)
14-
1514
_is_well_conditioned(matrix)
15+
@testset "$T" for T in (Float64, ComplexF64)
16+
matrix = generate_well_conditioned_matrix(rng, T, 5)
17+
_is_well_conditioned(matrix)
18+
end
1619
end
1720

1821
@testset "Global RNG" begin
1922
matrix = generate_well_conditioned_matrix(5)
20-
2123
_is_well_conditioned(matrix)
24+
@testset "$T" for T in (Float64, ComplexF64)
25+
matrix = generate_well_conditioned_matrix(T, 5)
26+
end
2227
end
2328
end
2429
end

0 commit comments

Comments
 (0)