mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-28 14:15:42 -04:00
Fix HDF5/xtensor mismatched free/delete error
This commit is contained in:
parent
c9d676c6c9
commit
08a8d3288f
1 changed files with 12 additions and 9 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue