Skip to content

Commit 86a6df8

Browse files
author
adelepoulle
committed
Cython: use of adress to speed up c function
1 parent 8dc14c6 commit 86a6df8

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

src/py_eddy_tracker/tools.pyx

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -276,18 +276,22 @@ cdef dist_array_size(
276276
DTYPE_ui i_start,
277277
DTYPE_ui nb_c_per_l,
278278
DTYPE_ui * nb_pt_per_c,
279-
DTYPE_ui * c_i
279+
DTYPE_ui * c_i,
280+
# return param
281+
DTYPE_ui * i_end,
282+
DTYPE_ui * c_start,
283+
DTYPE_ui * c_end
280284
):
281285
"""Give slice to select data
282286
"""
283-
cdef DTYPE_ui i_elt, i_end, nb_pts
284-
i_end = i_start + nb_c_per_l
287+
cdef DTYPE_ui i_elt, nb_pts
288+
i_end[0] = i_start + nb_c_per_l
285289
nb_pts = 0
286290

287-
for i_elt from i_start <= i_elt < i_end:
288-
nb_pts += nb_pt_per_c[i_elt]
289-
i_contour = c_i[i_start]
290-
return i_start, i_end, i_contour, i_contour + nb_pts
291+
c_start[0] = c_i[i_start]
292+
c_end[0] = c_start[0]
293+
for i_elt from i_start <= i_elt < i_end[0]:
294+
c_end[0] += nb_pt_per_c[i_elt]
291295

292296

293297
@wraparound(False)
@@ -314,20 +318,25 @@ def index_from_nearest_path(
314318
if nb_contour == 0:
315319
return None
316320

317-
main_start, main_stop, start, end = dist_array_size(
318-
l_i[level_index],
321+
main_start = l_i[level_index]
322+
dist_array_size(
323+
main_start,
319324
nb_contour,
320325
& nb_pt_per_c[0],
321326
& indices_of_first_pts[0],
327+
& main_stop,
328+
& start,
329+
& end
322330
)
323331

324-
nearesti = nearest_contour_index(
332+
nearest_contour_index(
325333
& x_value[0],
326334
& y_value[0],
327335
xpt,
328336
ypt,
329337
start,
330338
end,
339+
&nearesti
331340
)
332341

333342
for i_elt from main_start <= i_elt < main_stop:
@@ -346,6 +355,8 @@ cdef nearest_contour_index(
346355
DTYPE_coord ypt,
347356
DTYPE_ui start,
348357
DTYPE_ui end,
358+
# return param
359+
DTYPE_ui * nearesti
349360
):
350361
"""Give index fron the nearest pts
351362
"""
@@ -358,4 +369,4 @@ cdef nearest_contour_index(
358369
if dist < dist_ref:
359370
dist_ref = dist
360371
i_ref = i_elt
361-
return i_ref - start
372+
nearesti[0] = i_ref - start

0 commit comments

Comments
 (0)