Skip to content

Commit 3fccb53

Browse files
tkfdlfivefifty
authored andcommitted
Define dataids for BlockArray (#65)
1 parent 4cfcc05 commit 3fccb53

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

src/BlockArrays.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import Base: @propagate_inbounds, Array, to_indices, to_index,
2323
RangeIndex, Int, Integer, Number,
2424
+, -, min, max, *, isless, in, copy, copyto!, axes, @deprecate,
2525
BroadcastStyle
26+
using Base: dataids
2627

2728

2829

src/blockarray.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,10 @@ end
276276
getblock(block_array, block_index.I...)[block_index.α...] = v
277277
end
278278

279+
Base.dataids(arr::BlockArray) = (dataids(arr.blocks)..., dataids(arr.block_sizes)...)
280+
# This is not entirely valid. In principle, we have to concatenate
281+
# all dataids of all blocks. However, it makes `dataids` non-inferable.
282+
279283
########
280284
# Misc #
281285
########

src/blocksizes.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ BlockSizes(sizes::Vararg{AbstractVector{Int}, N}) where {N} =
2626

2727
Base.:(==)(a::BlockSizes, b::BlockSizes) = cumulsizes(a) == cumulsizes(b)
2828

29+
Base.dataids(b::BlockSizes) = _splatmap(dataids, b.cumul_sizes)
30+
# _splatmap taken from Base:
31+
_splatmap(f, ::Tuple{}) = ()
32+
_splatmap(f, t::Tuple) = (f(t[1])..., _splatmap(f, tail(t))...)
33+
2934
function _cumul_vec(v::AbstractVector{T}) where {T}
3035
v_cumul = similar(v, length(v) + 1)
3136
z = one(T)

0 commit comments

Comments
 (0)