From a9ec1d19bd1c5b5f2c0e593ef67db98daf8d45c9 Mon Sep 17 00:00:00 2001 From: Felix Cremer Date: Wed, 13 May 2026 17:47:23 +0200 Subject: [PATCH 1/8] Add tests for aggregate_diskarray function These are partially broken. --- test/test_interpolation.jl | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/test/test_interpolation.jl b/test/test_interpolation.jl index e69de29..755b397 100644 --- a/test/test_interpolation.jl +++ b/test/test_interpolation.jl @@ -0,0 +1,33 @@ +@testset "Interpolation" begin + a = [i+j+k for i in 1:4, j in 1:5, k in 1:6] + #source coordinates + x = 5.0:5.0:20.0 + y = 2.0:3.0:14.0 + #target coordinates + x2 = 5.0:0.5:20.0 + y2 = 1.5:1.0:14.5 + r = interpolate_diskarray(a,(1=>(x,x2),2=>(y,y2))) +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 \ No newline at end of file From 9864839487ac3df6850d420eacf767ff065eabe5 Mon Sep 17 00:00:00 2001 From: Felix Cremer Date: Wed, 13 May 2026 17:48:59 +0200 Subject: [PATCH 2/8] Start adding aggregate_diskarray docstring --- src/util/aggregate.jl | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/util/aggregate.jl b/src/util/aggregate.jl index aa58e76..b69e588 100644 --- a/src/util/aggregate.jl +++ b/src/util/aggregate.jl @@ -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) @@ -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 From 8ac118f591b3de7a62b7e93710ee3b8dd2fe6e9f Mon Sep 17 00:00:00 2001 From: Felix Cremer Date: Mon, 18 May 2026 13:12:09 +0200 Subject: [PATCH 3/8] Fix show of Loop windows object this removes ... if the window length is less then 4 --- src/mwops.jl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/mwops.jl b/src/mwops.jl index 3d7037c..657dd2e 100644 --- a/src/mwops.jl +++ b/src/mwops.jl @@ -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 From 961cffb426f19cd3e44f4e0d179e92f0b72c7198 Mon Sep 17 00:00:00 2001 From: Felix Cremer Date: Mon, 18 May 2026 15:15:08 +0200 Subject: [PATCH 4/8] Add tests for interpolate_diskarrays --- test/test_interpolation.jl | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/test/test_interpolation.jl b/test/test_interpolation.jl index 755b397..f4ea34c 100644 --- a/test/test_interpolation.jl +++ b/test/test_interpolation.jl @@ -1,12 +1,21 @@ @testset "Interpolation" begin - a = [i+j+k for i in 1:4, j in 1:5, k in 1:6] + a = [i+j for i in 1:5, j in 1:7, k=1:6] #source coordinates - x = 5.0:5.0:20.0 - y = 2.0:3.0:14.0 + x = 2.0:2.0:10.0 + y = 2.0:2.0:14.0 #target coordinates - x2 = 5.0:0.5:20.0 - y2 = 1.5:1.0:14.5 - r = interpolate_diskarray(a,(1=>(x,x2),2=>(y,y2))) + 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_broken rout[1,1,1] == a[1,1,1] + r = interpolate_diskarray(a, (1=>(x, xedge), 2=>(y, youter))) + compute(r) + # Interestingly we need the third dimension for this to fail. end @testset "Aggregate" begin From 8f7bad69ff206c663eb89e49994eba24bf4a59c3 Mon Sep 17 00:00:00 2001 From: Felix Cremer Date: Mon, 18 May 2026 15:15:29 +0200 Subject: [PATCH 5/8] Start show method for GMWOPResult --- src/diskarrayresults.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/diskarrayresults.jl b/src/diskarrayresults.jl index a39a677..537764a 100644 --- a/src/diskarrayresults.jl +++ b/src/diskarrayresults.jl @@ -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 \ No newline at end of file From 78176daa07299baad3a60e58603153b1e6eebdee Mon Sep 17 00:00:00 2001 From: Felix Cremer Date: Tue, 19 May 2026 11:18:07 +0200 Subject: [PATCH 6/8] include interpolate and aggregate tests --- test/runtests.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/test/runtests.jl b/test/runtests.jl index 84b2b26..8556bfc 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -9,3 +9,4 @@ include("test_distribute.jl") include("test_restart.jl") include("test_graph.jl") include("test_mergeops.jl") +include("test_interpolation.jl") \ No newline at end of file From c3c7b8781e98e16f0489d346ddc082c145ec6f05 Mon Sep 17 00:00:00 2001 From: Felix Cremer Date: Tue, 19 May 2026 16:06:38 +0200 Subject: [PATCH 7/8] Fix interpolate by removing range dispatch --- src/util/interpolate.jl | 3 ++- test/test_interpolation.jl | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/util/interpolate.jl b/src/util/interpolate.jl index 5065cad..753257a 100644 --- a/src/util/interpolate.jl +++ b/src/util/interpolate.jl @@ -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 diff --git a/test/test_interpolation.jl b/test/test_interpolation.jl index f4ea34c..e6f60c2 100644 --- a/test/test_interpolation.jl +++ b/test/test_interpolation.jl @@ -12,10 +12,11 @@ @test size(redge) == (9,7, 6) rout = interpolate_diskarray(a,(2=>(y,youter),)) @test size(rout) == (5,25, 6) - @test_broken rout[1,1,1] == a[1,1,1] + @test rout[1,1,1] == a[1,1,1] r = interpolate_diskarray(a, (1=>(x, xedge), 2=>(y, youter))) - compute(r) - # Interestingly we need the third dimension for this to fail. + @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 From 741f5fe95ada443caadfbbde6dce101d4b76d1f6 Mon Sep 17 00:00:00 2001 From: Felix Cremer Date: Tue, 19 May 2026 16:21:17 +0200 Subject: [PATCH 8/8] Add Statistics as test dep --- test/Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Project.toml b/test/Project.toml index b77b8f4..0c8d77a 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -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"