Skip to content

Commit

Permalink
Merge pull request #163 from StingraySoftware/fix_array_take
Browse files Browse the repository at this point in the history
Numba now supports array np.take, we remove this conflicting overload
  • Loading branch information
matteobachetti authored Jun 12, 2024
2 parents 8990b80 + 9efd168 commit 5dc8c88
Showing 1 changed file with 6 additions and 17 deletions.
23 changes: 6 additions & 17 deletions hendrics/compat/compatibility.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from functools import wraps
import warnings
import numpy as np
from astropy import log
from collections.abc import Iterable as iterable
Expand All @@ -9,20 +10,6 @@
from numba import types
from numba.extending import overload_method

@overload_method(types.Array, "take") # pragma: no cover
def array_take(arr, indices):
"""Adapt np.take to arrays"""
if isinstance(indices, types.Array):

def take_impl(arr, indices):
n = indices.shape[0]
res = np.empty(n, arr.dtype)
for i in range(n):
res[i] = arr[indices[i]]
return res

return take_impl

HAS_NUMBA = True
except ImportError:
HAS_NUMBA = False
Expand Down Expand Up @@ -57,6 +44,8 @@ def __call__(self, func):

float32 = float64 = int32 = int64 = lambda x, y: None

def array_take(arr, indices):
"""Adapt np.take to arrays"""
return np.take(arr, indices)

def array_take(arr, indices): # pragma: no cover
"""Adapt np.take to arrays"""
warnings.warn("array_take is deprecated. Use np.take instead, also with Numba.")
return np.take(arr, indices)

0 comments on commit 5dc8c88

Please sign in to comment.