Skip to content

Commit

Permalink
Remove inline from cython classes (#49873)
Browse files Browse the repository at this point in the history
* removed inline class functions

* removed all cdef inline

* revert pxd

* removed unused code

* cython lint fixups
  • Loading branch information
WillAyd authored Dec 6, 2022
1 parent 2d185e1 commit d660831
Show file tree
Hide file tree
Showing 28 changed files with 274 additions and 290 deletions.
6 changes: 3 additions & 3 deletions pandas/_libs/algos.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ tiebreakers = {
}


cdef inline bint are_diff(object left, object right):
cdef bint are_diff(object left, object right):
try:
return fabs(left - right) > FP_ERR
except TypeError:
Expand Down Expand Up @@ -257,7 +257,7 @@ def groupsort_indexer(const intp_t[:] index, Py_ssize_t ngroups):
return indexer.base, counts.base


cdef inline Py_ssize_t swap(numeric_t *a, numeric_t *b) nogil:
cdef Py_ssize_t swap(numeric_t *a, numeric_t *b) nogil:
cdef:
numeric_t t

Expand All @@ -268,7 +268,7 @@ cdef inline Py_ssize_t swap(numeric_t *a, numeric_t *b) nogil:
return 0


cdef inline numeric_t kth_smallest_c(numeric_t* arr, Py_ssize_t k, Py_ssize_t n) nogil:
cdef numeric_t kth_smallest_c(numeric_t* arr, Py_ssize_t k, Py_ssize_t n) nogil:
"""
See kth_smallest.__doc__. The additional parameter n specifies the maximum
number of elements considered in arr, needed for compatibility with usage
Expand Down
8 changes: 4 additions & 4 deletions pandas/_libs/groupby.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ cdef enum InterpolationEnumType:
INTERPOLATION_MIDPOINT


cdef inline float64_t median_linear_mask(float64_t* a, int n, uint8_t* mask) nogil:
cdef float64_t median_linear_mask(float64_t* a, int n, uint8_t* mask) nogil:
cdef:
int i, j, na_count = 0
float64_t* tmp
Expand Down Expand Up @@ -97,7 +97,7 @@ cdef inline float64_t median_linear_mask(float64_t* a, int n, uint8_t* mask) nog
return result


cdef inline float64_t median_linear(float64_t* a, int n) nogil:
cdef float64_t median_linear(float64_t* a, int n) nogil:
cdef:
int i, j, na_count = 0
float64_t* tmp
Expand Down Expand Up @@ -134,7 +134,7 @@ cdef inline float64_t median_linear(float64_t* a, int n) nogil:
return result


cdef inline float64_t calc_median_linear(float64_t* a, int n, int na_count) nogil:
cdef float64_t calc_median_linear(float64_t* a, int n, int na_count) nogil:
cdef:
float64_t result

Expand Down Expand Up @@ -1231,7 +1231,7 @@ def group_quantile(
# group_nth, group_last, group_rank
# ----------------------------------------------------------------------

cdef inline bint _treat_as_na(numeric_object_t val, bint is_datetimelike) nogil:
cdef bint _treat_as_na(numeric_object_t val, bint is_datetimelike) nogil:
if numeric_object_t is object:
# Should never be used, but we need to avoid the `val != val` below
# or else cython will raise about gil acquisition.
Expand Down
8 changes: 4 additions & 4 deletions pandas/_libs/hashing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ def hash_object_array(
return result.base # .base to retrieve underlying np.ndarray


cdef inline uint64_t _rotl(uint64_t x, uint64_t b) nogil:
cdef uint64_t _rotl(uint64_t x, uint64_t b) nogil:
return (x << b) | (x >> (64 - b))


cdef inline uint64_t u8to64_le(uint8_t* p) nogil:
cdef uint64_t u8to64_le(uint8_t* p) nogil:
return (<uint64_t>p[0] |
<uint64_t>p[1] << 8 |
<uint64_t>p[2] << 16 |
Expand All @@ -125,8 +125,8 @@ cdef inline uint64_t u8to64_le(uint8_t* p) nogil:
<uint64_t>p[7] << 56)


cdef inline void _sipround(uint64_t* v0, uint64_t* v1,
uint64_t* v2, uint64_t* v3) nogil:
cdef void _sipround(uint64_t* v0, uint64_t* v1,
uint64_t* v2, uint64_t* v3) nogil:
v0[0] += v1[0]
v1[0] = _rotl(v1[0], 13)
v1[0] ^= v0[0]
Expand Down
2 changes: 1 addition & 1 deletion pandas/_libs/hashtable.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,5 @@ cdef class Int64Vector(Vector):

cdef resize(self)
cpdef ndarray to_array(self)
cdef inline void append(self, int64_t x)
cdef void append(self, int64_t x)
cdef extend(self, int64_t[:] x)
10 changes: 5 additions & 5 deletions pandas/_libs/hashtable_class_helper.pxi.in
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ ctypedef struct {{name}}VectorData:

@cython.wraparound(False)
@cython.boundscheck(False)
cdef inline void append_data_{{dtype}}({{name}}VectorData *data,
cdef void append_data_{{dtype}}({{name}}VectorData *data,
{{c_type}} x) nogil:

data.data[data.n] = x
Expand All @@ -163,7 +163,7 @@ ctypedef fused vector_data:
Complex64VectorData
StringVectorData

cdef inline bint needs_resize(vector_data *data) nogil:
cdef bint needs_resize(vector_data *data) nogil:
return data.n == data.m

# ----------------------------------------------------------------------
Expand Down Expand Up @@ -241,7 +241,7 @@ cdef class {{name}}Vector(Vector):
self.external_view_exists = True
return self.ao

cdef inline void append(self, {{c_type}} x):
cdef void append(self, {{c_type}} x):

if needs_resize(self.data):
if self.external_view_exists:
Expand Down Expand Up @@ -311,7 +311,7 @@ cdef class StringVector(Vector):
self.data.m = self.data.n
return ao

cdef inline void append(self, char *x):
cdef void append(self, char *x):

if needs_resize(self.data):
self.resize()
Expand Down Expand Up @@ -339,7 +339,7 @@ cdef class ObjectVector(Vector):
def __len__(self) -> int:
return self.n

cdef inline append(self, object obj):
cdef append(self, object obj):
if self.n == self.m:
if self.external_view_exists:
raise ValueError("external reference but "
Expand Down
12 changes: 6 additions & 6 deletions pandas/_libs/index.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ from pandas._libs.missing cimport (
multiindex_nulls_shift = 2


cdef inline bint is_definitely_invalid_key(object val):
cdef bint is_definitely_invalid_key(object val):
try:
hash(val)
except TypeError:
Expand Down Expand Up @@ -176,7 +176,7 @@ cdef class IndexEngine:
loc = self.values.searchsorted(self._np_type(val), side="left")
return loc

cdef inline _get_loc_duplicates(self, object val):
cdef _get_loc_duplicates(self, object val):
# -> Py_ssize_t | slice | ndarray[bool]
cdef:
Py_ssize_t diff, left, right
Expand Down Expand Up @@ -225,7 +225,7 @@ cdef class IndexEngine:

return self.unique == 1

cdef inline _do_unique_check(self):
cdef _do_unique_check(self):

# this de-facto the same
self._ensure_mapping_populated()
Expand All @@ -244,7 +244,7 @@ cdef class IndexEngine:

return self.monotonic_dec == 1

cdef inline _do_monotonic_check(self):
cdef _do_monotonic_check(self):
cdef:
bint is_unique
try:
Expand Down Expand Up @@ -277,7 +277,7 @@ cdef class IndexEngine:
def is_mapping_populated(self) -> bool:
return self.mapping is not None

cdef inline _ensure_mapping_populated(self):
cdef _ensure_mapping_populated(self):
# this populates the mapping
# if its not already populated
# also satisfies the need_unique_check
Expand Down Expand Up @@ -932,7 +932,7 @@ cdef class SharedEngine:

return self._get_loc_duplicates(val)

cdef inline _get_loc_duplicates(self, object val):
cdef _get_loc_duplicates(self, object val):
# -> Py_ssize_t | slice | ndarray[bool]
cdef:
Py_ssize_t diff
Expand Down
Loading

0 comments on commit d660831

Please sign in to comment.