Skip to content
Open
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
5 changes: 5 additions & 0 deletions src/diskarrayresults.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,9 @@ end
end
function compute(a::DiskArrayEngine.GMWOPResult;runner=LocalRunner,threaded=true,kwargs...)
compute!(nothing,a;runner,threaded,kwargs...)
end

function Base.show(io::IO,::MIME"text/plain",z::GMWOPResult)
println(io, "GMWOPResult of size $(size(z))")
println("Inputs:")
end
9 changes: 7 additions & 2 deletions src/mwops.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@ function Base.show(io::IO,::MIME"text/plain",lw::LoopWindows)
print(io,"$li: Window of length $(length(w)) [")
showifthere(io,w,1,sep=false)
showifthere(io,w,2)
print(io," ... ")
showifthere(io,w,max(length(w)-1,3),sep=false)
if length(w) > 4
print(io," ... ")
elseif length(w) > 2
print(io, ", ")
end
showifthere(io,w,max(length(w)-1,3), sep=false)
showifthere(io,w,max(length(w),4))

end
print(io, "]")
end
function showifthere(io,w,i;sep=true)
if length(w)>=i
Expand Down
13 changes: 12 additions & 1 deletion src/util/aggregate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ function gmwop_for_aggregator(agg,dimspec,inar;ismem=false,outchunks=nothing)
return GMDWop(tuple(inars),tuple(outspecs),agg.f)
end

# Todo Move function to first argument to enable do-blocks
"""
aggregate_diskarray(a, f, dimspec; skipmissing=false, strategy=:auto,outchunks=nothing)

Aggregate a DiskArray `a` with the aggregation function f.

Certain functions are special cased and will use OnlineStats if possible to speed up the computation.
This will never happen if you use a do-block.
```julia
aggregate_diskarray(a,mean,(2=>nothing,3=>4,4=>[1,1,1,2,2,2,3,3,3,4,4,4,4,4,5,5,5]))
"""
function aggregate_diskarray(a, f, dimspec; skipmissing=false, strategy=:auto,outchunks=nothing)

hasmissings = Missing <: eltype(a)
Expand Down Expand Up @@ -101,7 +112,7 @@ function aggregate_diskarray(a, f, dimspec; skipmissing=false, strategy=:auto,ou
p2 = optimize_loopranges(op2,5e8)
c1 = actual_io_costs(p1)
c2 = actual_io_costs(p2)
#we still prefer direct aggregatoin, so we giv it a slight lead:
#we still prefer direct aggregation, so we give it a slight lead:
op = c1*0.9 < c2 ? op1 : op2
results_as_diskarrays(op)[1]
else
Expand Down
3 changes: 2 additions & 1 deletion src/util/interpolate.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using Interpolations: BSpline, Linear, NoInterp, extrapolate, interpolate, Flat
export interpolate_diskarray, interpolate_diskarray!

#=
function getinterpinds(oldvals::AbstractRange, newvals::AbstractRange)
(newvals.-first(oldvals))./step(oldvals).+1
end
=#
function getinterpinds(r1,r2)
rev = issorted(r1) ? false : issorted(r1,rev=true) ? true : error("Axis values are not sorted")
map(r2) do ir
Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
DiskArrays = "3c3547ce-8d99-4f5e-a174-61eb10b00ae3"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Zarr = "0a941bbe-ad1d-11e8-39d9-ab76183a1d99"
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ include("test_distribute.jl")
include("test_restart.jl")
include("test_graph.jl")
include("test_mergeops.jl")
include("test_interpolation.jl")
43 changes: 43 additions & 0 deletions test/test_interpolation.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
@testset "Interpolation" begin
a = [i+j for i in 1:5, j in 1:7, k=1:6]
#source coordinates
x = 2.0:2.0:10.0
y = 2.0:2.0:14.0
#target coordinates
xedge = 2.0:1.0:10.0
youter = -5:1.0:19.
redge = interpolate_diskarray(a,(1=>(x,xedge),))
#compute(r)
@test redge[2,1,1] == 2.5
@test size(redge) == (9,7, 6)
rout = interpolate_diskarray(a,(2=>(y,youter),))
@test size(rout) == (5,25, 6)
@test rout[1,1,1] == a[1,1,1]
r = interpolate_diskarray(a, (1=>(x, xedge), 2=>(y, youter)))
@test compute(r)[2,1,1] == 2.5
@test compute(r)[2,2,1] == 2.5
@test r[1,13,1] == 4.5
end

@testset "Aggregate" begin
using Statistics
a = [i+j+k for i in 1:4, j in 1:5, k in 1:6]
agg_mean = aggregate_diskarray(a, mean, (1=>nothing,))
@test size(agg_mean) == (1,5,6)
@test agg_mean[:,:,:] == mean(a, dims=1)
agg_max = aggregate_diskarray(a, maximum, (2=>nothing,), strategy=:reduce)
# This gives all ones for some reason
@test_broken agg_max[:,:,:] == maximum(a, dims=2)
agg_sec = aggregate_diskarray(a, mean, (2=>2,))
# This should work but currently throws a bounds error
@test_throws BoundsError agg_sec[:,:,:]
agg_minimum = aggregate_diskarray(a, minimum, (3=>3,), strategy=:reduce)
@test agg_minimum[:,:,1] == minimum(a, dims=3)[:,:]
@test agg_minimum[:,:,2] == minimum(a, dims=3)[:,:] .+ 3
@test_broken eltype(agg_minimum) == Int
agg_minimum_direct = aggregate_diskarray(a, minimum, (3=>3,), strategy=:reduce)
@test agg_minimum_direct[:,:,1] == minimum(a, dims=3)[:,:]
@test agg_minimum_direct[:,:,2] == minimum(a, dims=3)[:,:] .+ 3
@test_broken eltype(agg_minimum_direct) == Int
# Why is the element type of minimum of an Int array Union{Missing, Float64}?
end
Loading