meggart / DiskArrays.jl

Other
79 stars 16 forks source link

Undef array for batch indexing #94

Closed tcarion closed 1 year ago

tcarion commented 1 year ago

When creating OffsetArray for batch indexing, it would currently fail for arrays for which elements have no zero methods. For example, with the _DiskArray from the tests:

cda = _DiskArray(rand(Char, 3, 4))
cda[[1, 2], [2, 4]]
ERROR: MethodError: no method matching zero(::Type{Char})
Closest candidates are:
  zero(::Union{Type{P}, P}) where P<:Dates.Period at ~/julia-1.7.3/share/julia/stdlib/v1.7/Dates/src/periods.jl:53
  zero(::T) where T<:Dates.TimeType at ~/julia-1.7.3/share/julia/stdlib/v1.7/Dates/src/types.jl:450
  zero(::LinearAlgebra.UniformScaling{T}) where T at ~/julia-1.7.3/share/julia/stdlib/v1.7/LinearAlgebra/src/uniformscaling.jl:136
  ...
Stacktrace:
 [1] zeros(#unused#::Type{Char}, dims::Tuple{Int64, Int64})
   @ Base ./array.jl:526
 [2] zeros(::Type{Char}, ::Int64, ::Int64)
   @ Base ./array.jl:521
 [3] disk_getindex_batch(ar::_DiskArray{Char, 2, Matrix{Char}}, indstoread::Matrix{Tuple{Int64, Int64}})
   @ DiskArrays ~/.julia/dev/DiskArrays/src/batchgetindex.jl:121
 [4] batchgetindex(::_DiskArray{Char, 2, Matrix{Char}}, ::Vector{Int64}, ::Vector{Int64})
   @ DiskArrays ~/.julia/dev/DiskArrays/src/batchgetindex.jl:72
 [5] getindex_disk(::_DiskArray{Char, 2, Matrix{Char}}, ::Vector{Int64}, ::Vararg{Vector{Int64}})
   @ DiskArrays ~/.julia/dev/DiskArrays/src/diskarray.jl:28
 [6] getindex(::_DiskArray{Char, 2, Matrix{Char}}, ::Vector{Int64}, ::Vector{Int64})
   @ Main ~/.julia/dev/DiskArrays/src/diskarray.jl:178

This issue originated from this discussion

tcarion commented 1 year ago

@rafaqz, do you think you could approve this PR? This would allow Alexander-Barth/NCDatasets.jl#205 to go further in the tests

rafaqz commented 1 year ago

Sorry it got lost in my feed.

@meggart was there a reason to use zeros here?

tcarion commented 1 year ago

Thanks!