File tree Expand file tree Collapse file tree 3 files changed +21
-0
lines changed
NDTensors/src/lib/BlockSparseArrays
ext/BlockSparseArraysAdaptExt/src
blocksparsearrayinterface Expand file tree Collapse file tree 3 files changed +21
-0
lines changed Original file line number Diff line number Diff line change 1+ module BlockSparseArraysAdaptExt
2+ using Adapt: Adapt, adapt
3+ using .. BlockSparseArrays: AbstractBlockSparseArray, map_stored_blocks
4+ Adapt. adapt_structure (to, x:: AbstractBlockSparseArray ) = map_stored_blocks (adapt (to), x)
5+ end
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ include("blocksparsearrayinterface/blocksparsearrayinterface.jl")
44include (" blocksparsearrayinterface/linearalgebra.jl" )
55include (" blocksparsearrayinterface/blockzero.jl" )
66include (" blocksparsearrayinterface/broadcast.jl" )
7+ include (" blocksparsearrayinterface/map.jl" )
78include (" blocksparsearrayinterface/arraylayouts.jl" )
89include (" blocksparsearrayinterface/views.jl" )
910include (" abstractblocksparsearray/abstractblocksparsearray.jl" )
@@ -20,4 +21,5 @@ include("blocksparsearray/blocksparsearray.jl")
2021include (" BlockArraysSparseArrayInterfaceExt/BlockArraysSparseArrayInterfaceExt.jl" )
2122include (" ../ext/BlockSparseArraysTensorAlgebraExt/src/BlockSparseArraysTensorAlgebraExt.jl" )
2223include (" ../ext/BlockSparseArraysGradedAxesExt/src/BlockSparseArraysGradedAxesExt.jl" )
24+ include (" ../ext/BlockSparseArraysAdaptExt/src/BlockSparseArraysAdaptExt.jl" )
2325end
Original file line number Diff line number Diff line change 1+ function map_stored_blocks (f, a:: AbstractArray )
2+ # TODO : Implement this as:
3+ # ```julia
4+ # mapped_blocks = SparseArraysInterface.map_stored(f, blocks(a))
5+ # BlockSparseArray(mapped_blocks, axes(a))
6+ # ```
7+ # TODO : `block_stored_indices` should output `Indices` storing
8+ # the stored Blocks, not a `Dictionary` from cartesian indices
9+ # to Blocks.
10+ bs = block_stored_indices (a)
11+ mapped_blocks = Dictionary (bs, map (b -> f (@view (a[b])), bs))
12+ # TODO : Use `similartype(typeof(a), eltype(eltype(mapped_blocks)))(...)`.
13+ return BlockSparseArray (mapped_blocks, axes (a))
14+ end
You can’t perform that action at this time.
0 commit comments