-
Notifications
You must be signed in to change notification settings - Fork 2
Noncontiguous slicing #116
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0b786d7
Unblocked slicing
mtfishman 0d11eec
Noncontiguous slicing on GPU
mtfishman 11bede8
Fix test on GPU
mtfishman 3b6cb1e
Bump version
mtfishman 5e53555
Start fixing more slicing
mtfishman e80370e
More general eachstoredindex/isstored for SubArray blocks
mtfishman 3e4a0a1
Fix tests
mtfishman 38782d8
Update comments in tests
mtfishman 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "BlockSparseArrays" | ||
uuid = "2c9a651f-6452-4ace-a6ac-809f4280fbb4" | ||
authors = ["ITensor developers <[email protected]> and contributors"] | ||
version = "0.5.1" | ||
version = "0.5.2" | ||
|
||
[deps] | ||
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e" | ||
|
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
using ArrayLayouts: ArrayLayouts, MemoryLayout | ||
using Base.Broadcast: Broadcast, BroadcastStyle | ||
using BlockArrays: BlockArrays, Block, BlockIndexRange, BlockSlice | ||
using TypeParameterAccessors: TypeParameterAccessors, parenttype, similartype | ||
|
||
const UnblockedIndices = Union{ | ||
Vector{<:Integer},BlockSlice{<:Block{1}},BlockSlice{<:BlockIndexRange{1}} | ||
} | ||
|
||
const UnblockedSubArray{T,N} = SubArray{ | ||
T,N,<:AbstractBlockSparseArray{T,N},<:Tuple{Vararg{UnblockedIndices}} | ||
} | ||
|
||
function BlockArrays.blocks(a::UnblockedSubArray) | ||
return SingleBlockView(a) | ||
end | ||
|
||
function DerivableInterfaces.interface(arraytype::Type{<:UnblockedSubArray}) | ||
return interface(blocktype(parenttype(arraytype))) | ||
end | ||
|
||
function ArrayLayouts.MemoryLayout(arraytype::Type{<:UnblockedSubArray}) | ||
return MemoryLayout(blocktype(parenttype(arraytype))) | ||
end | ||
|
||
function Broadcast.BroadcastStyle(arraytype::Type{<:UnblockedSubArray}) | ||
return BroadcastStyle(blocktype(parenttype(arraytype))) | ||
end | ||
|
||
function TypeParameterAccessors.similartype(arraytype::Type{<:UnblockedSubArray}, elt::Type) | ||
return similartype(blocktype(parenttype(arraytype)), elt) | ||
end | ||
|
||
function Base.similar( | ||
a::UnblockedSubArray, elt::Type, axes::Tuple{Base.OneTo,Vararg{Base.OneTo}} | ||
) | ||
return similar(similartype(blocktype(parenttype(a)), elt), axes) | ||
end | ||
function Base.similar(a::UnblockedSubArray, elt::Type, size::Tuple{Int,Vararg{Int}}) | ||
return similar(a, elt, Base.OneTo.(size)) | ||
end | ||
|
||
function ArrayLayouts.sub_materialize(a::UnblockedSubArray) | ||
a_cpu = adapt(Array, a) | ||
a_cpu′ = similar(a_cpu) | ||
a_cpu′ .= a_cpu | ||
if typeof(a) === typeof(a_cpu) | ||
return a_cpu′ | ||
end | ||
a′ = similar(a) | ||
a′ .= a_cpu′ | ||
return a′ | ||
end | ||
|
||
function Base.map!( | ||
f, a_dest::AbstractArray, a_src1::UnblockedSubArray, a_src_rest::UnblockedSubArray... | ||
) | ||
return invoke( | ||
map!, | ||
Tuple{Any,AbstractArray,AbstractArray,Vararg{AbstractArray}}, | ||
f, | ||
a_dest, | ||
a_src1, | ||
a_src_rest..., | ||
) | ||
end | ||
|
||
# Fix ambiguity and scalar indexing errors with GPUArrays. | ||
using Adapt: adapt | ||
using GPUArraysCore: GPUArraysCore | ||
function Base.map!( | ||
f, | ||
a_dest::GPUArraysCore.AnyGPUArray, | ||
a_src1::UnblockedSubArray, | ||
a_src_rest::UnblockedSubArray..., | ||
) | ||
a_dest_cpu = adapt(Array, a_dest) | ||
a_srcs_cpu = map(adapt(Array), (a_src1, a_src_rest...)) | ||
map!(f, a_dest_cpu, a_srcs_cpu...) | ||
a_dest .= a_dest_cpu | ||
return a_dest | ||
end | ||
|
||
function Base.iszero(a::UnblockedSubArray) | ||
return invoke(iszero, Tuple{AbstractArray}, adapt(Array, a)) | ||
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
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.
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.
Uh oh!
There was an error while loading. Please reload this page.