Skip to content
3 changes: 2 additions & 1 deletion src/LinearAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ public AbstractTriangular,
zeroslike,
matprod_dest,
fillstored!,
fillband!
fillband!,
uplo

const BlasFloat = Union{Float64,Float32,ComplexF64,ComplexF32}
const BlasReal = Union{Float64,Float32}
Expand Down
7 changes: 7 additions & 0 deletions src/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ Bidiagonal(A::Bidiagonal) = A
Bidiagonal{T}(A::Bidiagonal{T}) where {T} = A
Bidiagonal{T}(A::Bidiagonal) where {T} = Bidiagonal{T}(A.dv, A.ev, A.uplo)

"""
LinearAlgebra.uplo(S::Bidiagonal)::Symbol

Return a `Symbol` corresponding to whether the upper or lower off-diagonal band is stored.
"""
uplo(::Bidiagonal) = sym_uplo(B.uplo)

_offdiagind(uplo) = uplo == 'U' ? 1 : -1

@inline function Base.isassigned(A::Bidiagonal, i::Int, j::Int)
Expand Down
27 changes: 27 additions & 0 deletions src/symmetric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,33 @@ nonhermitianwrappertype(::SymSymTri{<:Real}) = Symmetric
nonhermitianwrappertype(::Hermitian{<:Real}) = Symmetric
nonhermitianwrappertype(::Hermitian) = identity

"""
LinearAlgebra.uplo(S::Union{Symmetric, Hermitian})::Symbol

Return a `Symbol` corresponding to the stored triangular half in the matrix `S`,
that is, the elements are common between `S` and `parent(S)` for that triangular half.

# Example
```jldoctest
julia> S = Symmetric([1 2; 3 4], :U)
2×2 Symmetric{Int64, Matrix{Int64}}:
1 2
2 4

julia> LinearAlgebra.uplo(S)
:U

julia> H = Hermitian([1 2; 3 4], :L)
2×2 Hermitian{Int64, Matrix{Int64}}:
1 3
3 4

julia> LinearAlgebra.uplo(H)
:L
```
"""
uplo(S::HermOrSym) = sym_uplo(S.uplo)

size(A::HermOrSym) = size(A.data)
axes(A::HermOrSym) = axes(A.data)
@inline function Base.isassigned(A::HermOrSym, i::Int, j::Int)
Expand Down
2 changes: 2 additions & 0 deletions test/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Random.seed!(1)
# from vectors
ubd = Bidiagonal(x, y, :U)
lbd = Bidiagonal(x, y, :L)
@test LinearAlgebra.uplo(ubd) == :U
@test LinearAlgebra.uplo(lbd) == :L
@test ubd != lbd || x === dv0
@test ubd.dv === x
@test lbd.ev === y
Expand Down
7 changes: 7 additions & 0 deletions test/symmetric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1343,4 +1343,11 @@ end
@test_throws msg LinearAlgebra.fillband!(Symmetric(A), 2, 0, 1)
end

@testset "uplo" begin
S = Symmetric([1 2; 3 4], :U)
@test LinearAlgebra.uplo(S) == :U
H = Hermitian([1 2; 3 4], :L)
@test LinearAlgebra.uplo(H) == :L
end

end # module TestSymmetric