Skip to content

Commit 60ca964

Browse files
kshyattlkdvos
andauthored
Allow not checking hermiticity in eigh functions (#321)
* Allow not checking hermiticity in eigh functions * Make check_hermiticity an alg kwarg * Restore Enzyme * Not all algs have kwargs * Formatter * Update src/implementations/eigh.jl Co-authored-by: Lukas Devos <ldevos98@gmail.com> --------- Co-authored-by: Lukas Devos <ldevos98@gmail.com>
1 parent 2ecf979 commit 60ca964

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

‎src/implementations/eigh.jl‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ copy_input(::Union{typeof(eigh_trunc), typeof(eigh_trunc_no_error)}, A) = copy_i
88

99
copy_input(::typeof(eigh_full), A::Diagonal) = copy(A)
1010

11+
check_hermiticity(::AbstractAlgorithm) = true
12+
check_hermiticity(alg::Algorithm) = get(alg.kwargs, :check_hermiticity, true)
13+
1114
check_hermitian(A, ::AbstractAlgorithm) = check_hermitian(A)
1215
check_hermitian(A, alg::Algorithm) = check_hermitian(A; atol = get(alg.kwargs, :hermitian_tol, default_hermitian_tol(A)))
1316
function check_hermitian(A; atol::Real = default_hermitian_tol(A), rtol::Real = 0)
@@ -17,8 +20,11 @@ function check_hermitian(A; atol::Real = default_hermitian_tol(A), rtol::Real =
1720
return nothing
1821
end
1922

23+
# keyword arguments consumed by `check_input` that should not be forwarded to the drivers
24+
_driver_kwargs(alg::Algorithm) = Base.structdiff(alg.kwargs, NamedTuple{(:check_hermiticity, :hermitian_tol)})
25+
2026
function check_input(::typeof(eigh_full!), A::AbstractMatrix, DV, alg::AbstractAlgorithm)
21-
check_hermitian(A, alg)
27+
check_hermiticity(alg) && check_hermitian(A, alg)
2228
D, V = DV
2329
m = size(A, 1)
2430
@assert D isa Diagonal && V isa AbstractMatrix
@@ -29,7 +35,7 @@ function check_input(::typeof(eigh_full!), A::AbstractMatrix, DV, alg::AbstractA
2935
return nothing
3036
end
3137
function check_input(::typeof(eigh_vals!), A::AbstractMatrix, D, alg::AbstractAlgorithm)
32-
check_hermitian(A, alg)
38+
check_hermiticity(alg) && check_hermitian(A, alg)
3339
m = size(A, 1)
3440
@assert D isa AbstractVector
3541
@check_size(D, (m,))
@@ -38,7 +44,7 @@ function check_input(::typeof(eigh_vals!), A::AbstractMatrix, D, alg::AbstractAl
3844
end
3945

4046
function check_input(::typeof(eigh_full!), A::AbstractMatrix, DV, alg::DiagonalAlgorithm)
41-
check_hermitian(A, alg)
47+
check_hermiticity(alg) && check_hermitian(A, alg)
4248
@assert isdiag(A)
4349
m = size(A, 1)
4450
D, V = DV
@@ -51,7 +57,7 @@ function check_input(::typeof(eigh_full!), A::AbstractMatrix, DV, alg::DiagonalA
5157
end
5258

5359
function check_input(::typeof(eigh_vals!), A::AbstractMatrix, D, alg::DiagonalAlgorithm)
54-
check_hermitian(A, alg)
60+
check_hermiticity(alg) && check_hermitian(A, alg)
5561
@assert isdiag(A)
5662
m = size(A, 1)
5763
@assert D isa AbstractVector
@@ -122,12 +128,12 @@ for (f, f_lapack!, Alg) in (
122128
@eval begin
123129
function eigh_full!(A::AbstractMatrix, DV, alg::$Alg)
124130
check_input(eigh_full!, A, DV, alg)
125-
$eigh_full_f!(A, DV; alg.kwargs...)
131+
$eigh_full_f!(A, DV; _driver_kwargs(alg)...)
126132
return DV
127133
end
128134
function eigh_vals!(A::AbstractMatrix, D, alg::$Alg)
129135
check_input(eigh_vals!, A, D, alg)
130-
$eigh_vals_f!(A, D; alg.kwargs...)
136+
$eigh_vals_f!(A, D; _driver_kwargs(alg)...)
131137
return D
132138
end
133139
end

0 commit comments

Comments
 (0)