Skip to content

Commit

Permalink
Basic np.load implementation, falling back to NumPy
Browse files Browse the repository at this point in the history
Mostly there to ensure that the NumPy ndarray coming out of np.load
gets cast to a cuNumeric ndarray. As requested by ORNL.
  • Loading branch information
manopapad committed Feb 21, 2024
1 parent fbdfe89 commit 3c9cdcc
Showing 1 changed file with 51 additions and 1 deletion.
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

0 comments on commit 3c9cdcc

Please sign in to comment.