Skip to content

Commit

Permalink
Merge pull request #11 from invenia/npr/newer-julia
Browse files Browse the repository at this point in the history
Update LinearAlgebra for Julia v1.2 and v1.3
  • Loading branch information
nickrobinson251 authored Jul 29, 2019
2 parents cd84d72 + 5a45178 commit f374931
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
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

2 comments on commit f374931

@nickrobinson251
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/2364

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.0 -m "<description of version>" f374931fbe4e76a391ddd2ef19a9d44eff0e8f83
git push origin v0.1.0

Please sign in to comment.