Skip to content

Commit 169f324

Browse files
committed
some final small fixes
1 parent ff9e391 commit 169f324

File tree

4 files changed

+50
-41
lines changed

4 files changed

+50
-41
lines changed

src/tensors/factorizations/adjoint.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ for f! in (:svd_full!, :svd_compact!, :svd_trunc!)
7878
$f!(adjoint(t), reverse(adjoint.(F)), _adjoint(alg))
7979
return F
8080
end
81+
82+
# disambiguate by prohibition
83+
@eval function initialize_output(::typeof($f!), t::AdjointTensorMap,
84+
alg::DiagonalAlgorithm)
85+
throw(MethodError($f!, (t, alg)))
86+
end
8187
end
8288
# avoid amgiguity
8389
function initialize_output(::typeof(svd_trunc!), t::AdjointTensorMap,

src/tensors/factorizations/matrixalgebrakit.jl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,6 @@ function check_input(::typeof(svd_compact!), t::AbstractTensorMap, USVᴴ,
128128
return nothing
129129
end
130130

131-
function check_input(::typeof(svd_vals!), t::AbstractTensorMap, S::SectorDict,
132-
::AbstractAlgorithm)
133-
@check_scalar S t real
134-
V_cod = V_dom = infimum(fuse(codomain(t)), fuse(domain(t)))
135-
@check_space(S, V_cod V_dom)
136-
return nothing
137-
end
138-
139131
function check_input(::typeof(svd_vals!), t::AbstractTensorMap, D, ::AbstractAlgorithm)
140132
@check_scalar D t real
141133
@assert D isa DiagonalTensorMap

test/ad.jl

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -148,22 +148,32 @@ project_hermitian(A) = (A + A') / 2
148148

149149
ChainRulesTestUtils.test_method_tables()
150150

151-
spacelist = try
152-
if ENV["CI"] == "true"
153-
println("Detected running on CI")
154-
if Sys.iswindows()
155-
(Vtr, Vℤ₃, VU₁, VfU₁, VCU₁, VSU₂)
156-
elseif Sys.isapple()
157-
(Vtr, Vℤ₃, VfU₁, VfSU₂)
158-
else
159-
(Vtr, VU₁, VCU₁, VfSU₂, Vfib)
160-
end
161-
else
162-
(Vtr, Vℤ₃, VU₁, VfU₁, VSU₂, VfSU₂, Vfib)
163-
end
164-
catch
165-
(Vtr, Vℤ₃, VU₁, VfU₁, VCU₁, VSU₂, VfSU₂, Vfib)
166-
end
151+
spacelist = ((ℂ^2, (ℂ^3)', ℂ^3, ℂ^2, (ℂ^2)'),
152+
(Vect[Z2Irrep](0 => 1, 1 => 1),
153+
Vect[Z2Irrep](0 => 1, 1 => 2)',
154+
Vect[Z2Irrep](0 => 3, 1 => 2)',
155+
Vect[Z2Irrep](0 => 2, 1 => 3),
156+
Vect[Z2Irrep](0 => 2, 1 => 2)),
157+
(Vect[FermionParity](0 => 1, 1 => 1),
158+
Vect[FermionParity](0 => 1, 1 => 2)',
159+
Vect[FermionParity](0 => 2, 1 => 2)',
160+
Vect[FermionParity](0 => 2, 1 => 3),
161+
Vect[FermionParity](0 => 2, 1 => 2)),
162+
(Vect[U1Irrep](0 => 2, 1 => 1, -1 => 1),
163+
Vect[U1Irrep](0 => 3, 1 => 1, -1 => 1),
164+
Vect[U1Irrep](0 => 2, 1 => 2, -1 => 1)',
165+
Vect[U1Irrep](0 => 1, 1 => 1, -1 => 2),
166+
Vect[U1Irrep](0 => 1, 1 => 2, -1 => 1)'),
167+
(Vect[SU2Irrep](0 => 2, 1 // 2 => 1),
168+
Vect[SU2Irrep](0 => 1, 1 => 1),
169+
Vect[SU2Irrep](1 // 2 => 1, 1 => 1)',
170+
Vect[SU2Irrep](1 // 2 => 2),
171+
Vect[SU2Irrep](0 => 1, 1 // 2 => 1, 3 // 2 => 1)'),
172+
(Vect[FibonacciAnyon](:I => 1, => 1),
173+
Vect[FibonacciAnyon](:I => 1, => 2)',
174+
Vect[FibonacciAnyon](:I => 3, => 2)',
175+
Vect[FibonacciAnyon](:I => 2, => 3),
176+
Vect[FibonacciAnyon](:I => 2, => 2)))
167177

168178
for V in spacelist
169179
I = sectortype(eltype(V))
@@ -308,8 +318,8 @@ for V in spacelist
308318

309319
@timedtestset "tensortrace!" begin
310320
for _ in 1:5
311-
k1 = rand(0:3)
312-
k2 = k1 == 3 ? 1 : rand(1:2)
321+
k1 = rand(0:2)
322+
k2 = rand(1:2)
313323
V1 = map(v -> rand(Bool) ? v' : v, rand(V, k1))
314324
V2 = map(v -> rand(Bool) ? v' : v, rand(V, k2))
315325

@@ -331,13 +341,13 @@ for V in spacelist
331341
end
332342

333343
@timedtestset "tensoradd!" begin
334-
A = randn(T, V[1] V[2] V[3] V[4] V[5])
344+
A = randn(T, V[1] V[2] V[4] V[5])
335345
α = randn(T)
336346
β = randn(T)
337347

338348
# repeat a couple times to get some distribution of arrows
339349
for _ in 1:5
340-
p = randindextuple(length(V))
350+
p = randindextuple(numind(A))
341351

342352
C1 = randn!(TensorOperations.tensoralloc_add(T, A, p, false,
343353
Val(false)))
@@ -399,19 +409,20 @@ for V in spacelist
399409
end
400410

401411
@timedtestset "Factorizations" begin
412+
W = V[1] V[2]
402413
@testset "QR" begin
403414
for T in eltypes,
404415
t in (randn(T, W, W), randn(T, W, W)',
405-
randn(T, W, V1), randn(T, V1, W),
406-
randn(T, W, V1)', randn(T, V1, W)',
407-
DiagonalTensorMap(randn(T, reduceddim(V1)), V1))
416+
randn(T, W, V[1]), randn(T, V[1], W),
417+
randn(T, W, V[1])', randn(T, V[1], W)',
418+
DiagonalTensorMap(randn(T, reduceddim(V[1])), V[1]))
408419

409420
atol = rtol = precision(T) * dim(space(t))
410421
fkwargs = (; positive=true) # make FiniteDifferences happy
411422

412423
test_ad_rrule(qr_compact, t; fkwargs, atol, rtol)
413-
test_ad_rrule(first qr_compact, t; fkwargs, atol, rtol,)
414-
test_ad_rrule(last qr_compact, t; fkwargs, atol, rtol,)
424+
test_ad_rrule(first qr_compact, t; fkwargs, atol, rtol)
425+
test_ad_rrule(last qr_compact, t; fkwargs, atol, rtol)
415426

416427
# qr_full/qr_null requires being careful with gauges
417428
Q, R = qr_full(t)
@@ -445,9 +456,9 @@ for V in spacelist
445456
@testset "LQ" begin
446457
for T in eltypes,
447458
t in (randn(T, W, W), randn(T, W, W)',
448-
randn(T, W, V1), randn(T, V1, W),
449-
randn(T, W, V1)', randn(T, V1, W)',
450-
DiagonalTensorMap(randn(T, reduceddim(V1)), V1))
459+
randn(T, W, V[1]), randn(T, V[1], W),
460+
randn(T, W, V[1])', randn(T, V[1], W)',
461+
DiagonalTensorMap(randn(T, reduceddim(V[1])), V[1]))
451462

452463
atol = rtol = precision(T) * dim(space(t))
453464
fkwargs = (; positive=true) # make FiniteDifferences happy
@@ -489,8 +500,8 @@ for V in spacelist
489500

490501
@testset "Eigenvalue decomposition" begin
491502
for T in eltypes,
492-
t in (rand(T, V1, V1), rand(T, W, W), rand(T, W, W)',
493-
DiagonalTensorMap(rand(T, reduceddim(V1)), V1))
503+
t in (rand(T, V[1], V[1]), rand(T, W, W), rand(T, W, W)',
504+
DiagonalTensorMap(rand(T, reduceddim(V[1])), V[1]))
494505

495506
atol = rtol = precision(T) * dim(space(t))
496507

@@ -524,7 +535,7 @@ for V in spacelist
524535

525536
@testset "Singular value decomposition" begin
526537
for T in eltypes,
527-
t in (randn(T, V1, V1), randn(T, W, W), randn(T, W, W))
538+
t in (randn(T, V[1], V[1]), randn(T, W, W), randn(T, W, W))
528539
# TODO: fix diagonaltensormap case
529540
# DiagonalTensorMap(rand(T, reduceddim(V1)), V1))
530541

test/bugfixes.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
# https://github.com/quantumkithub/TensorKit.jl/issues/201
4848
@testset "Issue #201" begin
4949
function f(A::AbstractTensorMap)
50-
U, S, V, = tsvd(A)
50+
U, S, V, = svd_compact(A)
5151
return tr(S)
5252
end
5353
function f(A::AbstractMatrix)
@@ -60,7 +60,7 @@
6060
@test convert(Array, grad1) grad2
6161

6262
function g(A::AbstractTensorMap)
63-
U, S, V, = tsvd(A)
63+
U, S, V, = svd_compact(A)
6464
return tr(U * V)
6565
end
6666
function g(A::AbstractMatrix)

0 commit comments

Comments
 (0)