Skip to content

Commit a185415

Browse files
authored
Fix: let Revise.jl parse functions and docstrings correctly (#528)
1 parent d95e413 commit a185415

2 files changed

Lines changed: 23 additions & 38 deletions

File tree

‎docs/src/lib/tensors.md‎

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -118,22 +118,11 @@ subblock
118118
subblocks
119119
```
120120

121-
To access the data associated with a specific fusion tree pair, you can use:
121+
One can access the data of an `AbstractTensorMap` in multiple ways, its availability depending on the sector type of the tensor.
122+
In particular, the data of a tensor `t` can be accessed by specifying the fusion tree pair, the outcoming sectors if `FusionStyle(sectortype(t)) isa UniqueFusion`, or by multidimensional array indexing if `sectortype(t) == Trivial`.
122123
```@docs
123-
Base.getindex(::AbstractTensorMap, ::FusionTree, ::FusionTree)
124-
Base.setindex!(::AbstractTensorMap, ::Any, ::FusionTree, ::FusionTree)
125-
```
126-
127-
For a tensor `t` with `FusionStyle(sectortype(t)) isa UniqueFusion`, fusion trees are completely determined by the outcoming sectors, and the data can be accessed in a more straightforward way:
128-
```@docs
129-
Base.getindex(::AbstractTensorMap, ::Tuple{I,Vararg{I}}) where {I<:Sector}
130-
```
131-
132-
For tensor `t` with `sectortype(t) == Trivial`, the data can be accessed and manipulated directly as multidimensional arrays:
133-
```@docs
134-
Base.getindex(::AbstractTensorMap)
135-
Base.getindex(::AbstractTensorMap, ::Vararg{SliceIndex})
136-
Base.setindex!(::AbstractTensorMap, ::Any, ::Vararg{SliceIndex})
124+
Base.getindex(::AbstractTensorMap, args...)
125+
Base.setindex!(::AbstractTensorMap, args...)
137126
```
138127

139128
The tensor data can also be filled with random numbers via

‎src/tensors/abstracttensor.jl‎

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ Return a view into the data of `t` corresponding to the splitting - fusion tree
419419
`(f₁, f₂)`. In particular, this is an `AbstractArray{T}` with `T = scalartype(t)`, of size
420420
`(dims(codomain(t), f₁.uncoupled)..., dims(codomain(t), f₂.uncoupled)...)`.
421421
422-
Whenever `FusionStyle(sectortype(t)) isa UniqueFusion` , it is also possible to provide only
422+
Whenever `FusionStyle(sectortype(t)) isa UniqueFusion`, it is also possible to provide only
423423
the external `sectors`, in which case the fusion tree pair will be constructed automatically.
424424
"""
425425

@@ -496,8 +496,18 @@ $_doc_subblock
496496
As a result, modifying the view will modify the data in the tensor.
497497
498498
See also [`subblock`](@ref), [`subblocks`](@ref) and [`fusiontrees`](@ref).
499-
""" Base.getindex(::AbstractTensorMap, ::Tuple{I, Vararg{I}}) where {I <: Sector},
500-
Base.getindex(::AbstractTensorMap, ::FusionTree, ::FusionTree)
499+
500+
Base.getindex(t::AbstractTensorMap, indices::Vararg{Int})
501+
t[indices]
502+
503+
Return a view into the data slice of `t` corresponding to `indices`, by slicing the
504+
`StridedViews.StridedView` into the full data array.
505+
506+
Base.getindex(t::AbstractTensorMap)
507+
t[]
508+
509+
Return a view into the data of `t` as a `StridedViews.StridedView` of size `dims(t)`.
510+
""" Base.getindex(::AbstractTensorMap, args...)
501511

502512
@inline Base.getindex(t::AbstractTensorMap, sectors::Tuple{I, Vararg{I}}) where {I <: Sector} =
503513
subblock(t, sectors)
@@ -514,8 +524,12 @@ Copies `v` into the data slice of `t` corresponding to the splitting - fusion tr
514524
By default, `v` can be any object that can be copied into the view associated with `t[f₁, f₂]`.
515525
516526
See also [`subblock`](@ref), [`subblocks`](@ref) and [`fusiontrees`](@ref).
517-
""" Base.setindex!(::AbstractTensorMap, ::Any, ::Tuple{I, Vararg{I}}) where {I <: Sector},
518-
Base.setindex!(::AbstractTensorMap, ::Any, ::FusionTree, ::FusionTree)
527+
528+
Base.setindex!(t::AbstractTensorMap, v, indices::Vararg{Int})
529+
t[indices] = v
530+
531+
Assigns `v` to the data slice of `t` corresponding to `indices`.
532+
""" Base.setindex!(::AbstractTensorMap, args...)
519533

520534
@inline Base.setindex!(t::AbstractTensorMap, v, sectors::Tuple{I, Vararg{I}}) where {I <: Sector} =
521535
copy!(subblock(t, sectors), v)
@@ -530,25 +544,13 @@ using TensorKit.Strided: SliceIndex
530544
# TODO: should we allow range indices as well
531545
# TODO 2: should we enable this for (abelian) symmetric tensors with some CUDA like `allowscalar` flag?
532546
# TODO 3: should we then also allow at least `getindex` for nonabelian tensors
533-
"""
534-
Base.getindex(t::AbstractTensorMap, indices::Vararg{Int})
535-
t[indices]
536-
537-
Return a view into the data slice of `t` corresponding to `indices`, by slicing the
538-
`StridedViews.StridedView` into the full data array.
539-
"""
540547
@inline function Base.getindex(t::AbstractTensorMap, indices::Vararg{SliceIndex})
541548
data = t[trivial_fusiontree(t)...]
542549
@boundscheck checkbounds(data, indices...)
543550
@inbounds v = data[indices...]
544551
return v
545552
end
546-
"""
547-
Base.setindex!(t::AbstractTensorMap, v, indices::Vararg{Int})
548-
t[indices] = v
549553

550-
Assigns `v` to the data slice of `t` corresponding to `indices`.
551-
"""
552554
@inline function Base.setindex!(t::AbstractTensorMap, v, indices::Vararg{SliceIndex})
553555
data = t[trivial_fusiontree(t)...]
554556
@boundscheck checkbounds(data, indices...)
@@ -558,12 +560,6 @@ end
558560

559561
# TODO : probably deprecate the following
560562
# For a tensor with trivial symmetry, allow no argument indexing
561-
"""
562-
Base.getindex(t::AbstractTensorMap)
563-
t[]
564-
565-
Return a view into the data of `t` as a `StridedViews.StridedView` of size `dims(t)`.
566-
"""
567563
@inline function Base.getindex(t::AbstractTensorMap)
568564
return t[trivial_fusiontree(t)...]
569565
end

0 commit comments

Comments
 (0)