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
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ repos:
exclude: ".ipynb"

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.11.5
rev: v0.11.10
hooks:
- id: ruff
- id: ruff-check
args: ["--fix"]
types_or: [ python, pyi, jupyter ]
- id: ruff-format
Expand Down
1 change: 0 additions & 1 deletion ci/Numba-array-api-skips.txt
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
array_api_tests/test_operators_and_elementwise_functions.py::test_floor
58 changes: 0 additions & 58 deletions ci/Numba-array-api-xfails.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ array_api_tests/test_creation_functions.py::test_arange
array_api_tests/test_creation_functions.py::test_linspace
array_api_tests/test_creation_functions.py::test_meshgrid
array_api_tests/test_data_type_functions.py::test_finfo[float32]
array_api_tests/test_data_type_functions.py::test_isdtype
array_api_tests/test_has_names.py::test_has_names[linalg-cholesky]
array_api_tests/test_has_names.py::test_has_names[linalg-cross]
array_api_tests/test_has_names.py::test_has_names[linalg-det]
Expand Down Expand Up @@ -36,7 +35,6 @@ array_api_tests/test_has_names.py::test_has_names[creation-from_dlpack]
array_api_tests/test_has_names.py::test_has_names[creation-linspace]
array_api_tests/test_has_names.py::test_has_names[creation-meshgrid]
array_api_tests/test_has_names.py::test_has_names[sorting-argsort]
array_api_tests/test_has_names.py::test_has_names[data_type-isdtype]
array_api_tests/test_has_names.py::test_has_names[array_method-__dlpack__]
array_api_tests/test_has_names.py::test_has_names[array_method-__dlpack_device__]
array_api_tests/test_has_names.py::test_has_names[array_method-__setitem__]
Expand All @@ -50,7 +48,6 @@ array_api_tests/test_signatures.py::test_func_signature[from_dlpack]
array_api_tests/test_signatures.py::test_func_signature[linspace]
array_api_tests/test_signatures.py::test_func_signature[meshgrid]
array_api_tests/test_signatures.py::test_func_signature[argsort]
array_api_tests/test_signatures.py::test_func_signature[isdtype]
array_api_tests/test_signatures.py::test_array_method_signature[__dlpack__]
array_api_tests/test_signatures.py::test_array_method_signature[__dlpack_device__]
array_api_tests/test_signatures.py::test_array_method_signature[__setitem__]
Expand All @@ -74,71 +71,28 @@ array_api_tests/test_data_type_functions.py::test_finfo[complex64]
array_api_tests/test_manipulation_functions.py::test_squeeze
array_api_tests/test_has_names.py::test_has_names[utility-diff]
array_api_tests/test_has_names.py::test_has_names[manipulation-repeat]
array_api_tests/test_has_names.py::test_has_names[elementwise-copysign]
array_api_tests/test_has_names.py::test_has_names[manipulation-tile]
array_api_tests/test_has_names.py::test_has_names[manipulation-unstack]
array_api_tests/test_has_names.py::test_has_names[elementwise-hypot]
array_api_tests/test_has_names.py::test_has_names[elementwise-maximum]
array_api_tests/test_has_names.py::test_has_names[elementwise-minimum]
array_api_tests/test_has_names.py::test_has_names[elementwise-nextafter]
array_api_tests/test_has_names.py::test_has_names[elementwise-reciprocal]
array_api_tests/test_has_names.py::test_has_names[elementwise-signbit]
array_api_tests/test_has_names.py::test_has_names[statistical-cumulative_sum]
array_api_tests/test_has_names.py::test_has_names[statistical-cumulative_prod]
array_api_tests/test_has_names.py::test_has_names[indexing-take_along_axis]
array_api_tests/test_has_names.py::test_has_names[info-__array_namespace_info__]
array_api_tests/test_has_names.py::test_has_names[searching-count_nonzero]
array_api_tests/test_has_names.py::test_has_names[searching-searchsorted]
array_api_tests/test_inspection_functions.py::test_array_namespace_info
array_api_tests/test_inspection_functions.py::test_array_namespace_info_dtypes
array_api_tests/test_signatures.py::test_func_signature[diff]
array_api_tests/test_signatures.py::test_func_signature[repeat]
array_api_tests/test_signatures.py::test_func_signature[tile]
array_api_tests/test_signatures.py::test_func_signature[unstack]
array_api_tests/test_signatures.py::test_func_signature[astype]
array_api_tests/test_signatures.py::test_func_signature[copysign]
array_api_tests/test_signatures.py::test_func_signature[hypot]
array_api_tests/test_signatures.py::test_func_signature[maximum]
array_api_tests/test_signatures.py::test_func_signature[minimum]
array_api_tests/test_signatures.py::test_func_signature[nextafter]
array_api_tests/test_signatures.py::test_func_signature[reciprocal]
array_api_tests/test_signatures.py::test_func_signature[signbit]
array_api_tests/test_signatures.py::test_func_signature[take_along_axis]
array_api_tests/test_signatures.py::test_func_signature[__array_namespace_info__]
array_api_tests/test_signatures.py::test_info_func_signature[capabilities]
array_api_tests/test_signatures.py::test_info_func_signature[default_device]
array_api_tests/test_signatures.py::test_info_func_signature[default_dtypes]
array_api_tests/test_signatures.py::test_info_func_signature[devices]
array_api_tests/test_signatures.py::test_info_func_signature[dtypes]
array_api_tests/test_special_cases.py::test_unary[clip(x_i is NaN) -> NaN]
array_api_tests/test_special_cases.py::test_unary[signbit(x_i is +0) -> False]
array_api_tests/test_special_cases.py::test_unary[signbit(x_i is -0) -> True]
array_api_tests/test_special_cases.py::test_unary[signbit(x_i is +infinity) -> False]
array_api_tests/test_special_cases.py::test_unary[signbit(x_i is -infinity) -> True]
array_api_tests/test_special_cases.py::test_unary[signbit(isfinite(x_i) and x_i > 0) -> False]
array_api_tests/test_special_cases.py::test_unary[signbit(isfinite(x_i) and x_i < 0) -> True]
array_api_tests/test_special_cases.py::test_unary[signbit(x_i is +NaN) -> False]
array_api_tests/test_special_cases.py::test_unary[signbit(x_i is -NaN) -> True]
array_api_tests/test_special_cases.py::test_binary[copysign(x1_i is NaN and x2_i < 0) -> NaN]
array_api_tests/test_special_cases.py::test_binary[copysign(x1_i is NaN and x2_i is -0) -> NaN]
array_api_tests/test_special_cases.py::test_binary[copysign(x1_i is NaN and x2_i is +0) -> NaN]
array_api_tests/test_special_cases.py::test_binary[copysign(x1_i is NaN and x2_i > 0) -> NaN]
array_api_tests/test_special_cases.py::test_binary[floor_divide(x1_i is +infinity and isfinite(x2_i) and x2_i > 0) -> +infinity]
array_api_tests/test_special_cases.py::test_binary[floor_divide(x1_i is +infinity and isfinite(x2_i) and x2_i < 0) -> -infinity]
array_api_tests/test_special_cases.py::test_binary[floor_divide(x1_i is -infinity and isfinite(x2_i) and x2_i > 0) -> -infinity]
array_api_tests/test_special_cases.py::test_binary[floor_divide(x1_i is -infinity and isfinite(x2_i) and x2_i < 0) -> +infinity]
array_api_tests/test_special_cases.py::test_binary[floor_divide(isfinite(x1_i) and x1_i > 0 and x2_i is -infinity) -> -0]
array_api_tests/test_operators_and_elementwise_functions.py::test_nextafter
array_api_tests/test_special_cases.py::test_binary[__floordiv__(x1_i is +infinity and isfinite(x2_i) and x2_i > 0) -> +infinity]
array_api_tests/test_special_cases.py::test_binary[floor_divide(isfinite(x1_i) and x1_i < 0 and x2_i is +infinity) -> -0]
array_api_tests/test_special_cases.py::test_binary[__floordiv__(x1_i is +infinity and isfinite(x2_i) and x2_i < 0) -> -infinity]
array_api_tests/test_special_cases.py::test_binary[maximum(x1_i is NaN or x2_i is NaN) -> NaN]
array_api_tests/test_special_cases.py::test_binary[__floordiv__(x1_i is -infinity and isfinite(x2_i) and x2_i > 0) -> -infinity]
array_api_tests/test_special_cases.py::test_binary[minimum(x1_i is NaN or x2_i is NaN) -> NaN]
array_api_tests/test_special_cases.py::test_binary[__floordiv__(x1_i is -infinity and isfinite(x2_i) and x2_i < 0) -> +infinity]
array_api_tests/test_special_cases.py::test_binary[nextafter(x1_i is NaN or x2_i is NaN) -> NaN]
array_api_tests/test_special_cases.py::test_binary[nextafter(x1_i is -0 and x2_i is +0) -> +0]
array_api_tests/test_special_cases.py::test_binary[nextafter(x1_i is +0 and x2_i is -0) -> -0]
array_api_tests/test_special_cases.py::test_binary[__floordiv__(isfinite(x1_i) and x1_i > 0 and x2_i is -infinity) -> -0]
array_api_tests/test_special_cases.py::test_binary[__floordiv__(isfinite(x1_i) and x1_i < 0 and x2_i is +infinity) -> -0]
array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(x1_i is +infinity and isfinite(x2_i) and x2_i > 0) -> +infinity]
Expand All @@ -147,30 +101,18 @@ array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(x1_i is +infinity
array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(isfinite(x1_i) and x1_i > 0 and x2_i is -infinity) -> -0]
array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(x1_i is -infinity and isfinite(x2_i) and x2_i > 0) -> -infinity]
array_api_tests/test_special_cases.py::test_iop[__ifloordiv__(isfinite(x1_i) and x1_i < 0 and x2_i is +infinity) -> -0]
array_api_tests/test_operators_and_elementwise_functions.py::test_reciprocal
array_api_tests/test_array_object.py::test_getitem_arrays_and_ints_1[1]
array_api_tests/test_statistical_functions.py::test_cumulative_prod
array_api_tests/test_statistical_functions.py::test_cumulative_sum
array_api_tests/test_array_object.py::test_getitem_arrays_and_ints_1[None]
array_api_tests/test_operators_and_elementwise_functions.py::test_signbit
array_api_tests/test_array_object.py::test_getitem_arrays_and_ints_2[1]
array_api_tests/test_array_object.py::test_getitem_arrays_and_ints_2[None]
array_api_tests/test_manipulation_functions.py::test_repeat
array_api_tests/test_searching_functions.py::test_count_nonzero
array_api_tests/test_operators_and_elementwise_functions.py::test_copysign
array_api_tests/test_operators_and_elementwise_functions.py::test_maximum
array_api_tests/test_searching_functions.py::test_searchsorted
array_api_tests/test_manipulation_functions.py::test_tile
array_api_tests/test_signatures.py::test_func_signature[cumulative_sum]
array_api_tests/test_signatures.py::test_func_signature[cumulative_prod]
array_api_tests/test_manipulation_functions.py::test_unstack
array_api_tests/test_operators_and_elementwise_functions.py::test_minimum
array_api_tests/test_operators_and_elementwise_functions.py::test_hypot
array_api_tests/test_operators_and_elementwise_functions.py::test_clip
array_api_tests/test_signatures.py::test_func_signature[count_nonzero]
array_api_tests/test_signatures.py::test_func_signature[searchsorted]
array_api_tests/test_operators_and_elementwise_functions.py::test_binary_with_scalars_real[copysign]
array_api_tests/test_operators_and_elementwise_functions.py::test_binary_with_scalars_real[hypot]
array_api_tests/test_operators_and_elementwise_functions.py::test_binary_with_scalars_real[nextafter]
array_api_tests/test_operators_and_elementwise_functions.py::test_binary_with_scalars_real[maximum]
array_api_tests/test_operators_and_elementwise_functions.py::test_binary_with_scalars_real[minimum]
1 change: 1 addition & 0 deletions sparse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class SparseFutureWarning(FutureWarning):
from sparse.numba_backend import * # noqa: F403
from sparse.numba_backend import ( # noqa: F401
__all__,
__array_namespace_info__,
_common,
_compressed,
_coo,
Expand Down
26 changes: 26 additions & 0 deletions sparse/numba_backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
complex64,
complex128,
conj,
copysign,
cos,
cosh,
divide,
Expand All @@ -22,6 +23,7 @@
floor_divide,
greater,
greater_equal,
hypot,
iinfo,
inf,
int8,
Expand All @@ -40,15 +42,20 @@
logical_not,
logical_or,
logical_xor,
maximum,
minimum,
multiply,
nan,
negative,
newaxis,
nextafter,
not_equal,
pi,
positive,
reciprocal,
remainder,
sign,
signbit,
sin,
sinh,
sqrt,
Expand Down Expand Up @@ -158,6 +165,8 @@
)
from ._dok import DOK
from ._io import load_npz, save_npz
from ._settings import IS_NUMPY2 as _IS_NUMPY2
from ._settings import __array_namespace_info__ # noqa: F401
from ._umath import elemwise
from ._utils import random

