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

Allowing broadcast operations to HDF5Dataset #586

Open
scottstanie opened this issue Oct 4, 2019 · 0 comments
Open

Allowing broadcast operations to HDF5Dataset #586

scottstanie opened this issue Oct 4, 2019 · 0 comments

Comments

@scottstanie
Copy link
Contributor

scottstanie commented Oct 4, 2019

A few times I've wanted to do something like this:

f = h5open("file.h5")
ds = f["array"]
newdata = ds .+ 5

But currently that errors:

julia> ds .+ 5
ERROR: MethodError: no method matching iterate(::HDF5Dataset)
Closest candidates are:
  iterate(::Core.SimpleVector) at essentials.jl:600
  iterate(::Core.SimpleVector, ::Any) at essentials.jl:600
  iterate(::ExponentialBackOff) at error.jl:218
  ...
Stacktrace:
 [1] copyto!(::Array{Int64,1}, ::HDF5Dataset) at ./abstractarray.jl:722
 [2] _collect(::UnitRange{Int64}, ::HDF5Dataset, ::Base.HasEltype, ::Base.HasLength) at ./array.jl:564
 [3] collect(::HDF5Dataset) at ./array.jl:558
 [4] broadcastable(::HDF5Dataset) at ./broadcast.jl:664
 [5] broadcasted(::Function, ::HDF5Dataset, ::Int64) at ./broadcast.jl:1234
 [6] top-level scope at REPL[7]:1

(note: the reason it says we need iterate is because of this line in "broadcast.jl":
https://github.com/JuliaLang/julia/blob/master/base/broadcast.jl#L662 that just passes along anything it is not sure of

I have this working for myself by adding:

import Base: broadcastable
broadcastable(x::HDF5Dataset) = read(x)

Is this desirable as a high level feature? or is it too opaque to users to have a dataset automatically get read in? If yes, I can create a pull request to add them here.

Similarly, if we want this I can add the other methods I've included for myself:

collect(x::HDF5Dataset) = collect(read(x))
iterate(x::HDF5Dataset) = iterate(read(x))
iterate(x::HDF5Dataset, state) = iterate(read(x), state)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant