-
Notifications
You must be signed in to change notification settings - Fork 64
Refactor index manipulation kernels around position-indexed subblocks #526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lkdvos
wants to merge
3
commits into
main
Choose a base branch
from
ld-adjoint
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -171,3 +171,73 @@ function Base.show(io::IO, mime::MIME"text/plain", iter::SubblockIterator) | |||||
| show_subblocks(io, mime, iter) | ||||||
| return nothing | ||||||
| end | ||||||
|
|
||||||
|
lkdvos marked this conversation as resolved.
|
||||||
| """ | ||||||
| struct StridedSubblocks{A <: DenseVector, N, F} | ||||||
| StridedSubblocks(t::TensorMap, [op = identity]) | ||||||
|
|
||||||
| Sector-independent, integer-indexable collection of the subblocks of a `TensorMap`, as | ||||||
| `StridedView`s into its flat data vector. Subblock `i` corresponds to the `i`th fusion tree pair | ||||||
| in the canonical order of `fusiontrees(space(t))`, see also [`fusiontreeindices`](@ref). | ||||||
| The operation `op` (`identity` or `conj`) is applied lazily to every view, which allows | ||||||
| representing the subblocks of a conjugated tensor without materializing it. | ||||||
|
|
||||||
| This is the data structure consumed by the index manipulation kernels, whose type does not | ||||||
| depend on the sectortype of `t`. | ||||||
| """ | ||||||
| const SubblockOp = Union{typeof(identity), typeof(conj)} | ||||||
| struct StridedSubblocks{A <: DenseVector, N, F <: SubblockOp} | ||||||
| data::A | ||||||
| structure::Vector{StridedStructure{N}} | ||||||
| op::F | ||||||
| end | ||||||
| Base.length(s::StridedSubblocks) = length(s.structure) | ||||||
| Base.firstindex(s::StridedSubblocks) = 1 | ||||||
| Base.lastindex(s::StridedSubblocks) = length(s) | ||||||
| Base.eltype(::Type{S}) where {S <: StridedSubblocks} = Core.Compiler.return_type(getindex, Tuple{S, Int}) | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this a bit lazy? Why not:
Suggested change
|
||||||
|
|
||||||
| Base.@propagate_inbounds function Base.getindex(s::StridedSubblocks, i::Int) | ||||||
| sz, str, offset = s.structure[i] | ||||||
| return StridedView(s.data, sz, str, offset, s.op) | ||||||
| end | ||||||
|
|
||||||
| function Base.iterate(s::StridedSubblocks, i::Int = 1) | ||||||
| i > length(s) && return nothing | ||||||
| return @inbounds(s[i]), i + 1 | ||||||
| end | ||||||
|
|
||||||
| storagetype(::Type{StridedSubblocks{A, N, F}}) where {A, N, F} = A | ||||||
|
|
||||||
| """ | ||||||
| struct TreeSubblocks{TT <: AbstractTensorMap, I, F} | ||||||
| TreeSubblocks(t::AbstractTensorMap, [op = identity]) | ||||||
|
|
||||||
| Integer-indexable collection of the subblocks of an arbitrary tensor `t`, where position `i` | ||||||
| refers to the `i`th fusion tree pair of `fusiontrees(space(t))` and the data is retrieved through | ||||||
| [`subblock`](@ref), with `op` (`identity` or `conj`) applied. This is the generic counterpart of | ||||||
| [`StridedSubblocks`](@ref) for tensor types that do not store their data in a flat vector. | ||||||
| """ | ||||||
| struct TreeSubblocks{TT <: AbstractTensorMap, I, F <: SubblockOp} | ||||||
| t::TT | ||||||
| trees::I | ||||||
| op::F | ||||||
| end | ||||||
| function TreeSubblocks(t::AbstractTensorMap, op::SubblockOp = identity) | ||||||
| return TreeSubblocks(t, fusiontrees(t), scalartype(t) <: Real ? identity : op) | ||||||
| end | ||||||
|
|
||||||
| storagetype(::Type{TreeSubblocks{TT, I, F}}) where {TT, I, F} = storagetype(TT) | ||||||
|
|
||||||
| Base.length(s::TreeSubblocks) = length(s.trees) | ||||||
| Base.firstindex(s::TreeSubblocks) = 1 | ||||||
| Base.lastindex(s::TreeSubblocks) = length(s) | ||||||
| Base.eltype(::Type{S}) where {S <: TreeSubblocks} = Core.Compiler.return_type(getindex, Tuple{S, Int}) | ||||||
|
|
||||||
| Base.@propagate_inbounds function Base.getindex(s::TreeSubblocks, i::Int) | ||||||
| return s.op(subblock(s.t, gettokenvalue(s.trees, i))) | ||||||
| end | ||||||
|
|
||||||
| function Base.iterate(s::TreeSubblocks, i::Int = 1) | ||||||
| i > length(s) && return nothing | ||||||
| return @inbounds(s[i]), i + 1 | ||||||
| end | ||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
heterogeneous key choice? Does this only affect how the results are displayed?