Skip to content

Commit ce63274

Browse files
Add move_marg
1 parent 12897cd commit ce63274

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

src/utils.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,3 +1108,15 @@ function shrinking_squared(vecs::Vector{<:AbstractMatrix{T}}; verbose = true) wh
11081108
return eta2
11091109
end
11101110
export shrinking_squared
1111+
1112+
"""
1113+
move_marg(FC::AbstractArray, sense::Int = -1)
1114+
1115+
Change convention for the placement of marginals.
1116+
By default, converts from first to last index.
1117+
If `sense=1`, convert back from last to first index.
1118+
"""
1119+
function move_marg(FC::AbstractArray{T, N}, sense = -1) where {T, N}
1120+
return circshift(FC, ntuple(i -> sense, Val(N)))
1121+
end
1122+
export move_marg

test/runtests.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ end
7070

7171
@testset "Testing Bell-Frank-Wolfe with d=2, N=2, and cor/marg matrices " begin
7272
# using the exact LMO at the end
73-
p = circshift(tensor_correlation(state_phiplus(), HQVNB17_mes(3), 2; marg=true), (-1, -1))
73+
p = move_marg(tensor_correlation(state_phiplus(), HQVNB17_mes(3), 2; marg=true))
7474
@test abs(bell_frank_wolfe(p; marg=true, mode_last=1)[3] - 0.613691) < 1e-5
7575
# with warm start
7676
active_set = bell_frank_wolfe(p; marg=true, max_iteration=10)[5]
@@ -83,9 +83,9 @@ end
8383
# HQVNB17 with symmetry
8484
@test abs(bell_frank_wolfe(p; marg=true)[3] - 0.613691) < 1e-5
8585

86-
p = circshift(tensor_correlation(state_phiplus(), HQVNB17_mes(5), 2; marg=true), (-1, -1))
86+
p = move_marg(tensor_correlation(state_phiplus(), HQVNB17_mes(5), 2; marg=true))
8787
@test abs(bell_frank_wolfe(p; marg=true)[3] - 5.69) < 1e-1
88-
# @test abs(bell_frank_wolfe(circshift(tensor_correlation(state_phiplus(), HQVNB17_mes(7), 2; marg=true), (-1, -1)); marg=true)[3] - 23.02) < 1e-1
88+
# @test abs(bell_frank_wolfe(move_marg(tensor_correlation(state_phiplus(), HQVNB17_mes(7), 2; marg=true)); marg=true)[3] - 23.02) < 1e-1
8989
end
9090

9191
@testset "Testing Bell-Frank-Wolfe with d=2, N=3, and correlation tensors " begin

0 commit comments

Comments
 (0)