Skip to content

Commit

Permalink
update to Diskarrays 0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
meggart committed Feb 16, 2024
1 parent 1ebefed commit 72e5984
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
CFTime = "0.1.1"
CommonDataModel = "0.3.4"
DataStructures = "0.17, 0.18"
DiskArrays = "0.3.22"
DiskArrays = "0.4"
NetCDF_jll = "=400.701.400, =400.702.400, =400.902.5, =400.902.208, =400.902.209"
NetworkOptions = "1.2"
julia = "1.6"
Expand Down
38 changes: 2 additions & 36 deletions src/variable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,8 @@ function eachchunk(v::Variable)
return DiskArrays.GridChunks(v, chunksizes)
end
end
haschunks(v::Variable) = (_chunking(v)[1] == :contiguous ? DiskArrays.Unchunked() : DiskArrays.Chunked())
haschunks(v::Variable) = (_chunking(v)[1] == :contiguous ? DiskArrays.Unchunked(DiskArrays.SubRanges(DiskArrays.CanStepRange(),1.0)) :
DiskArrays.Chunked(DiskArrays.SubRanges(DiskArrays.CanStepRange(),1.0)))

eachchunk(v::CFVariable{T,N,<:Variable}) where {T,N} = eachchunk(v.var)
haschunks(v::CFVariable{T,N,<:Variable}) where {T,N} = haschunks(v.var)
Expand Down Expand Up @@ -554,38 +555,3 @@ function _range_indices_dest(of,v,rest...)
end
range_indices_dest(ri...) = _range_indices_dest((),ri...)

function _batchgetindex(
v::Variable{T},
indices::Union{<:Integer,Colon,AbstractRange{<:Integer},AbstractVector{<:Integer}}...) where T

@debug "transform vector of indices to ranges"

sz_source = size(v)
ri = to_range_list.(indices,sz_source)
sz_dest = size_getindex(v,indices...)

N = length(indices)

ri_dest = range_indices_dest(ri...)
@debug "ri_dest $ri_dest"
@debug "ri $ri"

if all(==(1),length.(ri))
# single chunk
R = first(CartesianIndices(length.(ri)))
ind_source = ntuple(i -> ri[i][R[i]],N)
ind_dest = ntuple(i -> ri_dest[i][R[i]],length(ri_dest))
return v[ind_source...]
end

dest = Array{eltype(v),length(sz_dest)}(undef,sz_dest)
for R in CartesianIndices(length.(ri))
ind_source = ntuple(i -> ri[i][R[i]],N)
ind_dest = ntuple(i -> ri_dest[i][R[i]],length(ri_dest))
dest[ind_dest...] = v[ind_source...]
end
return dest
end

DiskArrays.batchgetindex(v::Variable,indices::Union{<:Integer,Colon,AbstractRange{<:Integer},AbstractVector{<:Integer}}...) = _batchgetindex(v,indices...)
DiskArrays.batchgetindex(v::Variable,index::AbstractVector{Int}) = _batchgetindex(v,index)

0 comments on commit 72e5984

Please sign in to comment.