Skip to content

restrict types diagonal#253

Open
sanderdemeyer wants to merge 5 commits into
QuantumKitHub:mainfrom
sanderdemeyer:exp_new
Open

restrict types diagonal#253
sanderdemeyer wants to merge 5 commits into
QuantumKitHub:mainfrom
sanderdemeyer:exp_new

Conversation

@sanderdemeyer

@sanderdemeyer sanderdemeyer commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

This is another type restriction (see #252) to make sure the exponential in TensorKit will be implemented correctly (see QuantumKitHub/TensorKit.jl#465). If I don't restrict these types, it will be ambiguous with this function in TensorKit (src/factorizations/matrixalgebrakit.jl).

for f! in (
        :qr_null!, :lq_null!,
        :svd_vals!, :eig_vals!, :eigh_vals!,
        :project_hermitian!, :project_antihermitian!, :project_isometric!,
        :exponential!,
    )
    @eval function MAK.$f!(t::AbstractTensorMap, N, alg::AbstractAlgorithm)
        $(f! in (:eig_vals!, :eigh_vals!, :project_hermitian!, :project_antihermitian!) && :(LinearAlgebra.checksquare(t)))
        foreachblock(t, N) do _, (tblock, Nblock)
            Nblock′ = $f!(tblock, Nblock, alg)
            # deal with the case where the output is not the same as the input
            Nblock === Nblock′ || copy!(Nblock, Nblock′)
            return nothing
        end
        return N
    end
end

@lkdvos lkdvos left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did a quick search throughout the codebase, and it seems like except for svd_compact, we always combine DiagonalAlgorithm with AbstractMatrix, so this is consistent with most of it.

Comment thread src/implementations/exponential.jl Outdated
Comment on lines +46 to +47
exponential!(t::Tuple{E, T}, ::DefaultAlgorithm) where {E <: Number, T <: Diagonal} = MAK.exponential!(t, DiagonalAlgorithm())
exponential!(t::Tuple{E, T1}, out::T2, ::DefaultAlgorithm) where {E <: Number, T1 <: Diagonal, T2 <: Diagonal} = MAK.exponential!(t, out, DiagonalAlgorithm())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the idea here is rather to make this go back to the default algorithm selection procedure, see all factorizations for examples: e.g.

for f! in (:lq_full!, :lq_compact!, :lq_null!)
@eval function $f!(A::AbstractMatrix, alg::DefaultAlgorithm)
return $f!(A, select_algorithm($f!, A, nothing; alg.kwargs...))
end
@eval function $f!(A::AbstractMatrix, out, alg::DefaultAlgorithm)
return $f!(A, out, select_algorithm($f!, A, nothing; alg.kwargs...))
end
end

(Also, this should not only be for Diagonal, but for AbstractMatrix instead.

@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.33333% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/implementations/exponential.jl 33.33% 2 Missing ⚠️
Files with missing lines Coverage Δ
src/implementations/exponential.jl 97.18% <33.33%> (-2.82%) ⬇️

... and 23 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread src/implementations/exponential.jl Outdated
Co-authored-by: Lukas Devos <ldevos98@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants