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

Basic np.load implementation, falling back to NumPy #1126

Merged
merged 4 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion cunumeric/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
from .utils import AxesPairLike, inner_modes, matmul_modes, tensordot_modes

if TYPE_CHECKING:
from typing import Callable
from os import PathLike
from typing import BinaryIO, Callable

import numpy.typing as npt

Expand Down Expand Up @@ -616,6 +617,55 @@ def copy(a: ndarray) -> ndarray:
return result


def load(
file: str | bytes | PathLike[Any] | BinaryIO,
*,
max_header_size: int = 10000,
) -> ndarray:
"""
Load an array from a ``.npy`` file.

Parameters
----------
file : file-like object, string, or pathlib.Path
The file to read. File-like objects must support the
``seek()`` and ``read()`` methods and must always
be opened in binary mode.
max_header_size : int, optional
Maximum allowed size of the header. Large headers may not be safe
to load securely and thus require explicitly passing a larger value.
See :py:func:`ast.literal_eval()` for details.

Returns
-------
result : array
Data stored in the file.

Raises
------
OSError
If the input file does not exist or cannot be read.

See Also
--------
numpy.load

Notes
-----
cuNumeric does not currently support ``.npz`` and pickled files.

Availability
--------
Single CPU
"""
return array(
np.load(
file,
max_header_size=max_header_size, # type: ignore [call-arg]
)
)


# Numerical ranges


Expand Down
11 changes: 11 additions & 0 deletions docs/cunumeric/source/api/io.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Input and output
================

.. currentmodule:: cunumeric

NumPy binary files (npy, npz)
-----------------------------
.. autosummary::
:toctree: generated/

load
1 change: 1 addition & 0 deletions docs/cunumeric/source/api/routines.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Routines
manipulation
binary
indexing
io
linalg
logic
math
Expand Down
Loading