Skip to content

Commit 6b1fa57

Browse files
committed
change default function interfaces
1 parent d4af0af commit 6b1fa57

7 files changed

Lines changed: 48 additions & 104 deletions

File tree

src/interface/eig.jl

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -87,27 +87,18 @@ See also [`eig_full(!)`](@ref eig_full) and [`eig_trunc(!)`](@ref eig_trunc).
8787

8888
# Algorithm selection
8989
# -------------------
90-
for f in (:eig_full, :eig_vals)
91-
f! = Symbol(f, :!)
92-
@eval begin
93-
function default_algorithm(::typeof($f), A; kwargs...)
94-
return default_algorithm($f!, A; kwargs...)
95-
end
96-
function default_algorithm(::typeof($f!), A; kwargs...)
97-
return default_eig_algorithm(A; kwargs...)
98-
end
99-
end
90+
# Default to LAPACK for `StridedMatrix{<:BlasFloat}`
91+
function default_algorithm(::typeof(eig_full!), ::Type{A};
92+
kwargs...) where {A<:StridedMatrix{<:BlasFloat}}
93+
return LAPACK_Expert(; kwargs...)
10094
end
101-
102-
function select_algorithm(::typeof(eig_trunc), A, alg; kwargs...)
103-
return select_algorithm(eig_trunc!, A, alg; kwargs...)
95+
function default_algorithm(::typeof(eig_vals!), ::Type{A};
96+
kwargs...) where {A<:StridedMatrix{<:BlasFloat}}
97+
return LAPACK_Expert(; kwargs...)
10498
end
105-
function select_algorithm(::typeof(eig_trunc!), A, alg; trunc=nothing, kwargs...)
99+
100+
function select_algorithm(::typeof(eig_trunc!), ::Type{A}, alg; trunc=nothing,
101+
kwargs...) where {A<:StridedMatrix{<:BlasFloat}}
106102
alg_eig = select_algorithm(eig_full!, A, alg; kwargs...)
107103
return TruncatedAlgorithm(alg_eig, select_truncation(trunc))
108104
end
109-
110-
# Default to LAPACK
111-
function default_eig_algorithm(A::StridedMatrix{<:BlasFloat}; kwargs...)
112-
return LAPACK_Expert(; kwargs...)
113-
end

src/interface/eigh.jl

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -86,27 +86,18 @@ See also [`eigh_full(!)`](@ref eigh_full) and [`eigh_trunc(!)`](@ref eigh_trunc)
8686

8787
# Algorithm selection
8888
# -------------------
89-
for f in (:eigh_full, :eigh_vals)
90-
f! = Symbol(f, :!)
91-
@eval begin
92-
function default_algorithm(::typeof($f), A; kwargs...)
93-
return default_algorithm($f!, A; kwargs...)
94-
end
95-
function default_algorithm(::typeof($f!), A; kwargs...)
96-
return default_eigh_algorithm(A; kwargs...)
97-
end
98-
end
89+
# Default to LAPACK for `StridedMatrix{<:BlasFloat}`
90+
function default_algorithm(::typeof(eigh_full!), ::Type{A};
91+
kwargs...) where {A<:StridedMatrix{<:BlasFloat}}
92+
return LAPACK_MultipleRelativelyRobustRepresentations(; kwargs...)
9993
end
100-
101-
function select_algorithm(::typeof(eigh_trunc), A, alg; kwargs...)
102-
return select_algorithm(eigh_trunc!, A, alg; kwargs...)
94+
function default_algorithm(::typeof(eigh_vals!), ::Type{A};
95+
kwargs...) where {A<:StridedMatrix{<:BlasFloat}}
96+
return LAPACK_MultipleRelativelyRobustRepresentations(; kwargs...)
10397
end
104-
function select_algorithm(::typeof(eigh_trunc!), A, alg; trunc=nothing, kwargs...)
98+
99+
function select_algorithm(::typeof(eigh_trunc!), ::Type{A}, alg; trunc=nothing,
100+
kwargs...) where {A<:StridedMatrix{<:BlasFloat}}
105101
alg_eigh = select_algorithm(eigh_full!, A, alg; kwargs...)
106102
return TruncatedAlgorithm(alg_eigh, select_truncation(trunc))
107103
end
108-
109-
# Default to LAPACK
110-
function default_eigh_algorithm(A::StridedMatrix{T}; kwargs...) where {T<:BlasFloat}
111-
return LAPACK_MultipleRelativelyRobustRepresentations(; kwargs...)
112-
end

src/interface/lq.jl

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,11 @@ See also [`qr_full(!)`](@ref lq_full) and [`qr_compact(!)`](@ref lq_compact).
6868

6969
# Algorithm selection
7070
# -------------------
71-
for f in (:lq_full, :lq_compact, :lq_null)
72-
f! = Symbol(f, :!)
71+
for f in (:lq_full!, :lq_compact!, :lq_null!)
7372
@eval begin
74-
function default_algorithm(::typeof($f), A; kwargs...)
75-
return default_algorithm($f!, A; kwargs...)
76-
end
77-
function default_algorithm(::typeof($f!), A; kwargs...)
78-
return default_lq_algorithm(A; kwargs...)
73+
function default_algorithm(::typeof($f), ::Type{A};
74+
kwargs...) where {A<:StridedMatrix{<:BlasFloat}}
75+
return LAPACK_HouseholderLQ(; kwargs...)
7976
end
8077
end
8178
end
82-
83-
# Default to LAPACK
84-
function default_lq_algorithm(A::StridedMatrix{<:BlasFloat}; kwargs...)
85-
return LAPACK_HouseholderLQ(; kwargs...)
86-
end

