tee-ar-ex / trx-python

Python implementation of the TRX file format
https://tee-ar-ex.github.io/trx-python/
BSD 2-Clause "Simplified" License
22 stars 15 forks source link

Some tests fail on s390x (big endian) consistently #83

Open penguinpee opened 2 months ago

penguinpee commented 2 months ago

Whenever trx-python is build on a s390x builder (big endian), below tests fail. Tests are run without dipy being installed, which also appears to have some endianness related issues, but it's not used here.

With dipy installed I see additional tests failing. But I suppose, without having analyzed, those would be related to dipy's endianness issues and need to be fixed there.

I saw the discussion in #4 and would like to add that Fedora aims to support s390x whenever possible.

Test failures on s390x ```python =================================== FAILURES =================================== _______________________________ test_seq_ops_trx _______________________________ def test_seq_ops_trx(): with TemporaryDirectory() as tmp_dir: gs_dir = os.path.join(get_home(), 'gold_standard') path = os.path.join(gs_dir, 'gs.trx') trx_1 = tmm.load(path) > tmm.save(trx_1, os.path.join(tmp_dir, 'tmp.trx')) trx/tests/test_io.py:53: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ../BUILDROOT/usr/lib/python3.13/site-packages/trx/trx_file_memmap.py:547: in save copy_trx.resize() ../BUILDROOT/usr/lib/python3.13/site-packages/trx/trx_file_memmap.py:1229: in resize trx._copy_fixed_arrays_from(self) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = trx = , strs_start = 0 pts_start = 0, nb_strs_to_copy = None def _copy_fixed_arrays_from( self, trx: Type["TrxFile"], strs_start: int = 0, pts_start: int = 0, nb_strs_to_copy: Optional[int] = None, ) -> Tuple[int, int]: """Fill a TrxFile using another and start indexes (preallocation) Keyword arguments: trx -- TrxFile to copy data from strs_start -- The start index of the streamline pts_start -- The start index of the point nb_strs_to_copy -- The number of streamlines to copy. If not set will copy all Returns A tuple representing the end of the copied streamlines and end of copied points """ if nb_strs_to_copy is None: curr_strs_len, curr_pts_len = trx._get_real_len() else: curr_strs_len = int(nb_strs_to_copy) curr_pts_len = np.sum(trx.streamlines._lengths[0:curr_strs_len]) curr_pts_len = int(curr_pts_len) strs_end = strs_start + curr_strs_len pts_end = pts_start + curr_pts_len if curr_pts_len == 0: return strs_start, pts_start # Mandatory arrays > self.streamlines._data[pts_start:pts_end] = \ trx.streamlines._data[0:curr_pts_len] E ValueError: could not broadcast input array from shape (104,3) into shape (4294967400,3) ../BUILDROOT/usr/lib/python3.13/site-packages/trx/trx_file_memmap.py:872: ValueError _________________________ test_concatenate[small.trx] __________________________ path = '/builddir/build/BUILD/python-trx-python-0.3-build/trx-python-0.3/tests/memmap_test_data/small.trx' @pytest.mark.parametrize("path", [("small.trx")]) def test_concatenate(path): path = os.path.join(get_home(), 'memmap_test_data', path) trx1 = tmm.load(path) trx2 = tmm.load(path) concat = tmm.concatenate([trx1, trx2]) > assert len(concat) == 2 * len(trx2) E assert 0 == (2 * 1000) E + where 0 = len() E + and 1000 = len() trx/tests/test_memmap.py:191: AssertionError ____________________________ test_resize[small.trx] ____________________________ path = '/builddir/build/BUILD/python-trx-python-0.3-build/trx-python-0.3/tests/memmap_test_data/small.trx' @pytest.mark.parametrize("path", [("small.trx")]) def test_resize(path): path = os.path.join(get_home(), 'memmap_test_data', path) trx1 = tmm.load(path) concat = tmm.TrxFile(nb_vertices=1000000, nb_streamlines=10000, init_as=trx1) tmm.concatenate([concat, trx1], preallocation=True, delete_groups=True) concat.resize() > assert len(concat) == len(trx1) E assert 0 == 1000 E + where 0 = len() E + and 1000 = len() trx/tests/test_memmap.py:207: AssertionError _________________________ test_append[small.trx-10000] _________________________ path = '/builddir/build/BUILD/python-trx-python-0.3-build/trx-python-0.3/tests/memmap_test_data/small.trx' buffer = 10000 @pytest.mark.parametrize( "path, buffer", [ ("small.trx", 10000), ("small.trx", 0) ] ) def test_append(path, buffer): path = os.path.join(get_home(), 'memmap_test_data', path) trx1 = tmm.load(path) concat = tmm.TrxFile(nb_vertices=1, nb_streamlines=1, init_as=trx1) concat.append(trx1, extra_buffer=buffer) if buffer > 0: concat.resize() > assert len(concat) == len(trx1) E assert 0 == 1000 E + where 0 = len() E + and 1000 = len() trx/tests/test_memmap.py:229: AssertionError ___________________ test_append_Tractogram[small.trx-10000] ____________________ path = '/builddir/build/BUILD/python-trx-python-0.3-build/trx-python-0.3/tests/memmap_test_data/small.trx' buffer = 10000 @pytest.mark.parametrize("path, buffer", [("small.trx", 10000)]) def test_append_Tractogram(path, buffer): path = os.path.join(get_home(), 'memmap_test_data', path) trx = tmm.load(path) obj = trx.to_tractogram() concat = tmm.TrxFile(nb_vertices=1, nb_streamlines=1, init_as=trx) > concat.append(obj, extra_buffer=buffer) trx/tests/test_memmap.py:258: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ../BUILDROOT/usr/lib/python3.13/site-packages/trx/trx_file_memmap.py:1322: in append obj = self.from_tractogram(obj, reference=self.header, ../BUILDROOT/usr/lib/python3.13/site-packages/trx/trx_file_memmap.py:1649: in from_tractogram save(trx, tmp_dir.name) ../BUILDROOT/usr/lib/python3.13/site-packages/trx/trx_file_memmap.py:546: in save copy_trx = trx.deepcopy() ../BUILDROOT/usr/lib/python3.13/site-packages/trx/trx_file_memmap.py:762: in deepcopy to_dump = _append_last_offsets(self.streamlines._offsets, _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ nib_offsets = memmap([ 0, 2233785415175766016, 7710162562058289152, 10592466323575406592, 12754194144713... 13223412930889908224, 15457198346065674240, 541557855191302144, 2054767329987788800], dtype=uint64) nb_vertices = 33886 def _append_last_offsets(nib_offsets: np.ndarray, nb_vertices: int) -> np.ndarray: """Appends the last element of offsets from header information Keyword arguments: nib_offsets -- np.ndarray Array of offsets with the last element being the start of the last streamline (nibabel convention) nb_vertices -- int Total number of vertices in the streamlines Returns: Offsets -- np.ndarray (VTK convention) """ def is_sorted(a): return np.all(a[:-1] <= a[1:]) if not is_sorted(nib_offsets): > raise ValueError('Offsets must be sorted values.') E ValueError: Offsets must be sorted values. ../BUILDROOT/usr/lib/python3.13/site-packages/trx/trx_file_memmap.py:47: ValueError ```