Skip to content

Commit 2008192

Browse files
Jutholkdvos
authored andcommitted
some changes
1 parent 6074c79 commit 2008192

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

src/factorizations/factorizations.jl

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,21 @@ LinearAlgebra.svdvals!(t::AbstractTensorMap) = diagview(svd_vals!(t))
5555
#--------------------------------------------------#
5656
# Checks for hermiticity and positive definiteness #
5757
#--------------------------------------------------#
58+
function _blockmap(f; kwargs...)
59+
return function ((c, b))
60+
return f(b; kwargs...)
61+
end
62+
end
63+
5864
function MAK.ishermitian(t::AbstractTensorMap; kwargs...)
5965
return InnerProductStyle(t) === EuclideanInnerProduct() &&
60-
domain(t) == codomain(t) &&
61-
all(cb -> MAK.ishermitian(cb[2]; kwargs...), blocks(t))
66+
domain(t) == codomain(t) &&
67+
all(_blockmap(MAK.ishermitian; kwargs...), blocks(t))
6268
end
6369
function MAK.isantihermitian(t::AbstractTensorMap; kwargs...)
6470
return InnerProductStyle(t) === EuclideanInnerProduct() &&
65-
domain(t) == codomain(t) &&
66-
all(cb -> MAK.isantihermitian(cb[2]; kwargs...), blocks(t))
71+
domain(t) == codomain(t) &&
72+
all(_blockmap(MAK.isantihermitian; kwargs...), blocks(t))
6773
end
6874
LinearAlgebra.ishermitian(t::AbstractTensorMap) = MAK.ishermitian(t)
6975

@@ -74,22 +80,17 @@ function LinearAlgebra.isposdef!(t::AbstractTensorMap)
7480
domain(t) == codomain(t) ||
7581
throw(SpaceMismatch("`isposdef` requires domain and codomain to be the same"))
7682
InnerProductStyle(spacetype(t)) === EuclideanInnerProduct() || return false
77-
for (c, b) in blocks(t)
78-
isposdef!(b) || return false
79-
end
80-
return true
83+
return all(_blockmap(isposdef!), blocks(t))
8184
end
8285

8386
# TODO: tolerances are per-block, not global or weighted - does that matter?
8487
function MAK.is_left_isometric(t::AbstractTensorMap; kwargs...)
8588
domain(t) codomain(t) || return false
86-
f((c, b)) = MAK.is_left_isometric(b; kwargs...)
87-
return all(f, blocks(t))
89+
return all(_blockmap(MAK.is_left_isometric; kwargs...), blocks(t))
8890
end
8991
function MAK.is_right_isometric(t::AbstractTensorMap; kwargs...)
9092
domain(t) codomain(t) || return false
91-
f((c, b)) = MAK.is_right_isometric(b; kwargs...)
92-
return all(f, blocks(t))
93+
return all(_blockmap(MAK.is_right_isometric; kwargs...), blocks(t))
9394
end
9495

9596
end

src/factorizations/matrixalgebrakit.jl

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@ for f! in (
3131
@eval function MAK.$f!(t::AbstractTensorMap, F, alg::AbstractAlgorithm)
3232
MAK.check_input($f!, t, F, alg)
3333

34-
foreachblock(t, F...) do _, bs
35-
factors = Base.tail(bs)
36-
factors′ = $f!(first(bs), factors, alg)
34+
foreachblock(t, F...) do _, (tblock, Fblocks...)
35+
Fblocks′ = $f!(tblock, Fblocks, alg)
3736
# deal with the case where the output is not in-place
38-
for (f′, f) in zip(factors′, factors)
39-
f′ === f || copy!(f, f′)
37+
for (b′, b) in zip(Fblocks′, Fblocks)
38+
b === b′ || copy!(b, b′)
4039
end
4140
return nothing
4241
end
@@ -50,10 +49,10 @@ for f! in (:qr_null!, :lq_null!, :project_hermitian!, :project_antihermitian!, :
5049
@eval function MAK.$f!(t::AbstractTensorMap, N, alg::AbstractAlgorithm)
5150
MAK.check_input($f!, t, N, alg)
5251

53-
foreachblock(t, N) do _, (b, n)
54-
n= $f!(b, n, alg)
52+
foreachblock(t, N) do _, (tblock, Nblock)
53+
Nblock= $f!(tblock, Nblock, alg)
5554
# deal with the case where the output is not the same as the input
56-
n === n|| copy!(n, n′)
55+
Nblock === Nblock|| copy!(Nblock, Nblock′)
5756
return nothing
5857
end
5958

@@ -66,10 +65,10 @@ for f! in (:svd_vals!, :eig_vals!, :eigh_vals!)
6665
@eval function MAK.$f!(t::AbstractTensorMap, N, alg::AbstractAlgorithm)
6766
MAK.check_input($f!, t, N, alg)
6867

69-
foreachblock(t, N) do _, (b, n)
70-
n= $f!(b, diagview(n), alg)
68+
foreachblock(t, N) do _, (tblock, Nblock)
69+
Nblock= $f!(tblock, diagview(Nblock), alg)
7170
# deal with the case where the output is not the same as the input
72-
diagview(n) === n|| copy!(diagview(n), n′)
71+
diagview(Nblock) === Nblock|| copy!(diagview(Nblock), Nblock′)
7372
return nothing
7473
end
7574

@@ -445,7 +444,7 @@ end
445444
# Projections
446445
# -----------
447446
function MAK.check_input(::typeof(project_hermitian!), tsrc::AbstractTensorMap, tdst::AbstractTensorMap, ::AbstractAlgorithm)
448-
domain(tsrc) == codomain(tsrc) || throw(ArgumentError("Hermitian projection requires square input tensor"))
447+
domain(tsrc) == codomain(tsrc) || throw(ArgumentError("(Anti-)Hermitian projection requires square input tensor"))
449448
tsrc === tdst || @check_space(tdst, space(tsrc))
450449
return nothing
451450
end

0 commit comments

Comments
 (0)