Skip to content

Commit 560276b

Browse files
authored
Char uplo in Bidiagonal constructor (#1342)
This is an internal constructor, but many methods involving `Bidiagonal` matrices currently use the `Char` `uplo` directly to construct a new `Bidiagonal` matrix. We therefore may require the constructors to accept a `Char` as well, wherever they accept a `Symbol`. This already works for some of the `Bidiagonal` constructors, and this PR plugs a missing case. Fixes issues like ```julia julia> B = Bidiagonal(fill(SMatrix{2,3}(1:6), 4), fill(SMatrix{1,3}(1:3), 3), :L) 4×4 Bidiagonal{StaticArraysCore.SArray{S, Int64, 2} where S<:Tuple, Vector{StaticArraysCore.SArray{S, Int64, 2} where S<:Tuple}}: [1 3 5; 2 4 6] ⋅ ⋅ ⋅ [1 2 3] [1 3 5; 2 4 6] ⋅ ⋅ ⋅ [1 2 3] [1 3 5; 2 4 6] ⋅ ⋅ ⋅ [1 2 3] [1 3 5; 2 4 6] julia> 2B ERROR: MethodError: no method matching Bidiagonal(::Vector{SMatrix{2, 3, Int64, 6}}, ::Vector{SMatrix{1, 3, Int64, 3}}, ::Char) The type `Bidiagonal` exists, but no method is defined for this combination of argument types when trying to construct it. Closest candidates are: Bidiagonal(::Vector{T}, ::Vector{S}, ::Symbol) where {T, S} @ LinearAlgebra ~/Dropbox/JuliaPackages/LinearAlgebra_2.jl/src/bidiag.jl:77 Bidiagonal(::V, ::V, ::AbstractChar) where {T, V<:AbstractVector{T}} @ LinearAlgebra ~/Dropbox/JuliaPackages/LinearAlgebra_2.jl/src/bidiag.jl:71 Bidiagonal(::V, ::V, ::Symbol) where {T, V<:AbstractVector{T}} @ LinearAlgebra ~/Dropbox/JuliaPackages/LinearAlgebra_2.jl/src/bidiag.jl:68 ... ``` After this, ```julia julia> 2B 4×4 Bidiagonal{StaticArraysCore.SArray{S, Int64, 2} where S<:Tuple, Vector{StaticArraysCore.SArray{S, Int64, 2} where S<:Tuple}}: [2 6 10; 4 8 12] ⋅ ⋅ ⋅ [2 4 6] [2 6 10; 4 8 12] ⋅ ⋅ ⋅ [2 4 6] [2 6 10; 4 8 12] ⋅ ⋅ ⋅ [2 4 6] [2 6 10; 4 8 12] ``` We may require that each method passes a `Symbol` as `uplo`, but this would be a much larger change, and the current approach seems to be less disruptive.
1 parent 58003a5 commit 560276b

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/bidiag.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,13 @@ julia> Bl = Bidiagonal(dv, ev, :L) # ev is on the first subdiagonal
6565
⋅ ⋅ 9 4
6666
```
6767
"""
68-
function Bidiagonal(dv::V, ev::V, uplo::Symbol) where {T,V<:AbstractVector{T}}
69-
Bidiagonal{T,V}(dv, ev, uplo)
70-
end
71-
function Bidiagonal(dv::V, ev::V, uplo::AbstractChar) where {T,V<:AbstractVector{T}}
68+
function Bidiagonal(dv::V, ev::V, uplo::Union{Symbol, AbstractChar}) where {T,V<:AbstractVector{T}}
7269
Bidiagonal{T,V}(dv, ev, uplo)
7370
end
7471

7572
#To allow Bidiagonal's where the "dv" is Vector{T} and "ev" Vector{S},
7673
#where T and S can be promoted
77-
function Bidiagonal(dv::Vector{T}, ev::Vector{S}, uplo::Symbol) where {T,S}
74+
function Bidiagonal(dv::Vector{T}, ev::Vector{S}, uplo::Union{Symbol, AbstractChar}) where {T,S}
7875
TS = promote_type(T,S)
7976
return Bidiagonal{TS,Vector{TS}}(dv, ev, uplo)
8077
end

test/bidiag.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,10 @@ Random.seed!(1)
512512
@test Matrix{ComplexF64}(BD) == BD
513513
end
514514

515+
@testset "Constructors with Char uplo" begin
516+
@test Bidiagonal(Int8[1,2], [1], 'U') == Bidiagonal(Int8[1,2], [1], :U)
517+
end
518+
515519
# Issue 10742 and similar
516520
let A = Bidiagonal([1,2,3], [0,0], :U)
517521
@test istril(A)

0 commit comments

Comments
 (0)