@@ -42,12 +42,14 @@ represent objects in 𝕜-linear monoidal categories.
42
42
abstract type VectorSpace end
43
43
44
44
"""
45
- field(V::VectorSpace) -> Field
45
+ field(a) -> Type{𝔽<:Field}
46
+ field(::Type{T}) -> Type{𝔽<:Field}
46
47
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.
48
50
"""
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 ))
51
53
52
54
# Basic vector space methods
53
55
# ----------------------------
@@ -102,7 +104,6 @@ of a homogeneous tensor product of these spaces.
102
104
abstract type ElementarySpace <: VectorSpace end
103
105
const IndexSpace = ElementarySpace
104
106
105
- field (V:: ElementarySpace ) = field (typeof (V))
106
107
# field(::Type{<:ElementarySpace{𝕜}}) where {𝕜} = 𝕜
107
108
108
109
@doc """
@@ -241,11 +242,14 @@ dual(::EuclideanInnerProduct, V::VectorSpace) = conj(V)
241
242
242
243
"""
243
244
sectortype(a) -> Type{<:Sector}
245
+ sectortype(::Type) -> Type{<:Sector}
244
246
245
247
Return the type of sector over which object `a` (e.g. a representation space or a tensor) is
246
248
defined. Also works in type domain.
247
249
"""
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
249
253
250
254
"""
251
255
hassector(V::VectorSpace, a::Sector) -> Bool
@@ -274,13 +278,19 @@ abstract type CompositeSpace{S<:ElementarySpace} <: VectorSpace end
274
278
275
279
InnerProductStyle (:: Type{<:CompositeSpace{S}} ) where {S} = InnerProductStyle (S)
276
280
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}
281
284
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
284
294
285
295
# make ElementarySpace instances behave similar to ProductSpace instances
286
296
blocksectors (V:: ElementarySpace ) = collect (sectors (V))
0 commit comments