Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/BlockSparseArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module BlockSparseArrays
include("BlockArraysExtensions/BlockArraysExtensions.jl")
include("blocksparsearrayinterface/blocksparsearrayinterface.jl")
include("blocksparsearrayinterface/linearalgebra.jl")
include("blocksparsearrayinterface/blockzero.jl")
include("blocksparsearrayinterface/getunstoredblock.jl")
include("blocksparsearrayinterface/broadcast.jl")
include("blocksparsearrayinterface/map.jl")
include("blocksparsearrayinterface/arraylayouts.jl")
Expand Down
2 changes: 1 addition & 1 deletion src/blocksparsearray/defaults.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ function default_blocks(
block_data::Dictionary{<:CartesianIndex{N},<:AbstractArray{<:Any,N}},
axes::Tuple{Vararg{AbstractUnitRange,N}},
) where {N}
return SparseArrayDOK(block_data, blocklength.(axes), BlockZero(axes))
return SparseArrayDOK(block_data, blocklength.(axes), GetUnstoredBlock(axes))
end
17 changes: 7 additions & 10 deletions src/blocksparsearrayinterface/blocksparsearrayinterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
)
# TODO: Use `Block()[]` once https://github.com/JuliaArrays/BlockArrays.jl/issues/430
# is fixed.
return a[BlockIndex{0,Tuple{},Tuple{}}((), ())]
return a[BlockIndex()]

Check warning on line 68 in src/blocksparsearrayinterface/blocksparsearrayinterface.jl

View check run for this annotation

Codecov / codecov/patch

src/blocksparsearrayinterface/blocksparsearrayinterface.jl#L68

Added line #L68 was not covered by tests
end

# a[1:2, 1:2]
Expand Down Expand Up @@ -135,7 +135,7 @@
)
# TODO: Use `Block()[]` once https://github.com/JuliaArrays/BlockArrays.jl/issues/430
# is fixed.
a[BlockIndex{0,Tuple{},Tuple{}}((), ())] = value
a[BlockIndex()] = value

Check warning on line 138 in src/blocksparsearrayinterface/blocksparsearrayinterface.jl

View check run for this annotation

Codecov / codecov/patch

src/blocksparsearrayinterface/blocksparsearrayinterface.jl#L138

Added line #L138 was not covered by tests
return a
end

Expand Down Expand Up @@ -301,6 +301,8 @@
function Base.size(a::SparseSubArrayBlocks)
return length.(axes(a))
end
# TODO: Define `isstored`.
# TODO: Define `getstoredindex`, `getunstoredindex` instead.
function Base.getindex(a::SparseSubArrayBlocks{<:Any,N}, I::Vararg{Int,N}) where {N}
# TODO: Should this be defined as `@view a.array[Block(I)]` instead?
return @view a.array[Block(I)]
Expand All @@ -312,9 +314,11 @@
## return @view parent_block[blockindices(parent(a.array), block, a.array.indices)...]
end
# TODO: This should be handled by generic `AbstractSparseArray` code.
# TODO: Define `getstoredindex`, `getunstoredindex` instead.
function Base.getindex(a::SparseSubArrayBlocks{<:Any,N}, I::CartesianIndex{N}) where {N}
return a[Tuple(I)...]
end
# TODO: Define `setstoredindex!`, `setunstoredindex!` instead.
function Base.setindex!(a::SparseSubArrayBlocks{<:Any,N}, value, I::Vararg{Int,N}) where {N}
parent_blocks = @view blocks(parent(a.array))[blockrange(a)...]
# TODO: The following line is required to instantiate
Expand Down Expand Up @@ -345,18 +349,11 @@
## array::Array
## end

## TODO: Delete.
## TODO: Define `storedvalues` instead.
## function SparseArraysBase.sparse_storage(a::SparseSubArrayBlocks)
## return map(I -> a[I], eachstoredindex(a))
## end

## TODO: Delete.
## function SparseArraysBase.getindex_zero_function(a::SparseSubArrayBlocks)
## # TODO: Base it off of `getindex_zero_function(blocks(parent(a.array))`, but replace the
## # axes with `axes(a.array)`.
## return BlockZero(axes(a.array))
## end

function SparseArraysBase.getunstoredindex(
a::SparseSubArrayBlocks{<:Any,N}, I::Vararg{Int,N}
) where {N}
Expand Down
49 changes: 0 additions & 49 deletions src/blocksparsearrayinterface/blockzero.jl

This file was deleted.

25 changes: 25 additions & 0 deletions src/blocksparsearrayinterface/getunstoredblock.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using ArrayLayouts: zero!
using BlockArrays: Block

struct GetUnstoredBlock{Axes}
axes::Axes
end

@inline function (f::GetUnstoredBlock)(
a::AbstractArray{<:Any,N}, I::Vararg{Int,N}
) where {N}
# TODO: Make sure this works for sparse or block sparse blocks, immutable
# blocks, diagonal blocks, etc.!
b_size = ntuple(ndims(a)) do d
return length(f.axes[d][Block(I[d])])
end
b = similar(eltype(a), b_size)
zero!(b)
return b
end
# TODO: Use `Base.to_indices`.
@inline function (f::GetUnstoredBlock)(

Check warning on line 21 in src/blocksparsearrayinterface/getunstoredblock.jl

View check run for this annotation

Codecov / codecov/patch

src/blocksparsearrayinterface/getunstoredblock.jl#L21

Added line #L21 was not covered by tests
a::AbstractArray{<:Any,N}, I::CartesianIndex{N}
) where {N}
return f(a, Tuple(I)...)

Check warning on line 24 in src/blocksparsearrayinterface/getunstoredblock.jl

View check run for this annotation

Codecov / codecov/patch

src/blocksparsearrayinterface/getunstoredblock.jl#L24

Added line #L24 was not covered by tests
end
Loading