Skip to content

Commit 8636d67

Browse files
committed
remove unnecessary left/rightorth functions
1 parent f623bc3 commit 8636d67

File tree

3 files changed

+2
-170
lines changed

3 files changed

+2
-170
lines changed

src/TensorKit.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ export left_orth, right_orth, left_null, right_null,
8282
eigh_full!, eigh_full, eigh_trunc!, eigh_trunc, eig_full!, eig_full, eig_trunc!,
8383
eig_trunc,
8484
eigh_vals!, eigh_vals, eig_vals!, eig_vals,
85-
isposdef, isposdef!, ishermitian, isisometric, isunitary, sylvester, rank, cond,
86-
LeftOrthAlgorithm, RightOrthAlgorithm
85+
isposdef, isposdef!, ishermitian, isisometric, isunitary, sylvester, rank, cond
8786

8887
export braid, braid!, permute, permute!, transpose, transpose!, twist, twist!, repartition,
8988
repartition!

src/factorizations/factorizations.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ using TensorOperations: Index2Tuple
1616
using MatrixAlgebraKit
1717
import MatrixAlgebraKit as MAK
1818
using MatrixAlgebraKit: AbstractAlgorithm, TruncatedAlgorithm, DiagonalAlgorithm
19-
using MatrixAlgebraKit: LeftOrthAlgorithm, RightOrthAlgorithm
2019
using MatrixAlgebraKit: TruncationStrategy, NoTruncation, TruncationByValue,
2120
TruncationByError, TruncationIntersection, TruncationByFilter, TruncationByOrder
2221
using MatrixAlgebraKit: diagview, isisometric

src/factorizations/matrixalgebrakit.jl

