Skip to content
Closed
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
11 changes: 11 additions & 0 deletions src/mapreduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,14 @@ macro implement_mapreduce(t)
end
end
end


# optimized implementation for special cases

for fname in [:sum,:prod,:count,:all,:any,:minimum,:maximum]
@eval function Base.$fname(v::AbstractDiskArray)
$fname(eachchunk(v)) do chunk
$fname(v[chunk...])
end
end
end
15 changes: 14 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -907,10 +907,23 @@ end
@test getindex_count(A) == 0
end

@testset "optimization for associative reductions" begin
A = rand(1:10,30,30)
DA = AccessCountDiskArray(A,chunksize=(2,2))

for fun in (sum, prod, maximum, minimum)
@test fun(A) == fun(DA)
end

Ab = rand(Bool,30,30)
DAb = AccessCountDiskArray(Ab,chunksize=(2,2))
for fun in (count, all, any)
@test fun(Ab) == fun(DAb)
end
end

# @test offsets == [[1:1,2:3,4:4],[5:5,6:6,7:7],[8:8,9:9]]
# inds = [1,1,1,3,5,6,6,7,10,13,16,16,19,20]
# readranges, offsets = find_subranges_sorted(inds,false)
# @test readranges == [1:1, 3:3, 5:7, 10:10, 13:13, 16:16, 19:20]
# @test offsets == [[1:3], [4:4], [5:5,6:7,8:8], [9:9], [10:10], [11:12], [13:13,14:14]]
# @test offsets == [[1:3], [4:4], [5:5,6:7,8:8], [9:9], [10:10], [11:12], [13:13,14:14]]