Skip to content

Commit 797e321

Browse files
authored
Rename BlockZero to GetUnstoredBlock (#15)
1 parent abe5237 commit 797e321

File tree

5 files changed

+34
-61
lines changed

5 files changed

+34
-61
lines changed

src/BlockSparseArrays.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module BlockSparseArrays
22
include("BlockArraysExtensions/BlockArraysExtensions.jl")
33
include("blocksparsearrayinterface/blocksparsearrayinterface.jl")
44
include("blocksparsearrayinterface/linearalgebra.jl")
5-
include("blocksparsearrayinterface/blockzero.jl")
5+
include("blocksparsearrayinterface/getunstoredblock.jl")
66
include("blocksparsearrayinterface/broadcast.jl")
77
include("blocksparsearrayinterface/map.jl")
88
include("blocksparsearrayinterface/arraylayouts.jl")

src/blocksparsearray/defaults.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ function default_blocks(
3838
block_data::Dictionary{<:CartesianIndex{N},<:AbstractArray{<:Any,N}},
3939
axes::Tuple{Vararg{AbstractUnitRange,N}},
4040
) where {N}
41-
return SparseArrayDOK(block_data, blocklength.(axes), BlockZero(axes))
41+
return SparseArrayDOK(block_data, blocklength.(axes), GetUnstoredBlock(axes))
4242
end

src/blocksparsearrayinterface/blocksparsearrayinterface.jl

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ end
6565
)
6666
# TODO: Use `Block()[]` once https://github.com/JuliaArrays/BlockArrays.jl/issues/430
6767
# is fixed.
68-
return a[BlockIndex{0,Tuple{},Tuple{}}((), ())]
68+
return a[BlockIndex()]
6969
end
7070

7171
# a[1:2, 1:2]
@@ -135,7 +135,7 @@ end
135135
)
136136
# TODO: Use `Block()[]` once https://github.com/JuliaArrays/BlockArrays.jl/issues/430
137137
# is fixed.
138-
a[BlockIndex{0,Tuple{},Tuple{}}((), ())] = value
138+
a[BlockIndex()] = value
139139
return a
140140
end
141141

@@ -301,6 +301,8 @@ end
301301
function Base.size(a::SparseSubArrayBlocks)
302302
return length.(axes(a))
303303
end
304+
# TODO: Define `isstored`.
305+
# TODO: Define `getstoredindex`, `getunstoredindex` instead.
304306
function Base.getindex(a::SparseSubArrayBlocks{<:Any,N}, I::Vararg{Int,N}) where {N}
305307
# TODO: Should this be defined as `@view a.array[Block(I)]` instead?
306308
return @view a.array[Block(I)]
@@ -312,9 +314,11 @@ function Base.getindex(a::SparseSubArrayBlocks{<:Any,N}, I::Vararg{Int,N}) where
312314
## return @view parent_block[blockindices(parent(a.array), block, a.array.indices)...]
313315
end
314316
# TODO: This should be handled by generic `AbstractSparseArray` code.
317+
# TODO: Define `getstoredindex`, `getunstoredindex` instead.
315318
function Base.getindex(a::SparseSubArrayBlocks{<:Any,N}, I::CartesianIndex{N}) where {N}
316319
return a[Tuple(I)...]
317320
end
321+
# TODO: Define `setstoredindex!`, `setunstoredindex!` instead.
318322
function Base.setindex!(a::SparseSubArrayBlocks{<:Any,N}, value, I::Vararg{Int,N}) where {N}
319323
parent_blocks = @view blocks(parent(a.array))[blockrange(a)...]
320324
# TODO: The following line is required to instantiate
@@ -345,18 +349,11 @@ SparseArraysBase.storedlength(a::SparseSubArrayBlocks) = length(eachstoredindex(
345349
## array::Array
346350
## end
347351

348-
## TODO: Delete.
352+
## TODO: Define `storedvalues` instead.
349353
## function SparseArraysBase.sparse_storage(a::SparseSubArrayBlocks)
350354
## return map(I -> a[I], eachstoredindex(a))
351355
## end
352356

353-
## TODO: Delete.
354-
## function SparseArraysBase.getindex_zero_function(a::SparseSubArrayBlocks)
355-
## # TODO: Base it off of `getindex_zero_function(blocks(parent(a.array))`, but replace the
356-
## # axes with `axes(a.array)`.
357-
## return BlockZero(axes(a.array))
358-
## end
359-
360357
function SparseArraysBase.getunstoredindex(
361358
a::SparseSubArrayBlocks{<:Any,N}, I::Vararg{Int,N}
362359
) where {N}

src/blocksparsearrayinterface/blockzero.jl

Lines changed: 0 additions & 49 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using ArrayLayouts: zero!
2+
using BlockArrays: Block
3+
4+
struct GetUnstoredBlock{Axes}
5+
axes::Axes
6+
end
7+
8+
@inline function (f::GetUnstoredBlock)(
9+
a::AbstractArray{<:Any,N}, I::Vararg{Int,N}
10+
) where {N}
11+
# TODO: Make sure this works for sparse or block sparse blocks, immutable
12+
# blocks, diagonal blocks, etc.!
13+
b_size = ntuple(ndims(a)) do d
14+
return length(f.axes[d][Block(I[d])])
15+
end
16+
b = similar(eltype(a), b_size)
17+
zero!(b)
18+
return b
19+
end
20+
# TODO: Use `Base.to_indices`.
21+
@inline function (f::GetUnstoredBlock)(
22+
a::AbstractArray{<:Any,N}, I::CartesianIndex{N}
23+
) where {N}
24+
return f(a, Tuple(I)...)
25+
end

0 commit comments

Comments
 (0)