Skip to content

Commit 66ba2ef

Browse files
committed
Stop pirating eigen and svd functions from LinearAlgebra
Instead, define separate unexported functions in the GenericLinearAlgebra module. Hence, users would have to explicitly opt in to using GenericLinearAlgebra. A consequence is that the implementations in this module will be used even for the element types support by LAPACK. Also, delete unused functionality.
1 parent 55a38e6 commit 66ba2ef

20 files changed

+499
-449
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "GenericLinearAlgebra"
22
uuid = "14197337-ba66-59df-a3e3-ca00e7dcff7a"
3-
version = "0.3.15"
3+
version = "1.0.0"
44

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

1111
[compat]
1212
Quaternions = "0.7.0"
13-
julia = "1.6"
13+
julia = "1.10"
1414

1515
[extras]
1616
DoubleFloats = "497a8b3b-efae-58df-a0af-a86822472b78"

src/GenericLinearAlgebra.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
module GenericLinearAlgebra
22

3-
import LinearAlgebra: mul!, ldiv!
3+
using LinearAlgebra: LinearAlgebra,
4+
Adjoint, Bidiagonal, Diagonal, Factorization, Givens, HermOrSym, Hermitian, I, LowerTriangular,
5+
Rotation, SVD, SymTridiagonal, Symmetric, UnitLowerTriangular, UnitUpperTriangular,
6+
UpperTriangular,
7+
BLAS,
8+
abs2, axpy!, diag, dot, eigencopy_oftype, givens, ishermitian, mul!, rdiv!, tril, triu
9+
using LinearAlgebra.BLAS: BlasFloat, BlasReal
410

511
include("juliaBLAS.jl")
612
include("lapack.jl")
@@ -9,6 +15,6 @@ include("householder.jl")
915
include("qr.jl")
1016
include("eigenSelfAdjoint.jl")
1117
include("eigenGeneral.jl")
12-
include("tridiag.jl")
1318
include("svd.jl")
19+
1420
end

src/cholesky.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using LinearAlgebra: rdiv!
2-
31
function cholUnblocked!(A::AbstractMatrix{T}, ::Type{Val{:L}}) where {T<:Number}
42
n = LinearAlgebra.checksquare(A)
53
A[1, 1] = sqrt(A[1, 1])

src/eigenGeneral.jl

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
using Printf
2-
using LinearAlgebra
3-
using LinearAlgebra: Givens, Rotation, givens
4-
5-
import Base: \
6-
71
# Hessenberg Matrix
82
struct HessenbergMatrix{T,S<:StridedMatrix} <: AbstractMatrix{T}
93
data::S
@@ -29,14 +23,6 @@ function LinearAlgebra.ldiv!(H::HessenbergMatrix, B::AbstractVecOrMat)
2923
end
3024
(\)(H::HessenbergMatrix, B::AbstractVecOrMat) = ldiv!(copy(H), copy(B))
3125

32-
if VERSION < v"1.10"
33-
# ensure tests pass on Julia v1.6
34-
copy_similar(A::AbstractArray, ::Type{T}) where {T} = copyto!(similar(A, T, size(A)), A)
35-
eigtype(T) = promote_type(Float32, typeof(zero(T)/sqrt(abs2(one(T)))))
36-
eigencopy_oftype(A, S) = copy_similar(A, S)
37-
LinearAlgebra.eigvals(A::HessenbergMatrix{T}; kws...) where T = LinearAlgebra.eigvals!(eigencopy_oftype(A, eigtype(T)); kws...)
38-
end
39-
4026
# Hessenberg factorization
4127
struct HessenbergFactorization{T,S<:StridedMatrix,U} <: Factorization{T}
4228
data::S
@@ -59,7 +45,7 @@ function _hessenberg!(A::StridedMatrix{T}) where {T}
5945
end
6046
return HessenbergFactorization{T,typeof(A),eltype(τ)}(A, τ)
6147
end
62-
LinearAlgebra.hessenberg!(A::StridedMatrix) = _hessenberg!(A)
48+
hessenberg!(A::StridedMatrix) = _hessenberg!(A)
6349

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

@@ -179,10 +165,7 @@ function _schur!(
179165

180166
return Schur{T,typeof(HH)}(HH, τ)
181167
end
182-
_schur!(A::StridedMatrix; kwargs...) = _schur!(_hessenberg!(A); kwargs...)
183-
184-
# FIXME! Move this method to piracy extension
185-
LinearAlgebra.schur!(A::StridedMatrix; kwargs...) = _schur!(A; kwargs...)
168+
schur!(A::StridedMatrix; kwargs...) = _schur!(_hessenberg!(A); kwargs...)
186169

187170
function singleShiftQR!(
188171
HH::StridedMatrix,
@@ -278,11 +261,11 @@ function doubleShiftQR!(
278261
return HH
279262
end
280263

281-
_eigvals!(A::StridedMatrix; kwargs...) = _eigvals!(_schur!(A; kwargs...))
264+
_eigvals!(A::StridedMatrix; kwargs...) = _eigvals!(schur!(A; kwargs...))
282265
_eigvals!(H::HessenbergMatrix; kwargs...) = _eigvals!(_schur!(H; kwargs...))
283266
_eigvals!(H::HessenbergFactorization; kwargs...) = _eigvals!(_schur!(H; kwargs...))
284267

285-
function LinearAlgebra.eigvals!(
268+
function eigvals!(
286269
A::StridedMatrix;
287270
sortby::Union{Function,Nothing} = LinearAlgebra.eigsortby,
288271
kwargs...,
@@ -294,13 +277,13 @@ function LinearAlgebra.eigvals!(
294277
LinearAlgebra.sorteig!(_eigvals!(A; kwargs...), sortby)
295278
end
296279

297-
LinearAlgebra.eigvals!(
280+
eigvals!(
298281
H::HessenbergMatrix;
299282
sortby::Union{Function,Nothing} = LinearAlgebra.eigsortby,
300283
kwargs...,
301284
) = LinearAlgebra.sorteig!(_eigvals!(H; kwargs...), sortby)
302285

303-
LinearAlgebra.eigvals!(
286+
eigvals!(
304287
H::HessenbergFactorization;
305288
sortby::Union{Function,Nothing} = LinearAlgebra.eigsortby,
306289
kwargs...,
@@ -338,3 +321,17 @@ function _eigvals!(S::Schur{T}; tol = eps(real(T))) where {T}
338321
end
339322
return vals
340323
end
324+
325+
## eigen!
326+
function eigen!(
327+
A::StridedMatrix;
328+
sortby::Union{Function,Nothing} = LinearAlgebra.eigsortby,
329+
kwargs...,
330+
)
331+
332+
if ishermitian(A)
333+
return eigen!(Hermitian(A); sortby)
334+
end
335+
336+
throw(ArgumentError("eigen! for general matrices not yet supported. Consider using schur!"))
337+
end

0 commit comments

Comments
 (0)