Skip to content

Commit d8a042e

Browse files
Add cython-lint to pre-commit configuration (#2925)
The PR extends pre-commit hooks with a `cython-lint` (used to lint Cython files) All detected issues were resolved
1 parent c1ce491 commit d8a042e

10 files changed

Lines changed: 1934 additions & 807 deletions

.git-blame-ignore-revs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ e62718415aa3660da5f607e352c991a063a54219
2020

2121
# Bump clang-format from 12.0.1 to 22.1.0 version
2222
c2d65bd451a7d8e5b6319147da95e9dabf7a382b
23+
24+
# cython-lint cleanup
25+
6afda951b26d59aee7488f40c40968feb4725ad8

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,8 @@ repos:
133133
- id: gersemi
134134
exclude: "dpnp/backend/cmake/Modules/"
135135
args: ["-i", "-l", "88", "--no-warn-about-unknown-commands"]
136+
- repo: https://github.com/MarcoGorelli/cython-lint
137+
rev: v0.19.0
138+
hooks:
139+
- id: cython-lint
140+
- id: double-quote-cython-strings

dpnp/dpnp_algo/dpnp_algo.pxd

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
# *****************************************************************************
3030

3131

32-
cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this namespace for Enum import
32+
# need this namespace for Enum import
33+
cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName":
3334
cdef enum DPNPFuncName "DPNPFuncName":
3435
DPNP_FN_PARTITION_EXT
3536
DPNP_FN_RNG_BETA_EXT
@@ -70,7 +71,8 @@ cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncName": # need this na
7071
DPNP_FN_RNG_WEIBULL_EXT
7172
DPNP_FN_RNG_ZIPF_EXT
7273

73-
cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncType": # need this namespace for Enum import
74+
# need this namespace for Enum import
75+
cdef extern from "dpnp_iface_fptr.hpp" namespace "DPNPFuncType":
7476
cdef enum DPNPFuncType "DPNPFuncType":
7577
DPNP_FT_NONE
7678
DPNP_FT_INT
@@ -88,7 +90,11 @@ cdef extern from "dpnp_iface_fptr.hpp":
8890
DPNPFuncType return_type_no_fp64
8991
void *ptr_no_fp64
9092

91-
DPNPFuncData get_dpnp_function_ptr(DPNPFuncName name, DPNPFuncType first_type, DPNPFuncType second_type) except +
93+
DPNPFuncData get_dpnp_function_ptr(
94+
DPNPFuncName name,
95+
DPNPFuncType first_type,
96+
DPNPFuncType second_type,
97+
) except +
9298

9399

94100
"""

dpnp/dpnp_algo/dpnp_algo.pyx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,30 +62,31 @@ cdef DPNPFuncType dpnp_dtype_to_DPNPFuncType(dtype):
6262
kind = chr(kind)
6363
itemsize = dpnp.dtype(dtype).itemsize
6464

65-
if dt_c == 'd':
65+
if dt_c == "d":
6666
return DPNP_FT_DOUBLE
67-
elif dt_c == 'f':
67+
elif dt_c == "f":
6868
return DPNP_FT_FLOAT
69-
elif kind == 'i':
69+
elif kind == "i":
7070
if itemsize == 8:
7171
return DPNP_FT_LONG
7272
elif itemsize == 4:
7373
return DPNP_FT_INT
7474
else:
7575
utils.checker_throw_type_error("dpnp_dtype_to_DPNPFuncType", dtype)
76-
elif dt_c == 'F':
76+
elif dt_c == "F":
7777
return DPNP_FT_CMPLX64
78-
elif dt_c == 'D':
78+
elif dt_c == "D":
7979
return DPNP_FT_CMPLX128
80-
elif dt_c == '?':
80+
elif dt_c == "?":
8181
return DPNP_FT_BOOL
8282
else:
8383
utils.checker_throw_type_error("dpnp_dtype_to_DPNPFuncType", dtype)
8484

8585

8686
cdef dpnp_DPNPFuncType_to_dtype(size_t type):
8787
"""
88-
Type 'size_t' used instead 'DPNPFuncType' because Cython has lack of Enum support (0.29)
88+
Type 'size_t' used instead 'DPNPFuncType' because
89+
Cython has lack of Enum support (0.29)
8990
TODO needs to use DPNPFuncType here
9091
"""
9192
if type == <size_t > DPNP_FT_DOUBLE:

dpnp/dpnp_algo/dpnp_algo_indexing.pxi

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ __all__ += [
4242
"dpnp_putmask",
4343
]
4444

45-
cpdef dpnp_putmask(utils.dpnp_descriptor arr, utils.dpnp_descriptor mask, utils.dpnp_descriptor values):
45+
cpdef dpnp_putmask(
46+
utils.dpnp_descriptor arr,
47+
utils.dpnp_descriptor mask,
48+
utils.dpnp_descriptor values,
49+
):
4650
cdef int values_size = values.size
4751

4852
mask_flatiter = mask.get_pyobj().flat

dpnp/dpnp_algo/dpnp_algo_sorting.pxi

Lines changed: 71 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -43,52 +43,85 @@ __all__ += [
4343
]
4444

4545

46-
ctypedef c_dpctl.DPCTLSyclEventRef(*fptr_dpnp_partition_t)(c_dpctl.DPCTLSyclQueueRef,
47-
void * ,
48-
void * ,
49-
void * ,
50-
const size_t,
51-
const shape_elem_type * ,
52-
const size_t,
53-
const c_dpctl.DPCTLEventVectorRef)
54-
55-
56-
cpdef utils.dpnp_descriptor dpnp_partition(utils.dpnp_descriptor arr, int kth, axis=-1, kind='introselect', order=None):
46+
ctypedef c_dpctl.DPCTLSyclEventRef(
47+
*fptr_dpnp_partition_t)(
48+
c_dpctl.DPCTLSyclQueueRef,
49+
void *,
50+
void *,
51+
void *,
52+
const size_t,
53+
const shape_elem_type *,
54+
const size_t,
55+
const c_dpctl.DPCTLEventVectorRef,
56+
)
57+
58+
59+
cpdef utils.dpnp_descriptor dpnp_partition(
60+
utils.dpnp_descriptor arr, int kth,
61+
axis=-1, kind="introselect", order=None,
62+
):
5763
cdef shape_type_c shape1 = arr.shape
5864

59-
cdef size_t kth_ = kth if kth >= 0 else (arr.ndim + kth)
60-
cdef DPNPFuncType param1_type = dpnp_dtype_to_DPNPFuncType(arr.dtype)
61-
62-
cdef DPNPFuncData kernel_data = get_dpnp_function_ptr(DPNP_FN_PARTITION_EXT, param1_type, param1_type)
63-
64-
cdef utils.dpnp_descriptor arr2 = dpnp.get_dpnp_descriptor(arr.get_pyobj().copy(), copy_when_nondefault_queue=False)
65+
cdef size_t kth_ = (
66+
kth if kth >= 0 else (arr.ndim + kth)
67+
)
68+
cdef DPNPFuncType param1_type = (
69+
dpnp_dtype_to_DPNPFuncType(arr.dtype)
70+
)
71+
72+
cdef DPNPFuncData kernel_data = (
73+
get_dpnp_function_ptr(
74+
DPNP_FN_PARTITION_EXT,
75+
param1_type, param1_type,
76+
)
77+
)
78+
79+
cdef utils.dpnp_descriptor arr2 = (
80+
dpnp.get_dpnp_descriptor(
81+
arr.get_pyobj().copy(),
82+
copy_when_nondefault_queue=False,
83+
)
84+
)
6585

6686
arr_obj = arr.get_array()
6787

68-
cdef utils.dpnp_descriptor result = utils.create_output_descriptor(arr.shape,
69-
kernel_data.return_type,
70-
None,
71-
device=arr_obj.sycl_device,
72-
usm_type=arr_obj.usm_type,
73-
sycl_queue=arr_obj.sycl_queue)
88+
cdef utils.dpnp_descriptor result = (
89+
utils.create_output_descriptor(
90+
arr.shape,
91+
kernel_data.return_type,
92+
None,
93+
device=arr_obj.sycl_device,
94+
usm_type=arr_obj.usm_type,
95+
sycl_queue=arr_obj.sycl_queue,
96+
)
97+
)
7498

7599
result_sycl_queue = result.get_array().sycl_queue
76100

77-
cdef c_dpctl.SyclQueue q = <c_dpctl.SyclQueue> result_sycl_queue
78-
cdef c_dpctl.DPCTLSyclQueueRef q_ref = q.get_queue_ref()
79-
80-
cdef fptr_dpnp_partition_t func = <fptr_dpnp_partition_t > kernel_data.ptr
81-
82-
cdef c_dpctl.DPCTLSyclEventRef event_ref = func(q_ref,
83-
arr.get_data(),
84-
arr2.get_data(),
85-
result.get_data(),
86-
kth_,
87-
shape1.data(),
88-
arr.ndim,
89-
NULL) # dep_events_ref
90-
91-
with nogil: c_dpctl.DPCTLEvent_WaitAndThrow(event_ref)
101+
cdef c_dpctl.SyclQueue q = (
102+
<c_dpctl.SyclQueue> result_sycl_queue
103+
)
104+
cdef c_dpctl.DPCTLSyclQueueRef q_ref = (
105+
q.get_queue_ref()
106+
)
107+
108+
cdef fptr_dpnp_partition_t func = (
109+
<fptr_dpnp_partition_t> kernel_data.ptr
110+
)
111+
112+
cdef c_dpctl.DPCTLSyclEventRef event_ref = func(
113+
q_ref,
114+
arr.get_data(),
115+
arr2.get_data(),
116+
result.get_data(),
117+
kth_,
118+
shape1.data(),
119+
arr.ndim,
120+
NULL,
121+
)
122+
123+
with nogil:
124+
c_dpctl.DPCTLEvent_WaitAndThrow(event_ref)
92125
c_dpctl.DPCTLEvent_Delete(event_ref)
93126

94127
return result

0 commit comments

Comments
 (0)