Fortran-contiguous (column-major) order is simply C-contiguous (row-major) order in reverse. So there’s a simple work around for the fact that dask array doesn’t support
- Transpose your array to reverse its dimensions.
- Reshape it to the reverse of your desired shape.
- Transpose it back.
In a function:
def reshape_fortran(x, shape): return x.T.reshape(shape[::-1]).T
Transposing with NumPy/dask is basically free (it doesn’t copy any data), so in principle this operation should also be quite efficient.
Here’s a simple test to verify it does the right thing:
In : import numpy as np In : import dask.array as da In : x = np.arange(100).reshape(10, 10) In : y = da.from_array(x, chunks=5) In : shape = (2, 5, 10) In : np.array_equal(reshape_fortran(y, shape).compute(), ...: x.reshape(shape, order='F')) ...: Out: True
Answered By – shoyer
Answer Checked By – Robin (BugsFixing Admin)