Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update LinearAlgebra for Julia v1.2 and v1.3 #11

Merged
merged 3 commits into from
Jul 29, 2019
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 .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ os:
julia:
- 1.0
- 1.1
- 1.2
- nightly
matrix:
allow_failures:
Expand Down
33 changes: 22 additions & 11 deletions src/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,31 @@ LinearAlgebra.logdet(B::BlockDiagonal) = sum(logdet, blocks(B))
LinearAlgebra.tr(B::BlockDiagonal) = sum(tr, blocks(B))

# Real matrices can have Complex eigenvalues; `eigvals` is not type stable.
function LinearAlgebra.eigvals(B::BlockDiagonal; kwargs...)
# Currently no convention for sorting eigenvalues.
# This may change in later a Julia version https://github.com/JuliaLang/julia/pull/21598
return mapreduce(b -> eigvals(b; kwargs...), vcat, blocks(B))
if VERSION < v"1.2.0-DEV.275"
# No convention for sorting eigenvalues in earlier versions of Julia.
function LinearAlgebra.eigvals(B::BlockDiagonal; kwargs...)
return mapreduce(b -> eigvals(b; kwargs...), vcat, blocks(B))
end
else
# Sorting was introduced in Julia v1.2 by https://github.com/JuliaLang/julia/pull/21598
function LinearAlgebra.eigvals(
B::BlockDiagonal; sortby::Union{Function, Nothing}=LinearAlgebra.eigsortby, kwargs...
)
vals = mapreduce(b -> eigvals(b; kwargs...), vcat, blocks(B))
return LinearAlgebra.sorteig!(vals, sortby)
end
end

# This is copy of the definition for LinearAlgebra.
# Should not be needed once we fix https://github.com/JuliaLang/julia/issues/31843
function LinearAlgebra.eigmax(B::BlockDiagonal; kwargs...)
v = eigvals(B; kwargs...)
if eltype(v) <: Complex
throw(DomainError(A, "`A` cannot have complex eigenvalues."))
if VERSION < v"1.3.0-DEV.426"
# This is copy of the definition for LinearAlgebra, only used to workaround
# https://github.com/JuliaLang/julia/issues/31843 which was fixed in Julia v1.3
function LinearAlgebra.eigmax(B::BlockDiagonal; kwargs...)
v = eigvals(B; kwargs...)
if eltype(v) <: Complex
throw(DomainError(A, "`A` cannot have complex eigenvalues."))
end
return maximum(v)
end
return maximum(v)
end

svdvals_blockwise(B::BlockDiagonal) = mapreduce(svdvals, vcat, blocks(B))
Expand Down