Skip to content

Commit 7d8a688

Browse files
committed
Add tests for conversion and a few more fixes
1 parent 33da0e1 commit 7d8a688

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Aqua = "0.8"
2727
BlockArrays = "1"
2828
Combinatorics = "1"
2929
Compat = "4.13"
30+
JLArrays = "0.3"
3031
LinearAlgebra = "1"
3132
MatrixAlgebraKit = "0.6"
3233
Random = "1"
@@ -44,10 +45,11 @@ julia = "1.10"
4445
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
4546
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
4647
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
48+
JLArrays = "27aeb0d3-9eb9-45fb-866b-73c2ecf80fcb"
4749
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
4850
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
4951
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
5052
TestExtras = "5ed8adda-3752-4e41-b88a-e8b09835ee3a"
5153

5254
[targets]
53-
test = ["Test", "TestExtras", "Random", "Combinatorics", "SafeTestsets", "Aqua", "Adapt"]
55+
test = ["Test", "TestExtras", "Random", "Combinatorics", "SafeTestsets", "Aqua", "Adapt", "JLArrays"]

src/tensors/abstractblocktensor/conversion.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ function Base.convert(::Type{TensorMap}, t::AbstractBlockTensorMap)
3535
return tdst
3636
end
3737

38-
function Base.convert(::Type{TT}, t::AbstractBlockTensorMap) where {TT <: TensorMap}
38+
function Base.convert(::Type{TT}, t::AbstractBlockTensorMap) where {TT <: TensorKit.TensorMap}
3939
S = spacetype(t)
4040
N₁, N₂ = numout(t), numin(t)
4141
cod = ProductSpace{S, N₁}(oplus.(codomain(t).spaces))
4242
dom = ProductSpace{S, N₂}(oplus.(domain(t).spaces))
43-
tdst = TT(undef, cod dom)
43+
tdst = TensorKit.TensorMapWithStorage{scalartype(TT), storagetype(TT)}(undef, cod, dom)
4444
issparse(t) && zerovector!(tdst)
4545

4646
_copy_subblocks!(tdst, t)

test/abstracttensor/blocktensor.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ using BlockTensorKit
55
using Random
66
using Combinatorics
77
using Adapt
8+
using JLArrays
89

910
Vtr = (
1011
SumSpace(ℂ^3),
@@ -82,6 +83,14 @@ end
8283
t2″ = @inferred BlockTensorMap(t2′, W)
8384
@test t1 t1″
8485
@test t2 t2″
86+
# test conversion to TensorMap that isn't backed by a Vector
87+
jl_bt1 = rand(JLVector{T}, W)
88+
TT = TensorKit.TensorMap{T, spacetype(t1′), numin(t1′), numout(t1′), JLVector{T}}
89+
JLArrays.@allowscalar begin # to avoid scalar indexing error in Strided
90+
jl_bt1′ = @constinferred convert(TT, jl_bt1)
91+
jl_bt1″ = @inferred BlockTensorMap(jl_bt1′, W)
92+
end
93+
@test jl_bt1 jl_bt1″
8594
end
8695
end
8796

0 commit comments

Comments
 (0)