BlueBrain / HighFive

HighFive - Header-only C++ HDF5 interface
https://bluebrain.github.io/HighFive/
Boost Software License 1.0
687 stars 161 forks source link

Prevent H5Easy from serializing column-major `xt::` objects. #917

Closed 1uc closed 6 months ago

1uc commented 9 months ago

XTensor support various memory layouts. H5Easy implements XTensor support as follows:

template <typename T>
struct io_impl<T, typename std::enable_if<xt::is_xexpression<T>::value>::type> {
    ...
    inline static DataSet dump(File& file,
                               const std::string& path,
                               const T& data,
                               const DumpOptions& options) {

        DataSet dataset = initDataset<value_type>(file, path, shape(data), options);
        dataset.write_raw(data.data());
        ...

which is correct for row-major layouts without padding or striding. The following code however compiles and runs:

xt::xarray<double, xt::layout_type::row_major> a({{1, 2, 3}, {4, 5, 6}});
H5Easy::dump(file, "a", a);
tdegeus commented 8 months ago

(In your example, you meant to put column_major I guess?)

A quick fix is to add a static_assert

1uc commented 6 months ago

Fixed by #989.