Skip to content

Commit c248b53

Browse files
committed
ENH: Make layout order an initialization parameter of ArrayProxy
1 parent b38a99b commit c248b53

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

nibabel/arrayproxy.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
KEEP_FILE_OPEN_DEFAULT = False
5454

5555

56-
class ArrayProxy(object):
56+
class ArrayProxy:
5757
""" Class to act as proxy for the array that can be read from a file
5858
5959
The array proxy allows us to freeze the passed fileobj and header such that
@@ -83,10 +83,9 @@ class ArrayProxy(object):
8383
See :mod:`nibabel.minc1`, :mod:`nibabel.ecat` and :mod:`nibabel.parrec` for
8484
examples.
8585
"""
86-
# Assume Fortran array memory layout
8786
order = 'F'
8887

89-
def __init__(self, file_like, spec, *, mmap=True, keep_file_open=None):
88+
def __init__(self, file_like, spec, *, mmap=True, order=None, keep_file_open=None):
9089
"""Initialize array proxy instance
9190
9291
Parameters
@@ -116,6 +115,10 @@ def __init__(self, file_like, spec, *, mmap=True, keep_file_open=None):
116115
True gives the same behavior as ``mmap='c'``. If `file_like`
117116
cannot be memory-mapped, ignore `mmap` value and read array from
118117
file.
118+
order : {'F', 'C'}, optional, keyword only
119+
`order` controls the order of the data array layout. Fortran-style,
120+
column-major order may be indicated with 'F', and C-style, row-major
121+
order may be indicated with 'C'. The default order is 'F'.
119122
keep_file_open : { None, True, False }, optional, keyword only
120123
`keep_file_open` controls whether a new file handle is created
121124
every time the image is accessed, or a single file handle is
@@ -128,6 +131,8 @@ def __init__(self, file_like, spec, *, mmap=True, keep_file_open=None):
128131
"""
129132
if mmap not in (True, False, 'c', 'r'):
130133
raise ValueError("mmap should be one of {True, False, 'c', 'r'}")
134+
if order not in (None, 'C', 'F'):
135+
raise ValueError("order should be one of {'C', 'F'}")
131136
self.file_like = file_like
132137
if hasattr(spec, 'get_data_shape'):
133138
slope, inter = spec.get_slope_inter()
@@ -147,6 +152,8 @@ def __init__(self, file_like, spec, *, mmap=True, keep_file_open=None):
147152
# Permit any specifier that can be interpreted as a numpy dtype
148153
self._dtype = np.dtype(self._dtype)
149154
self._mmap = mmap
155+
if order is not None:
156+
self.order = order
150157
# Flags to keep track of whether a single ImageOpener is created, and
151158
# whether a single underlying file handle is created.
152159
self._keep_file_open, self._persist_opener = \

0 commit comments

Comments
 (0)