|
| 1 | +import dataclasses |
| 2 | +import re |
| 3 | +from _typeshed import Incomplete |
| 4 | +from collections.abc import Generator, Sequence |
| 5 | +from contextlib import contextmanager |
| 6 | +from types import ModuleType |
| 7 | +from typing import Any, Final, Literal, TypeAlias |
| 8 | + |
| 9 | +from array_api_compat import ( |
| 10 | + device as xp_device, # pyright: ignore[reportUnknownVariableType] |
| 11 | + is_array_api_strict_namespace as is_array_api_strict, |
| 12 | + is_cupy_namespace as is_cupy, |
| 13 | + is_jax_namespace as is_jax, |
| 14 | + is_lazy_array as is_lazy_array, |
| 15 | + is_numpy_namespace as is_numpy, |
| 16 | + is_torch_namespace as is_torch, |
| 17 | + size as xp_size, |
| 18 | +) |
| 19 | + |
| 20 | +__all__ = [ |
| 21 | + "SCIPY_ARRAY_API", |
| 22 | + "SCIPY_DEVICE", |
| 23 | + "_asarray", |
| 24 | + "array_namespace", |
| 25 | + "assert_almost_equal", |
| 26 | + "assert_array_almost_equal", |
| 27 | + "default_xp", |
| 28 | + "eager_warns", |
| 29 | + "is_array_api_strict", |
| 30 | + "is_complex", |
| 31 | + "is_cupy", |
| 32 | + "is_jax", |
| 33 | + "is_lazy_array", |
| 34 | + "is_marray", |
| 35 | + "is_numpy", |
| 36 | + "is_torch", |
| 37 | + "scipy_namespace_for", |
| 38 | + "xp_assert_close", |
| 39 | + "xp_assert_equal", |
| 40 | + "xp_assert_less", |
| 41 | + "xp_capabilities", |
| 42 | + "xp_copy", |
| 43 | + "xp_device", |
| 44 | + "xp_promote", |
| 45 | + "xp_ravel", |
| 46 | + "xp_result_type", |
| 47 | + "xp_size", |
| 48 | + "xp_unsupported_param_msg", |
| 49 | + "xp_vector_norm", |
| 50 | +] |
| 51 | + |
| 52 | +SCIPY_ARRAY_API: Final[str | Literal[False]] = ... |
| 53 | +SCIPY_DEVICE: Final[str] = ... |
| 54 | + |
| 55 | +Array: TypeAlias = Incomplete |
| 56 | + |
| 57 | +def array_namespace(*arrays: Array) -> ModuleType: ... |
| 58 | +def _asarray( |
| 59 | + array: Any, |
| 60 | + dtype: Any = None, |
| 61 | + order: Literal["K", "A", "C", "F"] | None = None, |
| 62 | + copy: bool | None = None, |
| 63 | + *, |
| 64 | + xp: ModuleType | None = None, |
| 65 | + check_finite: bool = False, |
| 66 | + subok: bool = False, |
| 67 | +) -> Array: ... |
| 68 | +def xp_copy(x: Array, *, xp: ModuleType | None = None) -> Array: ... |
| 69 | +@contextmanager |
| 70 | +def default_xp(xp: ModuleType) -> Generator[None]: ... |
| 71 | +def eager_warns( |
| 72 | + x: Array, warning_type: type[Warning] | tuple[type[Warning], ...], match: str | re.Pattern[str] | None = None |
| 73 | +) -> Incomplete: ... # _pytest.recwarn.WarningsChecker |
| 74 | +def xp_assert_equal( |
| 75 | + actual: Incomplete, |
| 76 | + desired: Incomplete, |
| 77 | + *, |
| 78 | + check_namespace: bool = True, |
| 79 | + check_dtype: bool = True, |
| 80 | + check_shape: bool = True, |
| 81 | + check_0d: bool = True, |
| 82 | + err_msg: str = "", |
| 83 | + xp: ModuleType | None = None, |
| 84 | +) -> None: ... |
| 85 | +def xp_assert_close( |
| 86 | + actual: Incomplete, |
| 87 | + desired: Incomplete, |
| 88 | + *, |
| 89 | + rtol: Incomplete | None = None, |
| 90 | + atol: int = 0, |
| 91 | + check_namespace: bool = True, |
| 92 | + check_dtype: bool = True, |
| 93 | + check_shape: bool = True, |
| 94 | + check_0d: bool = True, |
| 95 | + err_msg: str = "", |
| 96 | + xp: ModuleType | None = None, |
| 97 | +) -> None: ... |
| 98 | +def xp_assert_less( |
| 99 | + actual: Incomplete, |
| 100 | + desired: Incomplete, |
| 101 | + *, |
| 102 | + check_namespace: bool = True, |
| 103 | + check_dtype: bool = True, |
| 104 | + check_shape: bool = True, |
| 105 | + check_0d: bool = True, |
| 106 | + err_msg: str = "", |
| 107 | + verbose: bool = True, |
| 108 | + xp: ModuleType | None = None, |
| 109 | +) -> None: ... |
| 110 | +def assert_array_almost_equal( |
| 111 | + actual: Incomplete, desired: Incomplete, decimal: int = 6, *args: Incomplete, **kwds: Incomplete |
| 112 | +) -> None: ... |
| 113 | +def assert_almost_equal( |
| 114 | + actual: Incomplete, desired: Incomplete, decimal: int = 7, *args: Incomplete, **kwds: Incomplete |
| 115 | +) -> None: ... |
| 116 | +def xp_unsupported_param_msg(param: Incomplete) -> str: ... |
| 117 | +def is_complex(x: Array, xp: ModuleType) -> bool: ... |
| 118 | +def scipy_namespace_for(xp: ModuleType) -> ModuleType | None: ... |
| 119 | +def xp_vector_norm( |
| 120 | + x: Array, |
| 121 | + /, |
| 122 | + *, |
| 123 | + axis: int | tuple[int, ...] | None = None, |
| 124 | + keepdims: bool = False, |
| 125 | + ord: float = 2, |
| 126 | + xp: ModuleType | None = None, |
| 127 | +) -> Array: ... |
| 128 | +def xp_ravel(x: Array, /, *, xp: ModuleType | None = None) -> Array: ... |
| 129 | +def xp_result_type(*args: Incomplete, force_floating: bool = False, xp: ModuleType) -> type: ... |
| 130 | +def xp_promote(*args: Incomplete, broadcast: bool = False, force_floating: bool = False, xp: ModuleType | None) -> Array: ... |
| 131 | +def is_marray(xp: ModuleType) -> bool: ... |
| 132 | + |
| 133 | +@dataclasses.dataclass(repr=False) |
| 134 | +class _XPSphinxCapability: |
| 135 | + cpu: bool | None |
| 136 | + gpu: bool | None |
| 137 | + warnings: list[str] = ... |
| 138 | + |
| 139 | + def _render(self, /, value: object) -> str: ... |
| 140 | + |
| 141 | +def xp_capabilities( |
| 142 | + *, |
| 143 | + capabilities_table: Incomplete | None = None, |
| 144 | + skip_backends: Sequence[tuple[str, str]] = (), |
| 145 | + xfail_backends: Sequence[tuple[str, str]] = (), |
| 146 | + cpu_only: bool = False, |
| 147 | + np_only: bool = False, |
| 148 | + reason: str | None = None, |
| 149 | + exceptions: Sequence[str] = (), |
| 150 | + warnings: Sequence[tuple[str, str]] = (), |
| 151 | + allow_dask_compute: bool = False, |
| 152 | + jax_jit: bool = True, |
| 153 | +) -> dict[str, _XPSphinxCapability]: ... |
0 commit comments