Vindaar / nimhdf5

Wrapper and some simple high-level bindings for the HDF5 library for the Nim language
MIT License
28 stars 2 forks source link

Returns nothing #59

Closed AmjadHD closed 1 year ago

AmjadHD commented 1 year ago

I tried to open this file using this library:

import pkg/nimhdf5

let h5f = H5open("testset.hdf5", "r")
for item in h5f.items():
  echo item
discard h5f.close()

but I get nothing. when using h5py:

import h5py

h5f = h5py.File("testset.hdf5", "r")
for item in h5f.items():
    print(item)
h5f.close()

I get:

('X_test', <HDF5 dataset "X_test": shape (200, 64, 64), type "|u1">)
('Y_test', <HDF5 dataset "Y_test": shape (200, 1), type "<f8">)

Notes:

Vindaar commented 1 year ago

You can't assume that nimhdf5 works exactly like h5py. Groups and datasets are represented using different types. So the default items iterator never yields datasets, it only yields groups!

If you really want the datasets from an iterator, you first need to get the root group and then call items on that.

import nimhdf5

let h5f = H5open("/t/testset.hdf5", "r")
let root = h5f["/".grp_str]
for dset in root:
  echo dset
discard h5f.close()

There are other important differences between h5py and nimhdf5 though, all essentially related to type safety. Better ping me on matrix/discord, as lately and in the near future I won't be looking at Github much.