Skip to content

Commit dfb01a6

Browse files
committed
add array_namespace
1 parent 519afb0 commit dfb01a6

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

heat/array_api/_array_object.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ def __and__(self: Array, other: Union[int, bool, Array], /) -> Array:
319319
res = self._array.__and__(other._array)
320320
return self.__class__._new(res)
321321

322+
# TODO: Ready to Remove
322323
def __array_namespace__(self: Array, /, *, api_version: Optional[str] = None) -> Any:
323324
"""
324325
Returns an object that has all the array API functions on it.

heat/core/dndarray.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from inspect import stack
1111
from mpi4py import MPI
1212
from pathlib import Path
13-
from typing import Union, TypeVar
13+
from typing import Any, Union, TypeVar
1414

1515
warnings.simplefilter("always", ResourceWarning)
1616

@@ -509,6 +509,24 @@ def __array_function__(self, func, types, args, kwargs):
509509
return NotImplemented
510510
return ht_func(*args, **kwargs)
511511

512+
def __array_namespace__(self, *, api_version: str | None = None) -> Any:
513+
"""
514+
Returns an object that has all the array API functions on it.
515+
516+
Parameters
517+
----------
518+
api_version : Optional[str]
519+
string representing the version of the array API specification to
520+
be returned, in ``'YYYY.MM'`` form. If it is ``None`` (default), it
521+
returns the namespace corresponding to latest version of the
522+
array API specification.
523+
"""
524+
if api_version is not None and api_version != "2025.12":
525+
raise ValueError(f"Unrecognized array API version: {api_version}")
526+
import heat
527+
528+
return heat
529+
512530
def astype(self, dtype, copy=True) -> DNDarray:
513531
"""
514532
Returns a casted version of this array.

0 commit comments

Comments
 (0)