-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BlockSparseArrays] Initial support for more general blocks, such as …
…GPU blocks (#1560)
- Loading branch information
Showing
13 changed files
with
257 additions
and
120 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
.../src/lib/BlockSparseArrays/ext/BlockSparseArraysAdaptExt/src/BlockSparseArraysAdaptExt.jl
This file contains 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,5 @@ | ||
module BlockSparseArraysAdaptExt | ||
using Adapt: Adapt, adapt | ||
using ..BlockSparseArrays: AbstractBlockSparseArray, map_stored_blocks | ||
Adapt.adapt_structure(to, x::AbstractBlockSparseArray) = map_stored_blocks(adapt(to), x) | ||
end |
This file contains 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 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 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 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 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 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 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 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 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
19 changes: 19 additions & 0 deletions
19
NDTensors/src/lib/BlockSparseArrays/src/blocksparsearrayinterface/map.jl
This file contains 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,19 @@ | ||
function map_stored_blocks(f, a::AbstractArray) | ||
# TODO: Implement this as: | ||
# ```julia | ||
# mapped_blocks = SparseArraysInterface.map_stored(f, blocks(a)) | ||
# BlockSparseArray(mapped_blocks, axes(a)) | ||
# ``` | ||
# TODO: `block_stored_indices` should output `Indices` storing | ||
# the stored Blocks, not a `Dictionary` from cartesian indices | ||
# to Blocks. | ||
bs = collect(block_stored_indices(a)) | ||
ds = map(b -> f(@view(a[b])), bs) | ||
# We manually specify the block type using `Base.promote_op` | ||
# since `a[b]` may not be inferrable. For example, if `blocktype(a)` | ||
# is `Diagonal{Float64,Vector{Float64}}`, the non-stored blocks are `Matrix{Float64}` | ||
# since they can't necessarily by `Diagonal` if there are rectangular blocks. | ||
mapped_blocks = Dictionary{eltype(bs),eltype(ds)}(bs, ds) | ||
# TODO: Use `similartype(typeof(a), eltype(eltype(mapped_blocks)))(...)`. | ||
return BlockSparseArray(mapped_blocks, axes(a)) | ||
end |
Oops, something went wrong.