Lines changed: 1 addition & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ end
2626
for f! in (
2727
:qr_compact!, :qr_full!, :lq_compact!, :lq_full!,
2828
:eig_full!, :eigh_full!, :svd_compact!, :svd_full!,
29-
:left_polar!, :right_polar!
29+
:left_polar!, :right_polar!,
3030
)
3131
@eval function MAK.$f!(t::AbstractTensorMap, F, alg::AbstractAlgorithm)
3232
MAK.check_input($f!, t, F, alg)
@@ -45,43 +45,6 @@ for f! in (
4545
end
4646
end
4747

48-
for alg in (MAK.LeftOrthAlgorithm{:qr}, MAK.LeftOrthAlgorithm{:svd}, MAK.LeftOrthAlgorithm{:polar})
49-
@eval begin
50-
function MAK.left_orth!(t::AbstractTensorMap, F, alg::$alg)
51-
MAK.check_input(left_orth!, t, F, alg)
52-
53-
foreachblock(t, F...) do _, bs
54-
factors = Base.tail(bs)
55-
factors′ = left_orth!(first(bs), factors, alg)
56-
# deal with the case where the output is not in-place
57-
for (f′, f) in zip(factors′, factors)
58-
f′ === f || copy!(f, f′)
59-
end
60-
return nothing
61-
end
62-
return F
63-
end
64-
end
65-
end
66-
67-
for alg in (MAK.RightOrthAlgorithm{:lq}, MAK.RightOrthAlgorithm{:svd}, MAK.RightOrthAlgorithm{:polar})
68-
@eval function MAK.right_orth!(t::AbstractTensorMap, F, alg::$alg)
69-
MAK.check_input(right_orth!, t, F, alg)
70-
71-
foreachblock(t, F...) do _, bs
72-
factors = Base.tail(bs)
73-
factors′ = right_orth!(first(bs), factors, alg)
74-
# deal with the case where the output is not in-place
75-
for (f′, f) in zip(factors′, factors)
76-
f′ === f || copy!(f, f′)
77-
end
78-
return nothing
79-
end
80-
return F
81-
end
82-
end
83-
84-
8548
# Handle these separately because single output instead of tuple
8649
for f! in (:qr_null!, :lq_null!)
8750
@eval function MAK.$f!(t::AbstractTensorMap, N, alg::AbstractAlgorithm)
@@ -484,135 +447,6 @@ function MAK.initialize_output(::typeof(right_polar!), t::AbstractTensorMap, ::A
484447
return P, Wᴴ
485448
end
486449

487-
# Orthogonalization
488-
# -----------------
489-
function MAK.check_input(::typeof(left_orth!), t::AbstractTensorMap, VC, ::AbstractAlgorithm)
490-
V, C = VC
491-
492-
# scalartype checks
493-
@check_scalar V t
494-
isnothing(C) || @check_scalar C t
495-
496-
# space checks
497-
V_C = infimum(fuse(codomain(t)), fuse(domain(t)))
498-
@check_space(V, codomain(t) V_C)
499-
isnothing(C) || @check_space(C, V_C domain(t))
500-
501-
return nothing
502-
end
503-
504-
function MAK.check_input(::typeof(left_orth!), t::AbstractTensorMap, VC, alg::MAK.LeftOrthAlgorithm{:qr})
505-
return MAK.check_input(qr_compact!, t, VC, alg.alg)
506-
end
507-
508-
function MAK.check_input(::typeof(left_orth!), t::AbstractTensorMap, VC, alg::MAK.LeftOrthAlgorithm{:svd})
509-
return MAK.check_input(svd_compact!, t, VC, alg.alg)
510-
end
511-
512-
function MAK.check_input(::typeof(left_orth!), t::AbstractTensorMap, VC, alg::MAK.LeftOrthAlgorithm{:polar})
513-
return MAK.check_input(left_polar!, t, VC, alg.alg)
514-
end
515-
516-
function MAK.check_input(::typeof(right_orth!), t::AbstractTensorMap, CVᴴ, ::AbstractAlgorithm)
517-
C, Vᴴ = CVᴴ
518-
519-
# scalartype checks
520-
isnothing(C) || @check_scalar C t
521-
@check_scalar Vᴴ t
522-
523-
# space checks
524-
V_C = infimum(fuse(codomain(t)), fuse(domain(t)))
525-
isnothing(C) || @check_space(C, codomain(t) V_C)
526-
@check_space(Vᴴ, V_C domain(t))
527-
528-
return nothing
529-
end
530-
531-
function MAK.check_input(::typeof(right_orth!), t::AbstractTensorMap, VC, alg::MAK.RightOrthAlgorithm{:lq})
532-
return MAK.check_input(lq_compact!, t, VC, alg.alg)
533-
end
534-
535-
function MAK.check_input(::typeof(right_orth!), t::AbstractTensorMap, VC, alg::MAK.RightOrthAlgorithm{:svd})
536-
return MAK.check_input(svd_compact!, t, VC, alg.alg)
537-
end
538-
539-
function MAK.check_input(::typeof(right_orth!), t::AbstractTensorMap, VC, alg::MAK.RightOrthAlgorithm{:polar})
540-
return MAK.check_input(right_polar!, t, VC, alg.alg)
541-
end
542-
543-
function MAK.initialize_output(::typeof(left_orth!), t::AbstractTensorMap)
544-
V_C = infimum(fuse(codomain(t)), fuse(domain(t)))
545-
V = similar(t, codomain(t) V_C)
546-
C = similar(t, V_C domain(t))
547-
return V, C
548-
end
549-
550-
function MAK.initialize_output(::typeof(right_orth!), t::AbstractTensorMap)
551-
V_C = infimum(fuse(codomain(t)), fuse(domain(t)))
552-
C = similar(t, codomain(t) V_C)
553-
Vᴴ = similar(t, V_C domain(t))
554-
return C, Vᴴ
555-
end
556-
557-
# This is a rework of the dispatch logic in order to avoid having to deal with having to
558-
# allocate the output before knowing the kind of decomposition. In particular, here I disable
559-
# providing output arguments for left_ and right_orth.
560-
# This is mainly because polar decompositions have different shapes, and SVD for Diagonal
561-
# also does
562-
function MAK.left_orth!(
563-
t::AbstractTensorMap;
564-
trunc::TruncationStrategy = notrunc(),
565-
alg::AbstractAlgorithm = (trunc == notrunc()) ? MAK.select_algorithm(left_orth!, t, Val(:qr)) : MAK.select_algorithm(left_orth!, t, Val(:svd); trunc)
566-
)
567-
MAK.left_orth!(t, MAK.initialize_output(left_orth!, t, alg), alg)
568-
end
569-
function MAK.right_orth!(
570-
t::AbstractTensorMap;
571-
trunc::TruncationStrategy = notrunc(),
572-
alg::AbstractAlgorithm = (trunc == notrunc()) ? MAK.select_algorithm(right_orth!, t, Val(:lq)) : MAK.select_algorithm(right_orth!, t, Val(:svd); trunc)
573-
)
574-
MAK.right_orth!(t, MAK.initialize_output(right_orth!, t, alg), alg)
575-
end
576-
577-
# Nullspace
578-
# ---------
579-
function MAK.check_input(::typeof(left_null!), t::AbstractTensorMap, N, ::AbstractAlgorithm)
580-
# scalartype checks
581-
@check_scalar N t
582-
583-
# space checks
584-
V_Q = infimum(fuse(codomain(t)), fuse(domain(t)))
585-
V_N = (fuse(codomain(t)), V_Q)
586-
@check_space(N, codomain(t) V_N)
587-
588-
return nothing
589-
end
590-
591-
function MAK.check_input(::typeof(right_null!), t::AbstractTensorMap, N, ::AbstractAlgorithm)
592-
@check_scalar N t
593-
594-
# space checks
595-
V_Q = infimum(fuse(codomain(t)), fuse(domain(t)))
596-
V_N = (fuse(domain(t)), V_Q)
597-
@check_space(N, V_N domain(t))
598-
599-
return nothing
600-
end
601-
602-
function MAK.initialize_output(::typeof(left_null!), t::AbstractTensorMap)
603-
V_Q = infimum(fuse(codomain(t)), fuse(domain(t)))
604-
V_N = (fuse(codomain(t)), V_Q)
605-
N = similar(t, codomain(t) V_N)
606-
return N
607-
end
608-
609-
function MAK.initialize_output(::typeof(right_null!), t::AbstractTensorMap)
610-
V_Q = infimum(fuse(codomain(t)), fuse(domain(t)))
611-
V_N = (fuse(domain(t)), V_Q)
612-
N = similar(t, V_N domain(t))
613-
return N
614-
end
615-
616450
# Projections
617451
# -----------
618452
function MAK.check_input(::typeof(project_hermitian!), tsrc::AbstractTensorMap, tdst::AbstractTensorMap)

0 commit comments

Comments
 (0)