@@ -39,10 +39,6 @@ cdef extern from "_fornav_templates.h":
39
39
ctypedef float ewa_param_type
40
40
ctypedef float accum_type
41
41
cdef float EPSILON
42
- # ctypedef double weight_type
43
- # ctypedef double ewa_param_type
44
- # ctypedef double accum_type
45
- # cdef double EPSILON
46
42
47
43
ctypedef struct ewa_parameters :
48
44
ewa_param_type a
@@ -64,42 +60,42 @@ cdef extern from "_fornav_templates.h":
64
60
weight_type * wtab
65
61
66
62
cdef int initialize_weight (size_t chan_count , unsigned int weight_count , weight_type weight_min , weight_type weight_distance_max ,
67
- weight_type weight_delta_max , weight_type weight_sum_min , ewa_weight * ewaw )
68
- cdef void deinitialize_weight (ewa_weight * ewaw )
69
- cdef accum_type ** initialize_grid_accums (size_t chan_count , size_t grid_cols , size_t grid_rows )
70
- cdef weight_type ** initialize_grid_weights (size_t chan_count , size_t grid_cols , size_t grid_rows )
71
- cdef void deinitialize_grids (size_t chan_count , void ** grids )
63
+ weight_type weight_delta_max , weight_type weight_sum_min , ewa_weight * ewaw ) nogil
64
+ cdef void deinitialize_weight (ewa_weight * ewaw ) nogil
65
+ cdef accum_type ** initialize_grid_accums (size_t chan_count , size_t grid_cols , size_t grid_rows ) nogil
66
+ cdef weight_type ** initialize_grid_weights (size_t chan_count , size_t grid_cols , size_t grid_rows ) nogil
67
+ cdef void deinitialize_grids (size_t chan_count , void ** grids ) nogil
72
68
73
69
cdef int compute_ewa_parameters [CR_TYPE ](size_t swath_cols , size_t swath_rows ,
74
- CR_TYPE * uimg , CR_TYPE * vimg , ewa_weight * ewaw , ewa_parameters * ewap )
70
+ CR_TYPE * uimg , CR_TYPE * vimg , ewa_weight * ewaw , ewa_parameters * ewap ) nogil
75
71
76
72
cdef int compute_ewa [CR_TYPE , IMAGE_TYPE ](
77
73
size_t chan_count , bint maximum_weight_mode ,
78
74
size_t swath_cols , size_t swath_rows , size_t grid_cols , size_t grid_rows ,
79
75
CR_TYPE * uimg , CR_TYPE * vimg ,
80
76
IMAGE_TYPE ** images , IMAGE_TYPE img_fill , accum_type ** grid_accums , weight_type ** grid_weights ,
81
- ewa_weight * ewaw , ewa_parameters * ewap )
77
+ ewa_weight * ewaw , ewa_parameters * ewap ) nogil
82
78
83
79
cdef int compute_ewa_single [CR_TYPE , IMAGE_TYPE ](
84
80
bint maximum_weight_mode ,
85
81
size_t swath_cols , size_t swath_rows , size_t grid_cols , size_t grid_rows ,
86
82
CR_TYPE * uimg , CR_TYPE * vimg ,
87
83
IMAGE_TYPE * image , IMAGE_TYPE img_fill , accum_type * grid_accum , weight_type * grid_weight ,
88
- ewa_weight * ewaw , ewa_parameters * ewap )
84
+ ewa_weight * ewaw , ewa_parameters * ewap ) nogil
89
85
90
86
# For some reason cython can't deduce the type when using the template
91
87
# cdef int write_grid_image[GRID_TYPE](GRID_TYPE *output_image, GRID_TYPE fill, size_t grid_cols, size_t grid_rows,
92
88
# accum_type *grid_accum, weight_type *grid_weights,
93
89
# int maximum_weight_mode, weight_type weight_sum_min)
94
90
cdef unsigned int write_grid_image (numpy .float32_t * output_image , numpy .float32_t fill , size_t grid_cols , size_t grid_rows ,
95
91
accum_type * grid_accum , weight_type * grid_weights ,
96
- int maximum_weight_mode , weight_type weight_sum_min )
92
+ int maximum_weight_mode , weight_type weight_sum_min ) nogil
97
93
cdef unsigned int write_grid_image (numpy .float64_t * output_image , numpy .float64_t fill , size_t grid_cols , size_t grid_rows ,
98
94
accum_type * grid_accum , weight_type * grid_weights ,
99
- int maximum_weight_mode , weight_type weight_sum_min )
95
+ int maximum_weight_mode , weight_type weight_sum_min ) nogil
100
96
cdef unsigned int write_grid_image (numpy .int8_t * output_image , numpy .int8_t fill , size_t grid_cols , size_t grid_rows ,
101
97
accum_type * grid_accum , weight_type * grid_weights ,
102
- int maximum_weight_mode , weight_type weight_sum_min )
98
+ int maximum_weight_mode , weight_type weight_sum_min ) nogil
103
99
104
100
ctypedef fused cr_dtype :
105
101
numpy .float32_t
@@ -124,7 +120,7 @@ cdef int fornav(unsigned int * valid_list, size_t chan_count, size_t swath_cols,
124
120
image_dtype ** input_arrays , grid_dtype ** output_arrays ,
125
121
image_dtype input_fill , grid_dtype output_fill , size_t rows_per_scan ,
126
122
unsigned int weight_count , weight_type weight_min , weight_type weight_distance_max , weight_type weight_delta_max ,
127
- weight_type weight_sum_min , bint maximum_weight_mode ) except - 1 :
123
+ weight_type weight_sum_min , bint maximum_weight_mode ) nogil except - 1 :
128
124
cdef unsigned int row_idx
129
125
cdef unsigned int idx
130
126
cdef bint got_point = 0
@@ -279,54 +275,74 @@ def fornav_wrapper(numpy.ndarray[cr_dtype, ndim=2, mode='c'] cols_array,
279
275
if not all (output_array .dtype == out_type for output_array in output_arrays ):
280
276
raise ValueError ("Input arrays must all be of the same data type" )
281
277
282
- cdef void ** input_pointer = < void ** > malloc (num_items * sizeof (void * ))
278
+ cdef void ** input_pointer = < void ** > malloc (num_items * sizeof (void * ))
283
279
if not input_pointer :
284
280
raise MemoryError ()
285
- cdef void ** output_pointer = < void ** > malloc (num_items * sizeof (void * ))
281
+ cdef void ** output_pointer = < void ** > malloc (num_items * sizeof (void * ))
286
282
if not output_pointer :
287
283
raise MemoryError ()
288
284
cdef unsigned int * valid_arr = < unsigned int * > malloc (num_items * sizeof (unsigned int ))
289
285
valid_list = []
290
- cdef numpy .ndarray [numpy .float32_t , ndim = 2 ] tmp_arr_f32
291
- cdef numpy .ndarray [numpy .float64_t , ndim = 2 ] tmp_arr_f64
292
- cdef numpy .ndarray [numpy .int8_t , ndim = 2 ] tmp_arr_i8
293
286
cdef cr_dtype * cols_pointer = & cols_array [0 , 0 ]
294
287
cdef cr_dtype * rows_pointer = & rows_array [0 , 0 ]
288
+ cdef bint mwm = maximum_weight_mode
295
289
cdef int func_result
290
+ cdef numpy .float32_t input_fill_f32
291
+ cdef numpy .float64_t input_fill_f64
292
+ cdef numpy .int8_t input_fill_i8
293
+ cdef numpy .float32_t output_fill_f32
294
+ cdef numpy .float64_t output_fill_f64
295
+ cdef numpy .int8_t output_fill_i8
296
+ cdef numpy .ndarray [numpy .float32_t , ndim = 2 ] tmp_arr_f32
297
+ cdef numpy .ndarray [numpy .float64_t , ndim = 2 ] tmp_arr_f64
298
+ cdef numpy .ndarray [numpy .int8_t , ndim = 2 ] tmp_arr_i8
299
+ cdef cr_dtype [:, ::1 ] tmp_arr
296
300
297
301
if in_type == numpy .float32 :
302
+ input_fill_f32 = < numpy .float32_t > input_fill
303
+ output_fill_f32 = < numpy .float32_t > output_fill
298
304
for i in range (num_items ):
299
305
tmp_arr_f32 = input_arrays [i ]
300
306
input_pointer [i ] = & tmp_arr_f32 [0 , 0 ]
301
307
tmp_arr_f32 = output_arrays [i ]
302
308
output_pointer [i ] = & tmp_arr_f32 [0 , 0 ]
303
- func_result = fornav (valid_arr , num_items , swath_cols , swath_rows , grid_cols , grid_rows , cols_pointer , rows_pointer ,
304
- < numpy .float32_t ** > input_pointer , < numpy .float32_t ** > output_pointer ,
305
- < numpy .float32_t > input_fill , < numpy .float32_t > output_fill , rows_per_scan ,
306
- weight_count , weight_min , weight_distance_max , weight_delta_max , weight_sum_min ,
307
- < bint > maximum_weight_mode )
309
+ with nogil :
310
+ func_result = fornav (valid_arr , num_items , swath_cols , swath_rows , grid_cols , grid_rows ,
311
+ cols_pointer , rows_pointer ,
312
+ < numpy .float32_t ** > input_pointer , < numpy .float32_t ** > output_pointer ,
313
+ output_fill_f32 , output_fill_f32 , rows_per_scan ,
314
+ weight_count , weight_min , weight_distance_max , weight_delta_max , weight_sum_min ,
315
+ mwm )
308
316
elif in_type == numpy .float64 :
317
+ input_fill_f64 = < numpy .float64_t > input_fill
318
+ output_fill_f64 = < numpy .float64_t > output_fill
309
319
for i in range (num_items ):
310
320
tmp_arr_f64 = input_arrays [i ]
311
321
input_pointer [i ] = & tmp_arr_f64 [0 , 0 ]
312
322
tmp_arr_f64 = output_arrays [i ]
313
323
output_pointer [i ] = & tmp_arr_f64 [0 , 0 ]
314
- func_result = fornav (valid_arr , num_items , swath_cols , swath_rows , grid_cols , grid_rows , cols_pointer , rows_pointer ,
315
- < numpy .float64_t ** > input_pointer , < numpy .float64_t ** > output_pointer ,
316
- < numpy .float64_t > input_fill , < numpy .float64_t > output_fill , rows_per_scan ,
317
- weight_count , weight_min , weight_distance_max , weight_delta_max , weight_sum_min ,
318
- < bint > maximum_weight_mode )
324
+ with nogil :
325
+ func_result = fornav (valid_arr , num_items , swath_cols , swath_rows , grid_cols , grid_rows ,
326
+ cols_pointer , rows_pointer ,
327
+ < numpy .float64_t ** > input_pointer , < numpy .float64_t ** > output_pointer ,
328
+ input_fill_f64 , output_fill_f64 , rows_per_scan ,
329
+ weight_count , weight_min , weight_distance_max , weight_delta_max , weight_sum_min ,
330
+ mwm )
319
331
elif in_type == numpy .int8 :
332
+ input_fill_i8 = < numpy .int8_t > input_fill
333
+ output_fill_i8 = < numpy .int8_t > output_fill
320
334
for i in range (num_items ):
321
335
tmp_arr_i8 = input_arrays [i ]
322
336
input_pointer [i ] = & tmp_arr_i8 [0 , 0 ]
323
337
tmp_arr_i8 = output_arrays [i ]
324
338
output_pointer [i ] = & tmp_arr_i8 [0 , 0 ]
325
- func_result = fornav (valid_arr , num_items , swath_cols , swath_rows , grid_cols , grid_rows , cols_pointer , rows_pointer ,
326
- < numpy .int8_t ** > input_pointer , < numpy .int8_t ** > output_pointer ,
327
- < numpy .int8_t > input_fill , < numpy .int8_t > output_fill , rows_per_scan ,
328
- weight_count , weight_min , weight_distance_max , weight_delta_max , weight_sum_min ,
329
- < bint > maximum_weight_mode )
339
+ with nogil :
340
+ func_result = fornav (valid_arr , num_items , swath_cols , swath_rows , grid_cols , grid_rows ,
341
+ cols_pointer , rows_pointer ,
342
+ < numpy .int8_t ** > input_pointer , < numpy .int8_t ** > output_pointer ,
343
+ input_fill_i8 , output_fill_i8 , rows_per_scan ,
344
+ weight_count , weight_min , weight_distance_max , weight_delta_max , weight_sum_min ,
345
+ mwm )
330
346
else :
331
347
raise ValueError ("Unknown input and output data type" )
332
348
@@ -347,7 +363,7 @@ cdef int fornav_weights_and_sums(
347
363
image_dtype * input_array , weight_type * grid_weights , accum_type * grid_accums ,
348
364
image_dtype input_fill , grid_dtype output_fill , size_t rows_per_scan ,
349
365
unsigned int weight_count , weight_type weight_min , weight_type weight_distance_max , weight_type weight_delta_max ,
350
- weight_type weight_sum_min , bint maximum_weight_mode ) except - 1 :
366
+ weight_type weight_sum_min , bint maximum_weight_mode ) nogil except - 1 :
351
367
"""Get the weights and sums arrays from the fornav algorithm.
352
368
353
369
Typically fornav performs the entire operation of computing the weights
@@ -482,12 +498,14 @@ def fornav_weights_and_sums_wrapper(numpy.ndarray[cr_dtype, ndim=2, mode='c'] co
482
498
cdef weight_type * weights_pointer = & grid_weights [0 , 0 ]
483
499
cdef accum_type * accums_pointer = & grid_accums [0 , 0 ]
484
500
cdef int got_point
501
+ cdef bint mwm = maximum_weight_mode
485
502
486
- ret_val = fornav_weights_and_sums (swath_cols , swath_rows , grid_cols , grid_rows , cols_pointer , rows_pointer ,
487
- input_pointer , weights_pointer , accums_pointer ,
488
- input_fill , output_fill , rows_per_scan ,
489
- weight_count , weight_min , weight_distance_max , weight_delta_max , weight_sum_min ,
490
- < bint > maximum_weight_mode )
503
+ with nogil :
504
+ ret_val = fornav_weights_and_sums (swath_cols , swath_rows , grid_cols , grid_rows , cols_pointer , rows_pointer ,
505
+ input_pointer , weights_pointer , accums_pointer ,
506
+ input_fill , output_fill , rows_per_scan ,
507
+ weight_count , weight_min , weight_distance_max , weight_delta_max , weight_sum_min ,
508
+ mwm )
491
509
492
510
succeeded = ret_val == 0
493
511
return succeeded
@@ -501,8 +519,11 @@ def write_grid_image_single(numpy.ndarray[grid_dtype, ndim=2, mode='c'] output_a
501
519
grid_dtype output_fill ,
502
520
weight_type weight_sum_min = - 1.0 ,
503
521
cpython .bool maximum_weight_mode = False ):
504
- # unsigned int write_grid_image(GRID_TYPE *output_image, GRID_TYPE fill, size_t grid_cols, size_t grid_rows,
505
- # accum_type *grid_accum, weight_type *grid_weights,
506
- # int maximum_weight_mode, weight_type weight_sum_min) {
507
- return write_grid_image (& output_array [0 , 0 ], output_fill , < size_t > output_array .shape [1 ], < size_t > output_array .shape [0 ],
508
- & grid_accums [0 , 0 ], & grid_weights [0 , 0 ], < int > maximum_weight_mode , weight_sum_min )
522
+ cdef int mwm = < int > maximum_weight_mode
523
+ cdef size_t grid_cols = < size_t > output_array .shape [1 ]
524
+ cdef size_t grid_rows = < size_t > output_array .shape [0 ]
525
+ cdef unsigned int result
526
+ with nogil :
527
+ result = write_grid_image (& output_array [0 , 0 ], output_fill , grid_cols , grid_rows ,
528
+ & grid_accums [0 , 0 ], & grid_weights [0 , 0 ], mwm , weight_sum_min )
529
+ return result
0 commit comments