src/interface/polar.jl

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,11 @@ end
6060

6161
# Algorithm selection
6262
# -------------------
63-
for f in (:left_polar, :right_polar)
64-
f! = Symbol(f, :!)
65-
@eval begin
66-
function default_algorithm(::typeof($f), A; kwargs...)
67-
return default_algorithm($f!, A; kwargs...)
63+
function default_algorithm(::typeof(left_polar!), ::Type{A};
64+
kwargs...) where {A<:StridedMatrix{<:BlasFloat}}
65+
return PolarViaSVD(default_algorithm(svd_compact!, A; kwargs...))
6866
end
69-
function default_algorithm(::typeof($f!), A; kwargs...)
70-
return default_polar_algorithm(A; kwargs...)
71-
end
72-
end
73-
end
74-
75-
# Default to LAPACK SDD for `StridedMatrix{<:BlasFloat}`
76-
function default_polar_algorithm(A::StridedMatrix{<:BlasFloat}; kwargs...)
77-
return PolarViaSVD(default_svd_algorithm(A; kwargs...))
67+
function default_algorithm(::typeof(right_polar!), ::Type{A};
68+
kwargs...) where {A<:StridedMatrix{<:BlasFloat}}
69+
return PolarViaSVD(default_algorithm(svd_compact!, A; kwargs...))
7870
end

src/interface/qr.jl

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,11 @@ See also [`lq_full(!)`](@ref lq_full) and [`lq_compact(!)`](@ref lq_compact).
6868

6969
# Algorithm selection
7070
# -------------------
71-
for f in (:qr_full, :qr_compact, :qr_null)
72-
f! = Symbol(f, :!)
71+
for f in (:qr_full!, :qr_compact!, :qr_null!)
7372
@eval begin
74-
function default_algorithm(::typeof($f), A; kwargs...)
75-
return default_algorithm($f!, A; kwargs...)
76-
end
77-
function default_algorithm(::typeof($f!), A; kwargs...)
78-
return default_qr_algorithm(A; kwargs...)
73+
function default_algorithm(::typeof($f), ::Type{A};
74+
kwargs...) where {A<:StridedMatrix{<:BlasFloat}}
75+
return LAPACK_HouseholderQR(; kwargs...)
7976
end
8077
end
8178
end
82-
83-
# Default to LAPACK
84-
function default_qr_algorithm(A::StridedMatrix{<:BlasFloat}; kwargs...)
85-
return LAPACK_HouseholderQR(; kwargs...)
86-
end

src/interface/schur.jl

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,11 @@ See also [`eig_full(!)`](@ref eig_full) and [`eig_trunc(!)`](@ref eig_trunc).
5151

5252
# Algorithm selection
5353
# -------------------
54-
for f in (:schur_full, :schur_vals)
55-
f! = Symbol(f, :!)
56-
@eval begin
57-
function default_algorithm(::typeof($f), A; kwargs...)
58-
return default_algorithm($f!, A; kwargs...)
59-
end
60-
function default_algorithm(::typeof($f!), A; kwargs...)
61-
return default_eig_algorithm(A; kwargs...)
62-
end
63-
end
54+
function default_algorithm(::typeof(schur_full!), ::Type{A};
55+
kwargs...) where {A<:StridedMatrix{<:BlasFloat}}
56+
return default_algorithm(eig_full!, A; kwargs...)
57+
end
58+
function default_algorithm(::typeof(schur_vals!), ::Type{A};
59+
kwargs...) where {A<:StridedMatrix{<:BlasFloat}}
60+
return default_algorithm(eig_vals!, A; kwargs...)
6461
end

src/interface/svd.jl

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,27 +90,16 @@ See also [`svd_full(!)`](@ref svd_full), [`svd_compact(!)`](@ref svd_compact) an
9090

9191
# Algorithm selection
9292
# -------------------
93-
for f in (:svd_full, :svd_compact, :svd_vals)
94-
f! = Symbol(f, :!)
95-
@eval begin
96-
function default_algorithm(::typeof($f), A; kwargs...)
97-
return default_algorithm($f!, A; kwargs...)
98-
end
99-
function default_algorithm(::typeof($f!), A; kwargs...)
100-
return default_svd_algorithm(A; kwargs...)
101-
end
93+
for f in (:svd_full!, :svd_compact!, :svd_vals!)
94+
# Default to LAPACK SDD for `StridedMatrix{<:BlasFloat}`
95+
@eval function default_algorithm(::typeof($f), ::Type{A};
96+
kwargs...) where {A<:StridedMatrix{<:BlasFloat}}
97+
return LAPACK_DivideAndConquer(; kwargs...)
10298
end
10399
end
104100

105-
function select_algorithm(::typeof(svd_trunc), A, alg; kwargs...)
106-
return select_algorithm(svd_trunc!, A, alg; kwargs...)
107-
end
108-
function select_algorithm(::typeof(svd_trunc!), A, alg; trunc=nothing, kwargs...)
101+
function select_algorithm(::typeof(svd_trunc!), ::Type{A}, alg; trunc=nothing,
102+
kwargs...) where {A<:StridedMatrix{<:BlasFloat}}
109103
alg_svd = select_algorithm(svd_compact!, A, alg; kwargs...)
110104
return TruncatedAlgorithm(alg_svd, select_truncation(trunc))
111105
end
112-
113-
# Default to LAPACK SDD for `StridedMatrix{<:BlasFloat}`
114-
function default_svd_algorithm(A::StridedMatrix{<:BlasFloat}; kwargs...)
115-
return LAPACK_DivideAndConquer(; kwargs...)
116-
end

0 commit comments

Comments
 (0)