Skip to content

Commit b4e3505

Browse files
authored
fix: one! implementation for non-matching block partitions (#64)
* fix `one!` implementation * add test * bump version
1 parent 215f928 commit b4e3505

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

‎Project.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "BlockTensorKit"
22
uuid = "5f87ffc2-9cf1-4a46-8172-465d160bd8cd"
3-
version = "0.3.14"
3+
version = "0.3.15"
44
authors = ["Lukas Devos <ldevos98@gmail.com> and contributors"]
55

66
[deps]

‎src/auxiliary/blockarrays.jl‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@ function MAK.zero!(A::BlockBlasMat)
2727
end
2828

2929
function MAK.one!(A::BlockBlasMat)
30+
rowaxis, colaxis = axes(A)
3031
for bj in blockaxes(A, 2), bi in blockaxes(A, 1)
3132
a = view(A, bi, bj)
32-
bi == bj ? MAK.one!(a) : MAK.zero!(a)
33+
MAK.zero!(a)
34+
isempty(a) && continue
35+
k = first(rowaxis[bi]) - first(colaxis[bj])
36+
view(a, MAK.diagind(a, k)) .= one(eltype(a))
3337
end
3438
return A
3539
end

‎test/abstracttensor/blocktensor.jl‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,24 @@ end
152152
end
153153
end
154154

155+
@testset "one!/isomorphism with mismatched block partitions" begin
156+
# regression test: codomain and domain are isomorphic but partitioned differently
157+
# (Vflat has a single block, Vsum decomposes into two), which used to confuse
158+
# MAK.one!'s block-diagonal detection
159+
W1 = Rep[U₁](0 => 2, 1 => 1)
160+
W2 = Rep[U₁](0 => 2, 1 => 1)
161+
Vsum = W1 ⊞ W2
162+
Vflat = oplus(Vsum)
163+
164+
for T in (Float64, ComplexF64), A in (Vector{T}, JLVector{T})
165+
u = @constinferred unitary(A, Vflat, Vsum)
166+
@test storagetype(u) == A
167+
@test u' * u ≈ id(A, Vsum)
168+
@test only(u * u') ≈ id(A, Vflat)
169+
@test isunitary(u)
170+
end
171+
end
172+
155173
@testset "Basic linear algebra: test via conversion" begin
156174
W = V1 ⊗ V2 ⊗ V3 ← V4 ⊗ V5
157175
for T in (Float32, ComplexF64)

0 commit comments

Comments
 (0)