Fix HDF5/xtensor mismatched free/delete error

This commit is contained in:
Sterling Harper 2018-10-05 21:07:44 -04:00
parent c9d676c6c9
commit 08a8d3288f

View file

@ -162,13 +162,14 @@ void read_attribute(hid_t obj_id, const char* name, xt::xarray<T>& arr)
std::size_t size = 1;
for (const auto x : shape)
size *= x;
T* buffer = new T[size];
std::vector<T> buffer;
buffer.resize(size);
// Read data from attribute
read_attr(obj_id, name, H5TypeMap<T>::type_id, buffer);
read_attr(obj_id, name, H5TypeMap<T>::type_id, buffer.data());
// Adapt array into xarray
arr = xt::adapt(buffer, size, xt::acquire_ownership(), shape);
arr = xt::adapt(buffer, shape);
}
// overload for std::string
@ -244,13 +245,14 @@ void read_dataset(hid_t dset, xt::xarray<T>& arr, bool indep=false)
std::size_t size = 1;
for (const auto x : shape)
size *= x;
T* buffer = new T[size];
std::vector<T> buffer;
buffer.resize(size);
// Read data from attribute
read_dataset(dset, nullptr, H5TypeMap<T>::type_id, buffer, indep);
read_dataset(dset, nullptr, H5TypeMap<T>::type_id, buffer.data(), indep);
// Adapt into xarray
arr = xt::adapt(buffer, size, xt::acquire_ownership(), shape);
arr = xt::adapt(buffer, shape);
}
template <typename T>
@ -273,13 +275,14 @@ void read_dataset_as_shape(hid_t obj_id, const char* name,
std::size_t size = 1;
for (const auto x : arr.shape())
size *= x;
T* buffer = new T[size];
std::vector<T> buffer;
buffer.resize(size);
// Read data from attribute
read_dataset(dset, nullptr, H5TypeMap<T>::type_id, buffer, indep);
read_dataset(dset, nullptr, H5TypeMap<T>::type_id, buffer.data(), indep);
// Adapt into xarray
arr = xt::adapt(buffer, size, xt::acquire_ownership(), arr.shape());
arr = xt::adapt(buffer, arr.shape());
close_dataset(dset);
}