Skip to content
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
90 changes: 57 additions & 33 deletions array_api_strict/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@

__all__ += ["__array_api_version__"]

from ._constants import e, inf, nan, pi, newaxis
from ._constants import e, inf, nan, newaxis, pi

__all__ += ["e", "inf", "nan", "pi", "newaxis"]
__all__ += ["e", "inf", "nan", "newaxis", "pi"]

from ._creation_functions import (
asarray,
arange,
asarray,
empty,
empty_like,
eye,
Expand All @@ -52,8 +52,8 @@
)

__all__ += [
"asarray",
"arange",
"asarray",
"empty",
"empty_like",
"eye",
Expand All @@ -77,8 +77,8 @@
broadcast_to,
can_cast,
finfo,
isdtype,
iinfo,
isdtype,
result_type,
)

Expand All @@ -89,12 +89,17 @@
"broadcast_to",
"can_cast",
"finfo",
"isdtype",
"iinfo",
"isdtype",
"result_type",
]

from ._dtypes import (
bool,
complex64,
complex128,
float32,
float64,
int8,
int16,
int32,
Expand All @@ -103,14 +108,14 @@
uint16,
uint32,
uint64,
float32,
float64,
complex64,
complex128,
bool,
)

__all__ += [
"bool",
"complex64",
"complex128",
"float32",
"float64",
"int8",
"int16",
"int32",
Expand All @@ -119,11 +124,6 @@
"uint16",
"uint32",
"uint64",
"float32",
"float64",
"complex64",
"complex128",
"bool",
]

from ._elementwise_functions import (
Expand All @@ -137,8 +137,8 @@
atan2,
atanh,
bitwise_and,
bitwise_left_shift,
bitwise_invert,
bitwise_left_shift,
bitwise_or,
bitwise_right_shift,
bitwise_xor,
Expand Down Expand Up @@ -188,8 +188,8 @@
signbit,
sin,
sinh,
square,
sqrt,
square,
subtract,
tan,
tanh,
Expand All @@ -207,8 +207,8 @@
"atan2",
"atanh",
"bitwise_and",
"bitwise_left_shift",
"bitwise_invert",
"bitwise_left_shift",
"bitwise_or",
"bitwise_right_shift",
"bitwise_xor",
Expand Down Expand Up @@ -258,8 +258,8 @@
"signbit",
"sin",
"sinh",
"square",
"sqrt",
"square",
"subtract",
"tan",
"tanh",
Expand All @@ -276,9 +276,9 @@
"__array_namespace_info__",
]

from ._linear_algebra_functions import matmul, tensordot, matrix_transpose, vecdot
from ._linear_algebra_functions import matmul, matrix_transpose, tensordot, vecdot

__all__ += ["matmul", "tensordot", "matrix_transpose", "vecdot"]
__all__ += ["matmul", "matrix_transpose", "tensordot", "vecdot"]

