@@ -42,12 +42,14 @@ represent objects in 𝕜-linear monoidal categories.
4242abstract type VectorSpace end
4343
4444"""
45- field(V::VectorSpace) -> Field
45+ field(a) -> Type{𝔽<:Field}
46+ field(::Type{T}) -> Type{𝔽<:Field}
4647
47- Return the field type over which a vector space is defined.
48+ Return the type of field over which object `a` (e.g. a vector space or a tensor) is defined.
49+ Also works in type domain.
4850"""
49- function field end
50- field (V :: VectorSpace ) = field (typeof (V ))
51+ field (x) = field ( typeof (x))
52+ field (:: Type{T} ) where {T} = field (spacetype (T ))
5153
5254# Basic vector space methods
5355# ----------------------------
@@ -102,7 +104,6 @@ of a homogeneous tensor product of these spaces.
102104abstract type ElementarySpace <: VectorSpace end
103105const IndexSpace = ElementarySpace
104106
105- field (V:: ElementarySpace ) = field (typeof (V))
106107# field(::Type{<:ElementarySpace{𝕜}}) where {𝕜} = 𝕜
107108
108109@doc """
@@ -241,11 +242,14 @@ dual(::EuclideanInnerProduct, V::VectorSpace) = conj(V)
241242
242243"""
243244 sectortype(a) -> Type{<:Sector}
245+ sectortype(::Type) -> Type{<:Sector}
244246
245247Return the type of sector over which object `a` (e.g. a representation space or a tensor) is
246248defined. Also works in type domain.
247249"""
248- sectortype (V:: VectorSpace ) = sectortype (typeof (V))
250+ sectortype (x) = sectortype (typeof (x))
251+ sectortype (:: Type{T} ) where {T} = sectortype (spacetype (T))
252+ sectortype (:: Type{S} ) where {S<: Sector } = S
249253
250254"""
251255 hassector(V::VectorSpace, a::Sector) -> Bool
@@ -274,13 +278,19 @@ abstract type CompositeSpace{S<:ElementarySpace} <: VectorSpace end
274278
275279InnerProductStyle (:: Type{<:CompositeSpace{S}} ) where {S} = InnerProductStyle (S)
276280
277- spacetype (S:: Type{<:ElementarySpace} ) = S
278- spacetype (V:: ElementarySpace ) = typeof (V) # = spacetype(typeof(V))
279- spacetype (:: Type{<:CompositeSpace{S}} ) where {S} = S
280- spacetype (V:: CompositeSpace ) = spacetype (typeof (V)) # = spacetype(typeof(V))
281+ """
282+ spacetype(a) -> Type{S<:IndexSpace}
283+ spacetype(::Type) -> Type{S<:IndexSpace}
281284
282- field (P:: Type{<:CompositeSpace} ) = field (spacetype (P))
283- sectortype (P:: Type{<:CompositeSpace} ) = sectortype (spacetype (P))
285+ Return the type of the elementary space `S` of object `a` (e.g. a tensor). Also works in
286+ type domain.
287+ """
288+ spacetype (x) = spacetype (typeof (x))
289+ function spacetype (:: Type{T} ) where {T}
290+ throw (MethodError (spacetype, (T,)))
291+ end
292+ spacetype (:: Type{E} ) where {E<: ElementarySpace } = E
293+ spacetype (:: Type{S} ) where {E,S<: CompositeSpace{E} } = E
284294
285295# make ElementarySpace instances behave similar to ProductSpace instances
286296blocksectors (V:: ElementarySpace ) = collect (sectors (V))
0 commit comments