Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions src/factorizations/factorizations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ function MAK.isantihermitian(t::AbstractTensorMap; kwargs...)
end
LinearAlgebra.ishermitian(t::AbstractTensorMap) = MAK.ishermitian(t)

function LinearAlgebra.checksquare(t::AbstractTensorMap)
Comment thread
lkdvos marked this conversation as resolved.
dom = domain(t)
cod = codomain(t)
dom == cod || throw(SpaceMismatch(lazy"tensor is not square: codomain $cod ≠ domain $cod"))
Comment thread
lkdvos marked this conversation as resolved.
return dom
end

function LinearAlgebra.isposdef(t::AbstractTensorMap)
return isposdef!(copy_oftype(t, factorisation_scalartype(isposdef, t)))
end
Expand Down
2 changes: 2 additions & 0 deletions src/factorizations/matrixalgebrakit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ for f! in (
:left_polar!, :right_polar!,
)
@eval function MAK.$f!(t::AbstractTensorMap, F, alg::AbstractAlgorithm)
$(f! in (:eig_full!, :eigh_full!) && :(LinearAlgebra.checksquare(t)))
foreachblock(t, F...) do _, (tblock, Fblocks...)
Fblocks′ = $f!(tblock, Fblocks, alg)
# deal with the case where the output is not in-place
Expand All @@ -50,6 +51,7 @@ for f! in (
:project_hermitian!, :project_antihermitian!, :project_isometric!,
)
@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
Expand Down
7 changes: 7 additions & 0 deletions test/factorizations/projections.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ for V in spacelist
@test !isantihermitian(ta_approx)
@test isantihermitian(ta_approx; atol = 10 * noisefactor) || (T <: Real && t isa DiagonalTensorMap)
end

@test_throws SpaceMismatch project_hermitian(rand(V1, V1^2))
@test_throws SpaceMismatch project_antihermitian(rand(V1, V1^2))
if V1 != V1'
@test_throws SpaceMismatch project_hermitian(rand(V1, V1'))
@test_throws SpaceMismatch project_antihermitian(rand(V1, V1'))
end
end

@testset "Isometric projections" begin
Expand Down
Loading