-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
48 changes: 48 additions & 0 deletions
48
jhdf/src/test/resources/scripts/implicit_index_datasets.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import h5py | ||
import numpy | ||
|
||
|
||
f = h5py.File("implicit_index_datasets.hdf5", "w", libver='latest') | ||
|
||
data = numpy.arange(20) | ||
|
||
dataspace = h5py.h5s.create_simple(data.shape) # Create simple dataspace | ||
datatype = h5py.h5t.NATIVE_INT32 | ||
|
||
# Dataset creation property list | ||
dcpl = h5py.h5p.create(h5py.h5p.DATASET_CREATE) | ||
dcpl.set_alloc_time(h5py.h5d.ALLOC_TIME_EARLY) | ||
# Set chunk dimensions (e.g., chunks of size 5) | ||
chunk_dims = (5,) # Ensure chunks are compatible with dataspace shape | ||
dcpl.set_chunk(chunk_dims) | ||
|
||
# Create the dataset | ||
dataset_name = "implicit_index_exact".encode('utf-8') # Dataset name must be bytes | ||
dataset = h5py.h5d.create(f.id, dataset_name, datatype, dataspace, dcpl) | ||
|
||
# Write data to the dataset | ||
dataset.write(h5py.h5s.ALL, h5py.h5s.ALL, data) | ||
dataset.close() | ||
|
||
# Second dataset with chunk size mismatch | ||
data = numpy.arange(50).reshape(10,5) | ||
|
||
dataspace = h5py.h5s.create_simple(data.shape) # Create simple dataspace | ||
datatype = h5py.h5t.NATIVE_INT32 | ||
|
||
# Dataset creation property list | ||
dcpl = h5py.h5p.create(h5py.h5p.DATASET_CREATE) | ||
dcpl.set_alloc_time(h5py.h5d.ALLOC_TIME_EARLY) | ||
# Set chunk dimensions | ||
chunk_dims = (3,2) # mismatched to data shape | ||
dcpl.set_chunk(chunk_dims) | ||
|
||
# Create the dataset | ||
dataset_name = "implicit_index_mismatch".encode('utf-8') # Dataset name must be bytes | ||
dataset = h5py.h5d.create(f.id, dataset_name, datatype, dataspace, dcpl) | ||
|
||
# Write data to the dataset | ||
dataset.write(h5py.h5s.ALL, h5py.h5s.ALL, data) | ||
dataset.close() | ||
|
||
f.close() |