HighFive icon indicating copy to clipboard operation
HighFive copied to clipboard

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

Open 1uc opened this issue 1 year ago • 1 comments

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);

1uc avatar Jan 17 '24 07:01 1uc

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

A quick fix is to add a static_assert

tdegeus avatar Feb 14 '24 16:02 tdegeus

Fixed by #989.

1uc avatar May 06 '24 20:05 1uc