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

Bug in lazy_transpose #30

Open
HenryDayHall opened this issue Mar 27, 2024 · 0 comments
Open

Bug in lazy_transpose #30

HenryDayHall opened this issue Mar 27, 2024 · 0 comments

Comments

@HenryDayHall
Copy link

Python version 3.11.7, lazy_ops version 0.2.0.

When a dataset has been transposed, the left hand side of an assignment doesn't recognise the transpose. For example;

import h5py
import numpy as np
import lazy_ops

sample_data = np.random.rand(100, 10, 5)
with h5py.File("sample.h5", "w") as f:
    f.create_dataset("data", data=sample_data)
read_data = h5py.File("sample.h5", "r")["data"]
sample_view = lazy_ops.DatasetView(read_data)
sample_transposed = sample_view.lazy_transpose([0, 2, 1])
sample_transposed[:, :, -1] = sample_transposed[:, :, -1] * 2

Gives

#     sample_transposed[:, :, -1] = sample_transposed[:, :, -1] * 2
#     ~~~~~~~~~~~~~~~~~^^^^^^^^^^
#   File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
#   File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
#   File "/home/henry/Programs/miniconda3/envs/caloclouds/lib/python3.11/site-packages/h5py/_hl/dataset.py", line 997, in __setitem__
#     mspace = h5s.create_simple(selection.expand_shape(mshape))
#                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#   File "/home/henry/Programs/miniconda3/envs/caloclouds/lib/python3.11/site-packages/h5py/_hl/selections.py", line 264, in expand_shape
#     raise TypeError("Can't broadcast %s -> %s" % (source_shape, self.array_shape))  # array shape
#     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# TypeError: Can't broadcast (100, 5) -> (100, 10)

It's not a very useful operation, as it presumably breaks the lazy loading. None the less, it probably is a bug, or at least wants a different error message.

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

1 participant