@@ -42,11 +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
51+ field (x) = field (typeof (x))
52+ field (:: Type{T} ) where {T} = field (spacetype (T))
5053
5154# Basic vector space methods
5255# ----------------------------
@@ -239,11 +242,14 @@ dual(::EuclideanInnerProduct, V::VectorSpace) = conj(V)
239242
240243"""
241244 sectortype(a) -> Type{<:Sector}
245+ sectortype(::Type) -> Type{<:Sector}
242246
243247Return the type of sector over which object `a` (e.g. a representation space or a tensor) is
244248defined. Also works in type domain.
245249"""
246- 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
247253
248254"""
249255 hassector(V::VectorSpace, a::Sector) -> Bool
@@ -272,19 +278,20 @@ abstract type CompositeSpace{S<:ElementarySpace} <: VectorSpace end
272278
273279InnerProductStyle (:: Type{<:CompositeSpace{S}} ) where {S} = InnerProductStyle (S)
274280
281+ """
282+ spacetype(a) -> Type{S<:IndexSpace}
283+ spacetype(::Type) -> Type{S<:IndexSpace}
284+
285+ Return the type of the elementary space `S` of object `a` (e.g. a tensor). Also works in
286+ type domain.
287+ """
275288spacetype (x) = spacetype (typeof (x))
276289function spacetype (:: Type{T} ) where {T}
277- throw (MethodError (spacetype, (" spacetype not defined for type $T " ,)))
290+ throw (MethodError (spacetype, (T ,)))
278291end
279292spacetype (S:: Type{<:ElementarySpace} ) = S
280293spacetype (:: Type{<:CompositeSpace{S}} ) where {S} = S
281294
282- sectortype (x) = sectortype (typeof (x))
283- sectortype (:: Type{T} ) where {T} = sectortype (spacetype (T))
284-
285- field (x) = field (typeof (x))
286- field (:: Type{T} ) where {T} = field (spacetype (T))
287-
288295# make ElementarySpace instances behave similar to ProductSpace instances
289296blocksectors (V:: ElementarySpace ) = collect (sectors (V))
290297blockdim (V:: ElementarySpace , c:: Sector ) = dim (V, c)
0 commit comments