Expand Down Expand Up @@ -203,6 +212,7 @@
"concat",
"concatenate",
"conj",
"copysign",
"cos",
"cosh",
"diagonal",
Expand Down Expand Up @@ -230,6 +240,7 @@
"full_like",
"greater",
"greater_equal",
"hypot",
"iinfo",
"imag",
"inf",
Expand Down Expand Up @@ -258,8 +269,10 @@
"matmul",
"matrix_transpose",
"max",
"maximum",
"mean",
"min",
"minimum",
"moveaxis",
"multiply",
"nan",
Expand All @@ -271,6 +284,7 @@
"nansum",
"negative",
"newaxis",
"nextafter",
"nonzero",
"not_equal",
"ones",
Expand All @@ -284,13 +298,15 @@
"prod",
"random",
"real",
"reciprocal",
"remainder",
"reshape",
"result_type",
"roll",
"round",
"save_npz",
"sign",
"signbit",
"sin",
"sinh",
"sort",
Expand Down Expand Up @@ -320,3 +336,13 @@
"zeros",
"zeros_like",
]


if _IS_NUMPY2:
from numpy import isdtype

__all__ += [
"isdtype",
]

__all__.sort()
3 changes: 2 additions & 1 deletion sparse/numba_backend/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2726,7 +2726,8 @@ def reshape(x, /, shape, *, copy=None):
return x.reshape(shape=shape)


