Commit 5678af4
committed
Avoid eager C-order copies in NibabelReader (Fixes: #8107)
Nibabel exposes NIfTI voxel buffers in their native Fortran layout, but
MONAI was forcing np.asanyarray(img.dataobj, order="C") in
NibabelReader._get_array_data(). For compressed .nii.gz inputs that adds
a full dense memory reorder on top of the file read/decompression step,
which is the hot path reported in issue #8107.
Drop the forced C-order conversion and keep nibabel's native array layout
instead. Downstream MONAI conversion paths already handle contiguity when
they actually need it, so the reader does not need to pay that cost
eagerly at load time.
Add a regression test that loads a small NIfTI image through
NibabelReader and asserts the returned data is still correct while
preserving the native F-contiguous layout. This guards against
reintroducing the eager copy in the reader path.
Signed-off-by: Soumya Snigdha Kundu <[email protected]>1 parent 55c724f commit 5678af4
2 files changed
Lines changed: 22 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1217 | 1217 | | |
1218 | 1218 | | |
1219 | 1219 | | |
1220 | | - | |
| 1220 | + | |
1221 | 1221 | | |
1222 | 1222 | | |
1223 | 1223 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
14 | 16 | | |
15 | 17 | | |
| 18 | + | |
| 19 | + | |
16 | 20 | | |
17 | 21 | | |
18 | 22 | | |
| |||
76 | 80 | | |
77 | 81 | | |
78 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
79 | 100 | | |
80 | 101 | | |
81 | 102 | | |
0 commit comments