Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: np.memmap should take a strides arguemnt in the construtor #18494

Open
alanhdu opened this issue Feb 25, 2021 · 0 comments
Open

ENH: np.memmap should take a strides arguemnt in the construtor #18494

alanhdu opened this issue Feb 25, 2021 · 0 comments

Comments

@alanhdu
Copy link

alanhdu commented Feb 25, 2021

I am trying to share a np.memmap array across two processes by sharing the underlying mmap-ed file. To fully replicate this across processes, I need to replicate the filename (to share the buffer) and the numpy metadata. Unfortunately, the np.memmap constructor does not take a strides argument, which means that I can't directly construct the appropriate array.

I can currently achieve my aim by doing:

memmap = np.memmap(filename, dtype=..., mode="r", offset=...)
memmap = np.lib.stride_tricks.as_strided(memmap, shape=..., strides=..., subok=True)

but I think it'd be nice for np.memmap to directly supported the strides argument.

Implementationally, I think we just need to update the num_bytes calculation to take into acount striding and to pass strides into the ndarray.__new__ call at

numpy/numpy/core/memmap.py

Lines 269 to 270 in a14c412

self = ndarray.__new__(subtype, shape, dtype=descr, buffer=mm,
offset=array_offset, order=order)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant