Skip to content

Stop pirating eigen and svd functions from LinearAlgebra #147

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "GenericLinearAlgebra"
uuid = "14197337-ba66-59df-a3e3-ca00e7dcff7a"
version = "0.3.15"
version = "1.0.0"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand All @@ -10,7 +10,7 @@ libblastrampoline_jll = "8e850b90-86db-534c-a0d3-1478176c7d93"

[compat]
Quaternions = "0.7.0"
julia = "1.6"
julia = "1.10"

[extras]
DoubleFloats = "497a8b3b-efae-58df-a0af-a86822472b78"
Expand Down
10 changes: 8 additions & 2 deletions src/GenericLinearAlgebra.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
module GenericLinearAlgebra

import LinearAlgebra: mul!, ldiv!
using LinearAlgebra: LinearAlgebra,
Adjoint, Bidiagonal, Diagonal, Factorization, Givens, HermOrSym, Hermitian, I, LowerTriangular,
Rotation, SVD, SymTridiagonal, Symmetric, UnitLowerTriangular, UnitUpperTriangular,
UpperTriangular,
BLAS,
abs2, axpy!, diag, dot, eigencopy_oftype, givens, ishermitian, mul!, rdiv!, tril, triu
using LinearAlgebra.BLAS: BlasFloat, BlasReal

include("juliaBLAS.jl")
include("lapack.jl")
Expand All @@ -9,6 +15,6 @@ include("householder.jl")
include("qr.jl")
include("eigenSelfAdjoint.jl")
include("eigenGeneral.jl")
include("tridiag.jl")
include("svd.jl")

end
2 changes: 0 additions & 2 deletions src/cholesky.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using LinearAlgebra: rdiv!

function cholUnblocked!(A::AbstractMatrix{T}, ::Type{Val{:L}}) where {T<:Number}
n = LinearAlgebra.checksquare(A)
A[1, 1] = sqrt(A[1, 1])
Expand Down
51 changes: 25 additions & 26 deletions src/eigenGeneral.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
using Printf
using LinearAlgebra
using LinearAlgebra: Givens, Rotation, givens

import Base: \

# Hessenberg Matrix
struct HessenbergMatrix{T,S<:StridedMatrix} <: AbstractMatrix{T}
data::S
Expand All @@ -25,17 +19,10 @@
lmul!(G, view(Hd, 1:n, i:n))
lmul!(G, B)
end
ldiv!(UpperTriangular(Hd), B)
end
(\)(H::HessenbergMatrix, B::AbstractVecOrMat) = ldiv!(copy(H), copy(B))

if VERSION < v"1.10"
# ensure tests pass on Julia v1.6
copy_similar(A::AbstractArray, ::Type{T}) where {T} = copyto!(similar(A, T, size(A)), A)
eigtype(T) = promote_type(Float32, typeof(zero(T)/sqrt(abs2(one(T)))))
eigencopy_oftype(A, S) = copy_similar(A, S)
LinearAlgebra.eigvals(A::HessenbergMatrix{T}; kws...) where T = LinearAlgebra.eigvals!(eigencopy_oftype(A, eigtype(T)); kws...)
LinearAlgebra.ldiv!(UpperTriangular(Hd), B)
end
LinearAlgebra.:\(H::HessenbergMatrix, B::AbstractVecOrMat) =
LinearAlgebra.ldiv!(copy(H), copy(B))

# Hessenberg factorization
struct HessenbergFactorization{T,S<:StridedMatrix,U} <: Factorization{T}
Expand All @@ -46,7 +33,7 @@
Base.copy(HF::HessenbergFactorization{T,S,U}) where {T,S,U} =
HessenbergFactorization{T,S,U}(copy(HF.data), copy(HF.τ))

function _hessenberg!(A::StridedMatrix{T}) where {T}
function hessenberg!(A::StridedMatrix{T}) where {T}
n = LinearAlgebra.checksquare(A)
τ = Vector{Householder{T}}(undef, n - 1)
for i = 1:n-1
Expand All @@ -59,7 +46,6 @@
end
return HessenbergFactorization{T,typeof(A),eltype(τ)}(A, τ)
end
LinearAlgebra.hessenberg!(A::StridedMatrix) = _hessenberg!(A)

Base.size(H::HessenbergFactorization, args...) = size(H.data, args...)

Expand All @@ -71,6 +57,8 @@
end
end

Base.propertynames(F::HessenbergFactorization) = (fieldnames(typeof(F))..., :H)

Check warning on line 60 in src/eigenGeneral.jl

View check run for this annotation

Codecov / codecov/patch

src/eigenGeneral.jl#L60

Added line #L60 was not covered by tests

# Schur
struct Schur{T,S<:StridedMatrix} <: Factorization{T}
data::S
Expand Down Expand Up @@ -179,10 +167,7 @@

return Schur{T,typeof(HH)}(HH, τ)
end
_schur!(A::StridedMatrix; kwargs...) = _schur!(_hessenberg!(A); kwargs...)

# FIXME! Move this method to piracy extension
LinearAlgebra.schur!(A::StridedMatrix; kwargs...) = _schur!(A; kwargs...)
schur!(A::StridedMatrix; kwargs...) = _schur!(hessenberg!(A); kwargs...)

function singleShiftQR!(
HH::StridedMatrix,
Expand Down Expand Up @@ -278,11 +263,11 @@
return HH
end

_eigvals!(A::StridedMatrix; kwargs...) = _eigvals!(_schur!(A; kwargs...))
_eigvals!(A::StridedMatrix; kwargs...) = _eigvals!(schur!(A; kwargs...))
_eigvals!(H::HessenbergMatrix; kwargs...) = _eigvals!(_schur!(H; kwargs...))
_eigvals!(H::HessenbergFactorization; kwargs...) = _eigvals!(_schur!(H; kwargs...))

function LinearAlgebra.eigvals!(
function eigvals!(
A::StridedMatrix;
sortby::Union{Function,Nothing} = LinearAlgebra.eigsortby,
kwargs...,
Expand All @@ -294,13 +279,13 @@
LinearAlgebra.sorteig!(_eigvals!(A; kwargs...), sortby)
end

LinearAlgebra.eigvals!(
eigvals!(

Check warning on line 282 in src/eigenGeneral.jl

View check run for this annotation

Codecov / codecov/patch

src/eigenGeneral.jl#L282

Added line #L282 was not covered by tests
H::HessenbergMatrix;
sortby::Union{Function,Nothing} = LinearAlgebra.eigsortby,
kwargs...,
) = LinearAlgebra.sorteig!(_eigvals!(H; kwargs...), sortby)

LinearAlgebra.eigvals!(
eigvals!(
H::HessenbergFactorization;
sortby::Union{Function,Nothing} = LinearAlgebra.eigsortby,
kwargs...,
Expand Down Expand Up @@ -338,3 +323,17 @@
end
return vals
end

## eigen!
function eigen!(
A::StridedMatrix;
sortby::Union{Function,Nothing} = LinearAlgebra.eigsortby,
kwargs...,
)

if ishermitian(A)
return eigen!(Hermitian(A); sortby)
end

throw(ArgumentError("eigen! for general matrices not yet supported. Consider using schur!"))

Check warning on line 338 in src/eigenGeneral.jl

View check run for this annotation

Codecov / codecov/patch

src/eigenGeneral.jl#L338

Added line #L338 was not covered by tests
end
Loading
Loading