Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ LinearAlgebra.hermitianpart
LinearAlgebra.hermitianpart!
LinearAlgebra.copy_adjoint!
LinearAlgebra.copy_transpose!
LinearAlgebra.uplo
```

## Low-level matrix operations
Expand Down
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 (`:U`) or lower (`:L`) off-diagonal band is stored.
"""
uplo(B::Bidiagonal) = sym_uplo(B.uplo)

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

@inline function Base.isassigned(A::Bidiagonal, i::Int, j::Int)
Expand Down
35 changes: 35 additions & 0 deletions src/symmetric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ if any specialized algorithms.)
To compute the symmetric part of a real matrix, or more generally the Hermitian part `(A + A') / 2` of
a real or complex matrix `A`, use [`hermitianpart`](@ref).

The `uplo` symbol corresponding to the triangular half of `A` that is shared by the symmetric view may be
fetched by using the function [`LinearAlgebra.uplo`](@ref). The underlying matrix `A` may be fetched from the symmetric
view by using `parent`.

# Examples
```jldoctest
julia> A = [1 2 3; 4 5 6; 7 8 9]
Expand Down Expand Up @@ -112,6 +116,10 @@ triangle of the matrix `A`.

To compute the Hermitian part of `A`, use [`hermitianpart`](@ref).

The `uplo` symbol corresponding to the triangular half of `A` that is shared by the hermitian view may be
fetched by using the function [`LinearAlgebra.uplo`](@ref). The underlying matrix `A` may be fetched from the hermitian
view by using `parent`.

# Examples
```jldoctest
julia> A = [1 2+2im 3-3im; 4 5 6-6im; 7 8+8im 9]
Expand Down Expand Up @@ -237,6 +245,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 (`:U` or `:L`) 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