Repository navigation
Conversation
The image dtype table mapped DATATYPE_INT to np.dtype('int'), which is
the platform C long: int64 on Linux and macOS under NumPy 2. ISMRMRD
defines DATATYPE_INT as int32_t, and the HDF5 writer already stored it
as '<i4'. As a result Image.from_array() refused int32 arrays, accepted
int64 arrays as DATATYPE_INT and then failed in Dataset.append_image()
with a broadcast error (the int64 buffer viewed as '<i4' has twice as
many elements), and every DATATYPE_INT image, including files written
by the C++ library, was read back as int64.
Map DATATYPE_INT to int32. The new tests check, for each of the eight
MRD image data types, that from_array() sets the right data_type, that
a header's data_type gives the right dtype, and that an image survives
an HDF5 write and read with the same dtype and values. The int32 cases
fail before this change and the full suite passes after it.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
ISMRMRD defines eight image data types (uint16, int16, uint32, int32, float32, float64, complex64, complex128) and no 64-bit or 8-bit integer type. Image.from_array() rejected other dtypes with a message that named only the offending dtype, and Image(data=...) looked the dtype up directly in the inverse table and raised a bare KeyError. Route both through get_data_type_from_dtype() and list the supported dtypes in its message. The new test checks that int64, uint64, int8 and float16 arrays raise a TypeError naming the supported types from both constructors. It fails before this change (the message did not name the supported types, and Image(data=...) raised KeyError) and the full suite passes after it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ismrmrd/image.pymappedDATATYPE_INTtonp.dtype('int'), which is the platform long: int64 on Linux and macOS.The MRD specification and the C library define
ISMRMRD_INT(4) asint32_t, andhdf5.pyalready stores INTimage data as
'<i4'. This had three effects:TypeError: Datatype not supported: int32;'<i4'with twice the elements, which failed with a broadcasterror;
This PR maps
DATATYPE_INTto int32. It also makes bothImageconstructors go throughget_data_type_from_dtype(), so an unsupported dtype (int64, uint64, int8, float16) raises aTypeErrorthat liststhe supported types instead of a
KeyErroror a broadcast error. MRD has no 64-bit integer type.Tests: a round trip through
from_array, the headerdata_type, and HDF5 write and read for all eight MRD image types,plus a test of the error for unsupported dtypes. On master, 7 of the new tests fail; with this PR the suite passes
(125 passed). CHANGELOG entries are under "Unreleased".