@@ -94,15 +94,15 @@ ctypedef void (*FN)(const DTYPE_t[:, :, :] data, int l0, int p0, double dl, doub
9494
9595@cython .boundscheck (False )
9696@cython .wraparound (False )
97- cpdef one_step_gradient_search (np . ndarray [ DTYPE_t , ndim = 3 ] data ,
98- np . ndarray [ DTYPE_t , ndim = 2 ] src_x ,
99- np . ndarray [ DTYPE_t , ndim = 2 ] src_y ,
100- np . ndarray [ DTYPE_t , ndim = 2 ] xl ,
101- np . ndarray [ DTYPE_t , ndim = 2 ] xp ,
102- np . ndarray [ DTYPE_t , ndim = 2 ] yl ,
103- np . ndarray [ DTYPE_t , ndim = 2 ] yp ,
104- np . ndarray [ DTYPE_t , ndim = 2 ] dst_x ,
105- np . ndarray [ DTYPE_t , ndim = 2 ] dst_y ,
97+ cpdef one_step_gradient_search (const DTYPE_t [:, :, : ] data ,
98+ DTYPE_t [:, : ] src_x ,
99+ DTYPE_t [:, : ] src_y ,
100+ DTYPE_t [:, : ] xl ,
101+ DTYPE_t [:, : ] xp ,
102+ DTYPE_t [:, : ] yl ,
103+ DTYPE_t [:, : ] yp ,
104+ DTYPE_t [:, : ] dst_x ,
105+ DTYPE_t [:, : ] dst_y ,
106106 method = 'bilinear' ):
107107 """Gradient search, simple case variant."""
108108 cdef FN fun
@@ -119,16 +119,17 @@ cpdef one_step_gradient_search(np.ndarray[DTYPE_t, ndim=3] data,
119119
120120
121121 # output image array --> needs to be (lines, pixels) --> y,x
122- cdef np .ndarray [DTYPE_t , ndim = 3 ] image = np .full ([z_size , y_size , x_size ], np .nan , dtype = DTYPE )
123- cdef np .ndarray [size_t , ndim = 1 ] elements = np .arange (x_size , dtype = np .uintp )
124-
125- one_step_gradient_search_no_gil (data ,
126- src_x , src_y ,
127- xl , xp , yl , yp ,
128- dst_x , dst_y ,
129- x_size , y_size ,
130- fun , image ,
131- elements )
122+ image = np .full ([z_size , y_size , x_size ], np .nan , dtype = DTYPE )
123+ cdef DTYPE_t [:, :, :] image_view = image
124+ cdef size_t [:] elements = np .arange (x_size , dtype = np .uintp )
125+ with nogil :
126+ one_step_gradient_search_no_gil (data ,
127+ src_x , src_y ,
128+ xl , xp , yl , yp ,
129+ dst_x , dst_y ,
130+ x_size , y_size ,
131+ fun , image_view ,
132+ elements )
132133 # return the output image
133134 return image
134135
@@ -213,14 +214,14 @@ cdef void one_step_gradient_search_no_gil(const DTYPE_t[:, :, :] data,
213214
214215@cython .boundscheck (False )
215216@cython .wraparound (False )
216- cpdef one_step_gradient_indices (np . ndarray [ DTYPE_t , ndim = 2 ] src_x ,
217- np . ndarray [ DTYPE_t , ndim = 2 ] src_y ,
218- np . ndarray [ DTYPE_t , ndim = 2 ] xl ,
219- np . ndarray [ DTYPE_t , ndim = 2 ] xp ,
220- np . ndarray [ DTYPE_t , ndim = 2 ] yl ,
221- np . ndarray [ DTYPE_t , ndim = 2 ] yp ,
222- np . ndarray [ DTYPE_t , ndim = 2 ] dst_x ,
223- np . ndarray [ DTYPE_t , ndim = 2 ] dst_y ):
217+ cpdef one_step_gradient_indices (DTYPE_t [:, : ] src_x ,
218+ DTYPE_t [:, : ] src_y ,
219+ DTYPE_t [:, : ] xl ,
220+ DTYPE_t [:, : ] xp ,
221+ DTYPE_t [:, : ] yl ,
222+ DTYPE_t [:, : ] yp ,
223+ DTYPE_t [:, : ] dst_x ,
224+ DTYPE_t [:, : ] dst_y ):
224225 """Gradient search, simple case variant, returning float indices.
225226
226227 This is appropriate for monotonous gradients only, i.e. not modis or viirs in satellite projection.
@@ -232,17 +233,19 @@ cpdef one_step_gradient_indices(np.ndarray[DTYPE_t, ndim=2] src_x,
232233 cdef size_t x_size = dst_x .shape [1 ]
233234
234235 # output indices arrays --> needs to be (lines, pixels) --> y,x
235- cdef np .ndarray [DTYPE_t , ndim = 3 ] indices = np .full ([2 , y_size , x_size ], np .nan , dtype = DTYPE )
236- cdef np .ndarray [size_t , ndim = 1 ] elements = np .arange (x_size , dtype = np .uintp )
236+ indices = np .full ([2 , y_size , x_size ], np .nan , dtype = DTYPE )
237+ cdef DTYPE_t [:, :, :] indices_view = indices
238+ cdef size_t [:] elements = np .arange (x_size , dtype = np .uintp )
237239
238240 # fake_data is not going to be used anyway as we just fill in the indices
239- cdef np .ndarray [DTYPE_t , ndim = 3 ] fake_data = np .full ([1 , 1 , 1 ], np .nan , dtype = DTYPE )
240-
241- one_step_gradient_search_no_gil (fake_data ,
242- src_x , src_y ,
243- xl , xp , yl , yp ,
244- dst_x , dst_y ,
245- x_size , y_size ,
246- indices_xy , indices ,
247- elements )
241+ cdef DTYPE_t [:, :, :] fake_data = np .full ([1 , 1 , 1 ], np .nan , dtype = DTYPE )
242+
243+ with nogil :
244+ one_step_gradient_search_no_gil (fake_data ,
245+ src_x , src_y ,
246+ xl , xp , yl , yp ,
247+ dst_x , dst_y ,
248+ x_size , y_size ,
249+ indices_xy , indices_view ,
250+ elements )
248251 return indices
0 commit comments