Skip to content

Commit 97741f6

Browse files
committed
more careful with storagetypes
1 parent dfbf199 commit 97741f6

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/tensors/abstracttensor.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ similarstoragetype(::Type{TT}, ::Type{T}) where {TT <: AbstractTensorMap, T <: N
7474
similarstoragetype(storagetype(TT), T)
7575

7676
# implement on arrays
77-
similarstoragetype(::Type{A}, ::Type{T}) where {T <: Number, A <: DenseVector{T}} = A
7877
Base.@assume_effects :foldable similarstoragetype(::Type{A}, ::Type{T}) where {A <: AbstractArray, T <: Number} =
7978
Core.Compiler.return_type(similar, Tuple{A, Type{T}, Int})
8079

src/tensors/tensoroperations.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,16 @@ function TO.tensorcontract_type(
155155
) where {N₁, N₂}
156156
spacetype(A) == spacetype(B) || throw(SpaceMismatch("incompatible space types"))
157157
I = sectortype(A)
158-
M = similarstoragetype(A, sectorscalartype(I) <: Real ? TC : complex(TC))
159-
MB = similarstoragetype(B, sectorscalartype(I) <: Real ? TC : complex(TC))
160-
M == MB || throw(ArgumentError("incompatible storage types:\n$(M)$(MB)"))
158+
TC′ = isreal(I) ? TC : complex(TC)
159+
M = pomote_storagetype(similarstoragetype(A, TC′), similarstoragetype(B, TC′))
161160
return tensormaptype(spacetype(A), N₁, N₂, M)
162161
end
163162

163+
# TODO: handle actual promotion rule system
164+
function promote_storagetype(::Type{M₁}, ::Type{M₂}) where {M₁, M₂}
165+
return M₁ === M₂ ? M₁ : throw(ArgumentError("Cannot determine storage type for combining `$M₁` and `$M₂`"))
166+
end
167+
164168
function TO.tensorcontract_structure(
165169
A::AbstractTensorMap, pA::Index2Tuple, conjA::Bool,
166170
B::AbstractTensorMap, pB::Index2Tuple, conjB::Bool,

0 commit comments

Comments
 (0)