Skip to content

Commit c3e8d37

Browse files
authored
Type changes for complex sectors + BlockIterator fix (#26)
1 parent c36a83a commit c3e8d37

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

Project.toml

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

66
[deps]
77
BlockArrays = "8e7c35d0-a365-5155-bbbb-fb81a777f24e"

src/BlockTensorKit.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ using TensorKit:
2222
SectorDict,
2323
AdjointTensorMap,
2424
adjointtensorindices,
25-
compose
25+
compose,
26+
sectorscalartype
2627
using VectorInterface
2728
using TensorOperations
2829
using TensorOperations:

src/tensors/abstractblocktensor/abstracttensormap.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function TensorKit.block(t::AbstractBlockTensorMap, c::Sector)
6363
end
6464

6565
# TODO: this might get fixed once new tensormap is implemented
66-
TensorKit.blocks(t::AbstractBlockTensorMap) = ((c, block(t, c)) for c in blocksectors(t))
66+
TensorKit.blocks(t::AbstractBlockTensorMap) = ((c => block(t, c)) for c in blocksectors(t))
6767
TensorKit.blocksectors(t::AbstractBlockTensorMap) = blocksectors(space(t))
6868
TensorKit.hasblock(t::AbstractBlockTensorMap, c::Sector) = c in blocksectors(t)
6969

src/tensors/tensoroperations.jl

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ function TO.tensoradd_type(
44
TC, A::AbstractBlockTensorMap, ::Index2Tuple{N₁,N₂}, ::Bool
55
) where {N₁,N₂}
66
TA = eltype(A)
7+
I = sectortype(A)
8+
Tnew = sectorscalartype(I) <: Real ? TC : complex(TC)
79
if TA isa Union
8-
M = Union{TK.similarstoragetype(TA.a, TC),TK.similarstoragetype(TA.b, TC)}
10+
M = Union{TK.similarstoragetype(TA.a, Tnew),TK.similarstoragetype(TA.b, Tnew)}
911
else
10-
M = TK.similarstoragetype(TA, TC)
12+
M = TK.similarstoragetype(TA, Tnew)
1113
end
1214
return if issparse(A)
1315
sparseblocktensormaptype(spacetype(A), N₁, N₂, M)
@@ -33,7 +35,10 @@ function TO.tensorcontract_type(
3335
) where {N₁,N₂}
3436
spacetype(A) == spacetype(B) ||
3537
throw(SpaceMismatch("incompatible space types: $(spacetype(A)) ≠ $(spacetype(B))"))
36-
M = promote_storagetype(TC, eltype(A), eltype(B))
38+
39+
I = sectortype(A)
40+
Tnew = sectorscalartype(I) <: Real ? TC : complex(TC)
41+
M = promote_storagetype(Tnew, eltype(A), eltype(B))
3742
return if issparse(A) && issparse(B)
3843
sparseblocktensormaptype(spacetype(A), N₁, N₂, M)
3944
else
@@ -52,7 +57,10 @@ function TO.tensorcontract_type(
5257
) where {N₁,N₂}
5358
spacetype(A) == spacetype(B) ||
5459
throw(SpaceMismatch("incompatible space types: $(spacetype(A)) ≠ $(spacetype(B))"))
55-
M = promote_storagetype(TC, typeof(A), eltype(B))
60+
61+
I = sectortype(A)
62+
Tnew = sectorscalartype(I) <: Real ? TC : complex(TC)
63+
M = promote_storagetype(Tnew, typeof(A), eltype(B))
5664
return if issparse(A) && issparse(B)
5765
sparseblocktensormaptype(spacetype(A), N₁, N₂, M)
5866
else
@@ -71,7 +79,10 @@ function TO.tensorcontract_type(
7179
) where {N₁,N₂}
7280
spacetype(A) == spacetype(B) ||
7381
throw(SpaceMismatch("incompatible space types: $(spacetype(A)) ≠ $(spacetype(B))"))
74-
M = promote_storagetype(TC, eltype(A), typeof(B))
82+
83+
I = sectortype(A)
84+
Tnew = sectorscalartype(I) <: Real ? TC : complex(TC)
85+
M = promote_storagetype(Tnew, eltype(A), typeof(B))
7586
return if issparse(A) && issparse(B)
7687
sparseblocktensormaptype(spacetype(A), N₁, N₂, M)
7788
else

0 commit comments

Comments
 (0)