Skip to content
Merged
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
18 changes: 12 additions & 6 deletions src/implementations/eigh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ copy_input(::Union{typeof(eigh_trunc), typeof(eigh_trunc_no_error)}, A) = copy_i

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

check_hermiticity(::AbstractAlgorithm) = true
check_hermiticity(alg::Algorithm) = get(alg.kwargs, :check_hermiticity, true)

check_hermitian(A, ::AbstractAlgorithm) = check_hermitian(A)
check_hermitian(A, alg::Algorithm) = check_hermitian(A; atol = get(alg.kwargs, :hermitian_tol, default_hermitian_tol(A)))
function check_hermitian(A; atol::Real = default_hermitian_tol(A), rtol::Real = 0)
Expand All @@ -17,8 +20,11 @@ function check_hermitian(A; atol::Real = default_hermitian_tol(A), rtol::Real =
return nothing
end

# keyword arguments consumed by `check_input` that should not be forwarded to the drivers
_driver_kwargs(alg::Algorithm) = Base.structdiff(alg.kwargs, NamedTuple{(:check_hermiticity, :hermitian_tol)})

function check_input(::typeof(eigh_full!), A::AbstractMatrix, DV, alg::AbstractAlgorithm)
check_hermitian(A, alg)
check_hermiticity(alg) && check_hermitian(A, alg)
D, V = DV
m = size(A, 1)
@assert D isa Diagonal && V isa AbstractMatrix
Expand All @@ -29,7 +35,7 @@ function check_input(::typeof(eigh_full!), A::AbstractMatrix, DV, alg::AbstractA
return nothing
end
function check_input(::typeof(eigh_vals!), A::AbstractMatrix, D, alg::AbstractAlgorithm)
check_hermitian(A, alg)
check_hermiticity(alg) && check_hermitian(A, alg)
m = size(A, 1)
@assert D isa AbstractVector
@check_size(D, (m,))
Expand All @@ -38,7 +44,7 @@ function check_input(::typeof(eigh_vals!), A::AbstractMatrix, D, alg::AbstractAl
end

function check_input(::typeof(eigh_full!), A::AbstractMatrix, DV, alg::DiagonalAlgorithm)
check_hermitian(A, alg)
check_hermiticity(alg) && check_hermitian(A, alg)
@assert isdiag(A)
m = size(A, 1)
D, V = DV
Expand All @@ -51,7 +57,7 @@ function check_input(::typeof(eigh_full!), A::AbstractMatrix, DV, alg::DiagonalA
end

function check_input(::typeof(eigh_vals!), A::AbstractMatrix, D, alg::DiagonalAlgorithm)
check_hermitian(A, alg)
check_hermiticity(alg) && check_hermitian(A, alg)
@assert isdiag(A)
m = size(A, 1)
@assert D isa AbstractVector
Expand Down Expand Up @@ -122,12 +128,12 @@ for (f, f_lapack!, Alg) in (
@eval begin
function eigh_full!(A::AbstractMatrix, DV, alg::$Alg)
check_input(eigh_full!, A, DV, alg)
$eigh_full_f!(A, DV; alg.kwargs...)
$eigh_full_f!(A, DV; _driver_kwargs(alg)...)
return DV
end
function eigh_vals!(A::AbstractMatrix, D, alg::$Alg)
check_input(eigh_vals!, A, D, alg)
$eigh_vals_f!(A, D; alg.kwargs...)
$eigh_vals_f!(A, D; _driver_kwargs(alg)...)
return D
end
end
Expand Down
Loading