def astype(x, dtype, /, *, copy=True):
@_check_device
def astype(x, dtype, /, *, copy=True, device=None):
"""
Copies an array to a specified data type irrespective of type-promotion rules.

Expand Down
30 changes: 30 additions & 0 deletions sparse/numba_backend/_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

AUTO_DENSIFY = bool(int(os.environ.get("SPARSE_AUTO_DENSIFY", "0")))
WARN_ON_TOO_DENSE = bool(int(os.environ.get("SPARSE_WARN_ON_TOO_DENSE", "0")))
IS_NUMPY2 = np.lib.NumpyVersion(np.__version__) >= "2.0.0a1"


def _is_nep18_enabled():
Expand All @@ -18,3 +19,32 @@


NEP18_ENABLED = _is_nep18_enabled()


class ArrayNamespaceInfo:
def __init__(self):
self.np_info = np.__array_namespace_info__()

Check warning on line 26 in sparse/numba_backend/_settings.py

View check run for this annotation

Codecov / codecov/patch

sparse/numba_backend/_settings.py#L26

Added line #L26 was not covered by tests

def capabilities(self):
np_capabilities = self.np_info.capabilities()
return {

Check warning on line 30 in sparse/numba_backend/_settings.py

View check run for this annotation

Codecov / codecov/patch

sparse/numba_backend/_settings.py#L29-L30

Added lines #L29 - L30 were not covered by tests
"boolean indexing": True,
"data-dependent shapes": True,
"max dimensions": np_capabilities.get("max dimensions", 64) - 1,
}

def default_device(self):
return self.np_info.default_device()

Check warning on line 37 in sparse/numba_backend/_settings.py

View check run for this annotation

Codecov / codecov/patch

sparse/numba_backend/_settings.py#L37

Added line #L37 was not covered by tests

def default_dtypes(self, *, device=None):
return self.np_info.default_dtypes(device=device)

Check warning on line 40 in sparse/numba_backend/_settings.py

View check run for this annotation

Codecov / codecov/patch

sparse/numba_backend/_settings.py#L40

Added line #L40 was not covered by tests

def devices(self):
return self.np_info.devices()

Check warning on line 43 in sparse/numba_backend/_settings.py

View check run for this annotation

Codecov / codecov/patch

sparse/numba_backend/_settings.py#L43

Added line #L43 was not covered by tests

def dtypes(self, *, device=None, kind=None):
return self.np_info.dtypes(device=device, kind=kind)

Check warning on line 46 in sparse/numba_backend/_settings.py

View check run for this annotation

Codecov / codecov/patch

sparse/numba_backend/_settings.py#L46

Added line #L46 was not covered by tests


def __array_namespace_info__() -> ArrayNamespaceInfo:
return ArrayNamespaceInfo()

Check warning on line 50 in sparse/numba_backend/_settings.py

View check run for this annotation

Codecov / codecov/patch

sparse/numba_backend/_settings.py#L50

Added line #L50 was not covered by tests
2 changes: 0 additions & 2 deletions sparse/numba_backend/_sparse_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,6 @@ def clip(self, min=None, max=None, out=None):
- [sparse.clip][] : For full documentation and more details.
- [`numpy.clip`][] : Equivalent NumPy function.
"""
if min is None and max is None:
raise ValueError("One of max or min must be given.")
if out is not None and not isinstance(out, tuple):
out = (out,)
return self.__array_ufunc__(np.clip, "__call__", self, a_min=min, a_max=max, out=out)
Expand Down
3 changes: 0 additions & 3 deletions sparse/numba_backend/tests/test_coo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1130,9 +1130,6 @@ def test_clip():

assert_eq(np.clip(s, 1, 3), np.clip(x, 1, 3))

with pytest.raises(ValueError):
s.clip()

out = sparse.COO.from_numpy(np.zeros_like(x))
out2 = s.clip(min=1, max=3, out=out)
assert out is out2
Expand Down
Loading
Loading