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

Shape oppositely interpreted? #43

Open
olafx opened this issue Nov 24, 2021 · 1 comment
Open

Shape oppositely interpreted? #43

olafx opened this issue Nov 24, 2021 · 1 comment
Assignees

Comments

@olafx
Copy link

olafx commented Nov 24, 2021

I'm creating a 2 by 4 by 3 tensor in Python, verifying in C++ that it's indeed a 2 by 4 by 3 row major tensor where 3 is the fastest dimension. When I open this tensor in HDFView, I see 3 slides of 2 by 4 matrices, which implies the 3 dimension is the slowest.
I used to think that it was just the visualization that was odd, but now I think it's a bug.
Here are some programs I used to generate the data, maybe useful for testing purposes.

import h5py
import numpy as np

fp = h5py.File('0.h5', 'w')
data = np.array([[[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4]], [[5, 5, 5], [6, 6, 6], [7, 7, 7], [8, 8, 8]]], dtype=np.float64)
print(data)
print(data.shape) # 2, 4, 3
fp.create_dataset('0', data=data.flatten(), shape=(2, 4, 3))
# fp.create_dataset('0', data=data) # same thing
fp.close()
#include <H5Cpp.h>
#include <iostream>
#include <cstddef>

using namespace H5;

int main()
{
    H5File fp {"../0.h5", H5F_ACC_RDWR};
    DataSet dataset {fp.openDataSet("0")};
    DataSpace dataspace {dataset.getSpace()};
    auto *raw_data = new double[24];
    dataset.read(raw_data, PredType::NATIVE_DOUBLE);
    hsize_t shape[3];
    dataspace.getSimpleExtentDims(shape);
    //  Let's access the z component of the 2nd particle at the 2nd time. Should be 6 if row major.
    std::size_t index = 4*3*(2-1) /* 2nd time */ + 3*(2-1) /* 2nd particle */ + (3-1) /* z component*/;
    std::cout << shape[0]    << ' ' << shape[1] << ' ' << shape[2] << '\n'; // 2 4 3
    std::cout << raw_data[index] << '\n'; // 6
    delete[] raw_data;
}
@byrnHDF
Copy link
Collaborator

byrnHDF commented Jan 16, 2022

HDFView does not try to interpret the data, unless the data indicates an Image convention, and will choose to assign the frame to the index value assigned to the 3rd (selectedIndex[2]) index. The selected indices defaults are assigned by the type of object and the assignment is:
// select dim1 and dim2 as 2D data for display, and slice through dim0
selectedIndex[0] = 1;
selectedIndex[1] = 2;
selectedIndex[1] = 0;

This can be changed by opening the table with the "Show Data with Options" button.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants