Skip to content

DOC: See also np.load and np.memmap in np.lib.format.open_memmap #7987

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

Merged
merged 1 commit into from
Oct 28, 2016

Conversation

f0k
Copy link
Contributor

@f0k f0k commented Aug 29, 2016

np.load supports memmap_mode to open existing .npy files as memory-mapped files.
np.memmap supports creating or loading raw binary files as memory-mapped files.
Neither support creating .npy files as memory-mapped files, which is handy when writing data that is too large to keep in memory at once while still retaining the advantages of the .npy format (shape/dtype information and easy loading). np.lib.format.open_memmap allows just this, but is difficult to find (even if you already know it exists!).

This adds a link to np.lib.format.open_memmap from np.load and np.memmap.

np.load supports memmap_mode to open existing .npy files as
memory-mapped files. np.memmap supports creating or loading raw
binary files as memory-mapped files. This adds a link to a
function for creating memory-mapped files in .npy format.
@charris
Copy link
Member

charris commented Sep 24, 2016

Why do you want to advertise this function? It is already available in np.load and isn't imported into the numpy namespace. It looks more like a function that should be private. The documentation of load could use a bit of clarification for the mmap_mode parameter, noting that None is the default and reads the file into memory, as opposed to memmapping it.

@mhvk
Copy link
Contributor

mhvk commented Sep 24, 2016

Hmm, I've just started using memmap files as I was trying to do things on my laptop when not having access to a bigger computer, and had turned to open_memmap to access .npy files, and I see that np.load just does it for me. Including, it seems, opening such files for writing, which it seems is what @f0k missed.

Given this, I agree open_memmap does not need to be advertised, but it would be helpful to put a note in memmap pointing to load as the way to map .npy files.

@mhvk
Copy link
Contributor

mhvk commented Sep 24, 2016

Actually, the writing is problematic: how would I create a new array on disk with given dtype and shape, i.e., how could I use np.load to do the equivalent of (from somewhere in my code):

    d = open_memmap(out_fn, mode='w+', dtype=np.float16,
                    shape=(size, len(thread_ids)))

@f0k
Copy link
Contributor Author

f0k commented Sep 26, 2016

Why do you want to advertise this function? It is already available in np.load

No, this functionality isn't. You cannot create a new mem-mapped .npy file from scratch using np.load. Or can you?

Actually, the writing is problematic: how would I create a new array on disk with given dtype and shape, i.e., how could I use np.load to do the equivalent of [...]

Exactly, that's what I need open_memmap for, and I often had to search some of my old code for it when I forgot the name again.
@charris: Is this possible with np.load? If so, I'll gladly change my PR to document how!

@charris charris changed the title Advertise np.lib.format.open_memmap from np.load and np.memmap DOC: See also np.load and np.memmap in np.lib.format.open_memmap Oct 23, 2016
@charris charris merged commit 6ae8420 into numpy:master Oct 28, 2016
@charris
Copy link
Member

charris commented Oct 28, 2016

Can't hurt. Thanks @f0k .

@f0k f0k deleted the advertise-open_memmap branch October 28, 2016 16:26
@f0k
Copy link
Contributor Author

f0k commented Oct 28, 2016

Thanks for merging!

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

Successfully merging this pull request may close these issues.

3 participants