from ._manipulation_functions import (
concat,
Expand All @@ -297,44 +297,68 @@

__all__ += ["concat", "expand_dims", "flip", "moveaxis", "permute_dims", "repeat", "reshape", "roll", "squeeze", "stack", "tile", "unstack"]

from ._searching_functions import argmax, argmin, nonzero, count_nonzero, searchsorted, where
from ._searching_functions import (
argmax,
argmin,
count_nonzero,
nonzero,
searchsorted,
where,
)

__all__ += ["argmax", "argmin", "nonzero", "count_nonzero", "searchsorted", "where"]
__all__ += ["argmax", "argmin", "count_nonzero", "nonzero", "searchsorted", "where"]

from ._set_functions import unique_all, unique_counts, unique_inverse, unique_values, isin
from ._set_functions import (
isin,
unique_all,
unique_counts,
unique_inverse,
unique_values,
)

__all__ += ["unique_all", "unique_counts", "unique_inverse", "unique_values", "isin"]
__all__ += ["isin", "unique_all", "unique_counts", "unique_inverse", "unique_values"]

from ._sorting_functions import argsort, sort

__all__ += ["argsort", "sort"]

from ._statistical_functions import cumulative_sum, cumulative_prod, max, mean, min, prod, std, sum, var
from ._statistical_functions import (
cumulative_prod,
cumulative_sum,
max,
mean,
min,
prod,
std,
sum,
var,
)

__all__ += ["cumulative_sum", "cumulative_prod", "max", "mean", "min", "prod", "std", "sum", "var"]
__all__ += ["cumulative_prod", "cumulative_sum", "max", "mean", "min", "prod", "std", "sum", "var"]

from ._utility_functions import all, any, diff

__all__ += ["all", "any", "diff"]

from ._array_object import Device

__all__ += ["Device"]

# Helper functions that are not part of the standard

from ._flags import (
set_array_api_strict_flags,
ArrayAPIStrictFlags,
get_array_api_strict_flags,
reset_array_api_strict_flags,
ArrayAPIStrictFlags,
set_array_api_strict_flags,
)

__all__ += [
'set_array_api_strict_flags',
'get_array_api_strict_flags',
'reset_array_api_strict_flags',
'ArrayAPIStrictFlags',
'__version__',
'get_array_api_strict_flags',
'reset_array_api_strict_flags',
'set_array_api_strict_flags',
]

try:
Expand Down
8 changes: 4 additions & 4 deletions array_api_strict/_array_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@

import operator
import sys
from collections.abc import Iterator
from collections.abc import Callable, Iterator
from enum import IntEnum
from types import EllipsisType, ModuleType
from typing import Any, Literal, SupportsIndex, Callable
from typing import Any, Literal, SupportsIndex

import numpy as np
import numpy.typing as npt

from ._creation_functions import Undef, _undef, asarray
from ._devices import CPU_DEVICE, Device, device_supports_dtype
from ._dtypes import (
DType,
_all_dtypes,
Expand All @@ -40,7 +41,6 @@
_real_to_complex_map,
_result_type,
)
from ._devices import CPU_DEVICE, Device, device_supports_dtype
from ._flags import get_array_api_strict_flags, set_array_api_strict_flags
from ._typing import PyCapsule

Expand All @@ -64,7 +64,7 @@ class Array:
_array: npt.NDArray[Any]
_dtype: DType
_device: Device
__slots__ = ("_array", "_dtype", "_device", "__weakref__")
__slots__ = ("__weakref__", "_array", "_device", "_dtype")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh. I actually thought that __slots__ are ordered and the order translates directly to the order of elements of a corresponding C struct. Apparently not, and I actually don't know why I thought this. TIL.
(this is a note-to-self, not a request to change anything)


# Use a custom constructor instead of __init__, as manually initializing
# this class is not supported API.
Expand Down
8 changes: 5 additions & 3 deletions array_api_strict/_creation_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@

import numpy as np

from ._dtypes import DType, _all_dtypes, _np_dtype, bool as xp_bool
from ._devices import (
Device, device_supports_dtype, get_default_dtypes,
check_device as _check_device
Device,
check_device as _check_device,
device_supports_dtype,
get_default_dtypes,
)
from ._dtypes import DType, _all_dtypes, _np_dtype, bool as xp_bool
from ._flags import get_array_api_strict_flags
from ._typing import NestedSequence, SupportsBufferProtocol, SupportsDLPack

Expand Down
22 changes: 17 additions & 5 deletions array_api_strict/_devices.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
from typing import Final

from ._dtypes import (
DType, float32, float64, complex64, complex128, int64, uint64, int32,
_all_dtypes, _boolean_dtypes, _signed_integer_dtypes,
_unsigned_integer_dtypes, _integer_dtypes, _real_floating_dtypes,
_complex_floating_dtypes, _numeric_dtypes
DType,
_all_dtypes,
_boolean_dtypes,
_complex_floating_dtypes,
_integer_dtypes,
_numeric_dtypes,
_real_floating_dtypes,
_signed_integer_dtypes,
_unsigned_integer_dtypes,
complex64,
complex128,
float32,
float64,
int32,
int64,
uint64,
)

_ALL_DEVICE_NAMES = ("CPU_DEVICE", "device1", "device2", "no_float64", "no_x64")

class Device:
_device: Final[str]
__slots__ = ("_device", "__weakref__")
__slots__ = ("__weakref__", "_device")

def __init__(self, device: str = "CPU_DEVICE"):
if device not in _ALL_DEVICE_NAMES:
Expand Down
2 changes: 1 addition & 1 deletion array_api_strict/_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
class DType:
_np_dtype: Final[np.dtype[Any]]
_canonical_name: Final[Any]
__slots__ = ("_np_dtype", "_canonical_name", "__weakref__")
__slots__ = ("__weakref__", "_canonical_name", "_np_dtype")

def __init__(self, np_dtype: npt.DTypeLike):
self._canonical_name = np_dtype
Expand Down
20 changes: 10 additions & 10 deletions array_api_strict/_fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import numpy as np

from ._array_object import Array
from ._devices import ALL_DEVICES, Device, device_supports_dtype
from ._data_type_functions import astype
from ._devices import ALL_DEVICES, Device, device_supports_dtype
from ._dtypes import (
DType,
_complex_floating_dtypes,
Expand All @@ -14,8 +14,8 @@
complex64,
float32,
)
from ._info import __array_namespace_info__
from ._flags import requires_extension
from ._info import __array_namespace_info__


@requires_extension('fft')
Expand Down Expand Up @@ -338,17 +338,17 @@ def ifftshift(x: Array, /, *, axes: int | Sequence[int] | None = None) -> Array:

__all__ = [
"fft",
"ifft",
"fftfreq",
"fftn",
"fftshift",
"hfft",
"ifft",
"ifftn",
"rfft",
"ifftshift",
"ihfft",
"irfft",
"rfftn",
"irfftn",
"hfft",
"ihfft",
"fftfreq",
"rfft",
"rfftfreq",
"fftshift",
"ifftshift",
"rfftn",
]
4 changes: 2 additions & 2 deletions array_api_strict/_flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
import functools
import os
import warnings
from collections.abc import Callable
from collections.abc import Callable, Collection
from types import TracebackType
from typing import Any, Collection, ParamSpec, TypeVar, cast
from typing import Any, ParamSpec, TypeVar, cast

import array_api_strict

Expand Down
Loading
Loading