Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Diskarrays 0.4 #247

Merged
merged 5 commits into from
Oct 24, 2024
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
fail-fast: false
matrix:
version:
- '1.6'
- 'lts'
- '1'
#- '~1.8.0-0'
- 'nightly'
Expand Down
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.5"
NetCDF_jll = "=400.701.400, =400.702.400, =400.902.5, =400.902.208, =400.902.209, =400.902.211"
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 @@ -443,7 +443,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 @@ -537,38 +538,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)
4 changes: 2 additions & 2 deletions test/test_check_size.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ ds["w"][:,1:15] = ones(10,15)
@test size(ds["w"]) == (10,15)

# w cannot grow along a fixed dimension
@test_throws DimensionMismatch ds["w"][:,:] = ones(11,15)
@test_throws Union{NCDatasets.NetCDFError,DimensionMismatch} ds["w"][:, :] = ones(11, 15)

# NetCDF: Index exceeds dimension bound
@test_throws NCDatasets.NetCDFError ds["u"][100,100]
@test_throws Union{NCDatasets.NetCDFError,BoundsError} ds["u"][100,100]
close(ds)
rm(filename)

Expand Down
2 changes: 1 addition & 1 deletion test/test_variable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ NCDataset(filename,"c") do ds

v = defVar(ds,"small",Float64,("lon","lat"))
# @test_throws Union{NCDatasets.NetCDFError,DimensionMismatch} v[:] = zeros(sz[1]+1,sz[2])
@test_throws DimensionMismatch v[1:sz[1],1:sz[2]] = zeros(sz[1]+1,sz[2])
@test_throws Union{NCDatasets.NetCDFError,DimensionMismatch} v[1:sz[1],1:sz[2]] = zeros(sz[1]+1,sz[2])
@test_throws NCDatasets.NetCDFError v[sz[1]+1,1] = 1
@test_throws NCDatasets.NetCDFError v[-1,1] = 1

Expand Down
Loading