Skip to content

Commit

Permalink
Make sure init is always inside the domain
Browse files Browse the repository at this point in the history
  • Loading branch information
meggart committed Feb 22, 2023
1 parent 477f311 commit 5aac674
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Cubes/Rechunker.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,19 @@ function get_copy_buffer_size(incube, outcube;writefac=4.0, maxbuf = YAXDefaults
if nd == 1
return (min(maxbuf,length(incube)),)
end
init = fill(maxbuf^(1/nd),nd-1)
incs = DiskArrays.approx_chunksize(eachchunk(incube))
outcs = DiskArrays.approx_chunksize(eachchunk(outcube))
insize = size(incube)
outsize = size(outcube)
totsize = prod(insize)
incs = DiskArrays.approx_chunksize(eachchunk(incube))
outcs = DiskArrays.approx_chunksize(eachchunk(outcube))
#Catch case where buffer is larger than cube
if maxbuf > prod(insize)
return insize
end
init = [(Float64(maxbuf)*insize[i]^(nd)/totsize)^(1/nd) for i in 1:(nd-1)]
@debug "Init: ", init
r = optimize(sz->optifunc(sz,maxbuf,incs,outcs,insize, outsize,writefac),init, iterations=100)
@debug "Optimization result: $(r.minimizer)"
bufnow = (r.minimizer...,maxbuf/prod(r.minimizer))

bufcorrected = if align_output
Expand All @@ -91,6 +94,9 @@ end
function copy_diskarray(incube,outcube;writefac=4.0, maxbuf = YAXDefaults.max_cache[], align_output=true)
size(incube) == size(outcube) || throw(ArgumentError("Input and output cubes must have the same size"))
bufcorrected = get_copy_buffer_size(incube, outcube;writefac,maxbuf,align_output)
@debug "Copying with buffer size $bufcorrected"
@debug "Input chunk size: $(eachchunk(incube).chunks)"
@debug "Output chunk size: $(eachchunk(outcube).chunks)"
copybuf = DiskArrays.GridChunks(size(outcube),bufcorrected)
copydata(outcube,incube,copybuf)
end
Expand Down

3 comments on commit 5aac674

@dpabon
Copy link
Contributor

@dpabon dpabon commented on 5aac674 Feb 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change solved #237

@meggart
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error while trying to register: "Tag with name v0.4.4 already exists and points to a different commit"

Please sign in to comment.