Skip to content

Commit 2831fc4

Browse files
committed
generalize doc
1 parent c99d668 commit 2831fc4

File tree

2 files changed

+18
-33
lines changed

2 files changed

+18
-33
lines changed

src/spaces/vectorspaces.jl

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,14 @@ represent objects in 𝕜-linear monoidal categories.
4242
abstract 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
243247
Return the type of sector over which object `a` (e.g. a representation space or a tensor) is
244248
defined. 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

273279
InnerProductStyle(::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+
"""
275288
spacetype(x) = spacetype(typeof(x))
276289
function spacetype(::Type{T}) where {T}
277-
throw(MethodError(spacetype, ("spacetype not defined for type $T",)))
290+
throw(MethodError(spacetype, (T,)))
278291
end
279292
spacetype(S::Type{<:ElementarySpace}) = S
280293
spacetype(::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
289296
blocksectors(V::ElementarySpace) = collect(sectors(V))
290297
blockdim(V::ElementarySpace, c::Sector) = dim(V, c)

src/tensors/abstracttensor.jl

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,34 +32,12 @@ Return the scalar or element type `T` of a tensor.
3232
"""
3333
Base.eltype(::Type{<:AbstractTensorMap{T}}) where {T} = T
3434

35-
"""
36-
spacetype(::AbstractTensorMap) -> Type{S<:IndexSpace}
37-
spacetype(::Type{<:AbstractTensorMap}) -> Type{S<:IndexSpace}
38-
39-
Return the type of the elementary space `S` of a tensor.
40-
"""
4135
spacetype(::Type{<:AbstractTensorMap{<:Any,S}}) where {S} = S
4236

43-
"""
44-
sectortype(::AbstractTensorMap) -> Type{I<:Sector}
45-
sectortype(::Type{<:AbstractTensorMap}) -> Type{I<:Sector}
46-
47-
Return the type of sector `I` of a tensor.
48-
"""
49-
sectortype(::Type{TT}) where {TT<:AbstractTensorMap} = sectortype(spacetype(TT))
50-
5137
function InnerProductStyle(::Type{TT}) where {TT<:AbstractTensorMap}
5238
return InnerProductStyle(spacetype(TT))
5339
end
5440

55-
"""
56-
field(::AbstractTensorMap) -> Type{𝔽<:Field}
57-
field(::Type{<:AbstractTensorMap}) -> Type{𝔽<:Field}
58-
59-
Return the type of field `𝔽` of a tensor.
60-
"""
61-
field(::Type{TT}) where {TT<:AbstractTensorMap} = field(spacetype(TT))
62-
6341
@doc """
6442
storagetype(t::AbstractTensorMap) -> Type{A<:AbstractVector}
6543
storagetype(T::Type{<:AbstractTensorMap}) -> Type{A<:AbstractVector}

0 commit comments

Comments
 (0)