Skip to content

Commit 226f01d

Browse files
authored
Fix #141 (#142)
1 parent ac2fbec commit 226f01d

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/blockreduce.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ Base.mapfoldl(f::F, op::OP, B::PseudoBlockArray; kw...) where {F, OP} =
1616

1717
Base.mapreduce(f::F, op::OP, B::PseudoBlockArray; kw...) where {F, OP} =
1818
mapreduce(f, op, B.blocks; kw...)
19+
20+
# support sum, need to return something analoguous to Base.OneTo(1) but same type
21+
Base.reduced_index(::BR) where BR<:BlockedUnitRange = convert(BR, Base.OneTo(1))

test/test_blockreduce.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,13 @@ end
1515
x = PseudoBlockVector(rand(Int, 3), [1, 2])
1616
@test reduce(+, x) == sum(collect(x))
1717
end
18+
19+
@testset "sum (#141)" begin
20+
data = reshape(collect(1:20), 4, 5)
21+
A = BlockArray(data, [1,3], [2,3])
22+
@test sum(A) == sum(data)
23+
@test sum(A; dims=1) == sum(data; dims=1)
24+
@test sum(A; dims=2) == sum(data; dims=2)
25+
@test blockisequal(axes(A,2), axes(sum(A; dims=1),2))
26+
@test blockisequal(axes(A,1), axes(sum(A; dims=2),1))
27+
end

0 commit comments

Comments
 (0)