Skip to content

Commit bb06ebe

Browse files
committed
Fix legacy fornav not handling casting properly
1 parent 3050a62 commit bb06ebe

File tree

1 file changed

+58
-16
lines changed

1 file changed

+58
-16
lines changed

pyresample/ewa/_fornav.pyx

+58-16
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,10 @@ def fornav_wrapper(numpy.ndarray[cr_dtype, ndim=2, mode='c'] cols_array,
275275
if not all(output_array.dtype == out_type for output_array in output_arrays):
276276
raise ValueError("Input arrays must all be of the same data type")
277277

278-
cdef cr_dtype** input_pointer = <cr_dtype ** >malloc(num_items * sizeof(void * ))
278+
cdef void** input_pointer = <void ** >malloc(num_items * sizeof(void * ))
279279
if not input_pointer:
280280
raise MemoryError()
281-
cdef cr_dtype ** output_pointer = <cr_dtype ** >malloc(num_items * sizeof(void * ))
281+
cdef void** output_pointer = <void ** >malloc(num_items * sizeof(void * ))
282282
if not output_pointer:
283283
raise MemoryError()
284284
cdef unsigned int * valid_arr = <unsigned int * >malloc(num_items * sizeof(unsigned int))
@@ -287,22 +287,64 @@ def fornav_wrapper(numpy.ndarray[cr_dtype, ndim=2, mode='c'] cols_array,
287287
cdef cr_dtype * rows_pointer = &rows_array[0, 0]
288288
cdef bint mwm = maximum_weight_mode
289289
cdef int func_result
290-
cdef cr_dtype cast_input_fill = input_fill
291-
cdef cr_dtype cast_output_fill = output_fill
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
292299
cdef cr_dtype[:, ::1] tmp_arr
293300

294-
for i in range(num_items):
295-
tmp_arr = input_arrays[i]
296-
input_pointer[i] = &tmp_arr[0, 0]
297-
tmp_arr = output_arrays[i]
298-
output_pointer[i] = &tmp_arr[0, 0]
299-
with nogil:
300-
func_result = fornav(valid_arr, num_items, swath_cols, swath_rows, grid_cols, grid_rows,
301-
cols_pointer, rows_pointer,
302-
input_pointer, output_pointer,
303-
cast_input_fill, cast_output_fill, rows_per_scan,
304-
weight_count, weight_min, weight_distance_max, weight_delta_max, weight_sum_min,
305-
mwm)
301+
if in_type == numpy.float32:
302+
input_fill_f32 = <numpy.float32_t>input_fill
303+
output_fill_f32 = <numpy.float32_t>output_fill
304+
for i in range(num_items):
305+
tmp_arr_f32 = input_arrays[i]
306+
input_pointer[i] = &tmp_arr_f32[0, 0]
307+
tmp_arr_f32 = output_arrays[i]
308+
output_pointer[i] = &tmp_arr_f32[0, 0]
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)
316+
elif in_type == numpy.float64:
317+
input_fill_f64 = <numpy.float64_t>input_fill
318+
output_fill_f64 = <numpy.float64_t>output_fill
319+
for i in range(num_items):
320+
tmp_arr_f64 = input_arrays[i]
321+
input_pointer[i] = &tmp_arr_f64[0, 0]
322+
tmp_arr_f64 = output_arrays[i]
323+
output_pointer[i] = &tmp_arr_f64[0, 0]
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)
331+
elif in_type == numpy.int8:
332+
input_fill_i8 = <numpy.int8_t>input_fill
333+
output_fill_i8 = <numpy.int8_t>output_fill
334+
for i in range(num_items):
335+
tmp_arr_i8 = input_arrays[i]
336+
input_pointer[i] = &tmp_arr_i8[0, 0]
337+
tmp_arr_i8 = output_arrays[i]
338+
output_pointer[i] = &tmp_arr_i8[0, 0]
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)
346+
else:
347+
raise ValueError("Unknown input and output data type")
306348

307349
for i in range(num_items):
308350
valid_list.append(valid_arr[i])

0 commit comments

Comments
 (0)