From 3e25bd941c0a978345b54c72475d4fa9e5e168a7 Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlson Date: Wed, 11 Nov 2026 11:43:00 +0000 Subject: [PATCH] Return a Diagonal from rand of a diagonal uncertainty matrix Broadcasting rand over a Diagonal returns a dense Matrix on Julia 1.10 and a Diagonal on Julia 1.13, so the result type of rand(D, N) depended on the Julia version and test_uncertainty.jl failed on 1.13. A dedicated method now returns a Diagonal on all versions. Julia 1 is added to the CI matrix. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/CI.yml | 2 +- src/uncertainty_interface.jl | 2 ++ test/test_uncertainty.jl | 4 +++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 5dd8e86f..6a17efa1 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -5,7 +5,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - julia-version: ['1.10'] + julia-version: ['1.10', '1'] os: [ubuntu-latest] steps: - uses: actions/checkout@v2 diff --git a/src/uncertainty_interface.jl b/src/uncertainty_interface.jl index 8209bb3c..f851dbd4 100644 --- a/src/uncertainty_interface.jl +++ b/src/uncertainty_interface.jl @@ -414,6 +414,8 @@ function Base.rand(D::AbstractArray{<:δ}, N::Int) T.(M) end +Base.rand(D::Diagonal{<:δ}, N::Int) = Diagonal(rand(D.diag, N)) + function Base.rand(d::δ{Complex{F}}, N::Int) where F T = float(F) d.radius == 0 && return Particles(fill(T(d.val), N)) diff --git a/test/test_uncertainty.jl b/test/test_uncertainty.jl index abe33b0b..1e7f536c 100644 --- a/test/test_uncertainty.jl +++ b/test/test_uncertainty.jl @@ -39,7 +39,9 @@ sys = uss(d) D = RobustAndOptimalControl.Δ(2, δc) -@test rand(D, 100) isa Matrix{Complex{Particles{Float64, 100}}} +Dr = rand(D, 100) +@test Dr isa Diagonal{Complex{Particles{Float64, 100}}} +@test iszero(Dr[1, 2])