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

Added Resize functionality for the chuncked datasets #58

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
service:
prepare:
- apt-get update && apt-get install -y libhdf5-serial-dev
17 changes: 17 additions & 0 deletions h5d_dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,20 @@ func (s *Dataset) Datatype() (*Datatype, error) {
func (s *Dataset) hasIllegalGoPointer() bool {
return s.typ.hasIllegalGoPointer()
}

// Resize a dataset
func (s *Dataset) Resize(dims []uint) error {
var c_dims *C.hsize_t
if dims == nil {
return fmt.Errorf("dims are nil")
}
rank := s.Space().SimpleExtentNDims()
if rank != len(dims) {
return fmt.Errorf("Resize can't change the rank of the dataset space")
}
c_dims = (*C.hsize_t)(unsafe.Pointer(&dims[0]))

rc := C.H5Dset_extent(s.id, c_dims)
err := h5err(rc)
return err
}
57 changes: 57 additions & 0 deletions h5d_dataset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,60 @@ func TestSelectHyperslab(t *testing.T) {
t.Fatal(err)
}
}

func TestDatasetResize(t *testing.T) {
f, err := CreateFile(fname, F_ACC_TRUNC)
if err != nil {
t.Fatalf("CreateFile failed: %s", err)
}
defer os.Remove(fname)
defer f.Close()

dtype, err := NewDataTypeFromType(reflect.TypeOf(1))
if err != nil {
t.Fatal(err)
}
initdims := []uint{4, 4}
maxdims := []uint{12, 4}
chunkDims := []uint{2, 4}
resizedDims := []uint{8, 4}
space, err := CreateSimpleDataspace(initdims, maxdims)
if err != nil {
t.Fatal(err)
}
defer space.Close()

dcpl, err := NewPropList(P_DATASET_CREATE)
if err != nil {
t.Fatal(err)
}
defer dcpl.Close()
err = dcpl.SetChunk(chunkDims)
if err != nil {
t.Fatal(err)
}
dset, err := f.CreateDatasetWith("dsetchunked", dtype, space, dcpl)
if err != nil {
t.Fatal(err)
}
defer dset.Close()

dimsGot, maxdimsGot, err := dset.Space().SimpleExtentDims()
if !reflect.DeepEqual(dimsGot, initdims) || !reflect.DeepEqual(maxdimsGot, maxdims) {
t.Fatal("Dimension not correct when creating chunked dataset")
}
if err != nil {
t.Fatal(err)
}
err = dset.Resize(resizedDims)
if err != nil {
t.Fatal(err)
}
dimsGot, maxdimsGot, err = dset.Space().SimpleExtentDims()
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(dimsGot, resizedDims) || !reflect.DeepEqual(maxdimsGot, maxdims) {
t.Fatal("Resized dimension not as expected")
}
}