Skip to content

Commit f5023f7

Browse files
committed
Add more convenience constructors to DiagonalTensorMap
1 parent 5f75ba3 commit f5023f7

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/tensors/diagonal.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ storagetype(::Type{<:DiagonalTensorMap{T,S,A}}) where {T,S,A<:DenseVector{T}} =
3737
3838
Construct a `DiagonalTensorMap` with uninitialized data.
3939
"""
40+
function DiagonalTensorMap{T}(::UndefInitializer, V::TensorMapSpace) where {T}
41+
(numin(V) == numout(V) == 1 && domain(V) == codomain(V)) ||
42+
throw(SpaceMismatch("DiagonalTensorMap requires a space with equal domain and codomain and 2 indices"))
43+
return DiagonalTensorMap{T}(undef, domain(V))
44+
end
45+
function DiagonalTensorMap{T}(::UndefInitializer, V::ProductSpace) where {T}
46+
length(V) == 1 ||
47+
throw(DimensionMismatch("length(V) = $(length(V)) is not compatible with the space $V"))
48+
return DiagonalTensorMap{T}(undef, only(V))
49+
end
4050
function DiagonalTensorMap{T}(::UndefInitializer, V::S) where {T,S<:IndexSpace}
4151
return DiagonalTensorMap{T,S,Vector{T}}(undef, V)
4252
end

0 commit comments

Comments
 (0)