Skip to content

Commit d3a6355

Browse files
fix for #46 : do not call MKL is input size is zero
1 parent 66ff0dd commit d3a6355

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

mkl_fft/src/mklfft.c.src

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2017-2019, Intel Corporation
2+
Copyright (c) 2017-2020, Intel Corporation
33

44
Redistribution and use in source and binary forms, with or without
55
modification, are permitted provided that the following conditions are met:
@@ -35,6 +35,7 @@
3535
#include <limits.h>
3636

3737
#ifdef DEBUG
38+
#include <assert.h>
3839
#include <stdio.h>
3940
#define _debug_print(...) printf(__VA_ARGS__)
4041
#else
@@ -471,6 +472,9 @@ int @name@_mkl_@mode@_in(PyArrayObject* x_inout, npy_intp n, int axis, DftiCache
471472
get_basic_array_data(x_inout, &x_rank, &x_shape,
472473
&x_strides, &x_itemsize, &x_size);
473474

475+
if (x_size == 0) /* nothing to do */
476+
return status;
477+
474478
assert( x_size > 0 ); /* assert that x is non-empty */
475479
assert( 0 <= axis && axis < x_rank );
476480
assert( x_itemsize == sizeof(@MKL_TYPE@) );
@@ -625,6 +629,11 @@ int @REALIN@_@COMPLEXOUT@_mkl_@mode@_out(
625629

626630
assert(xout_rank == xin_rank);
627631

632+
if (xin_size == 0) {
633+
/* nothing to do */
634+
assert(xin_size == xout_size);
635+
return status;
636+
}
628637
assert( xin_size > 0 ); /* assert that array is non-empty */
629638
assert(0 <= axis && axis < xin_rank);
630639
assert( 0 < n && n <= xin_shape[axis] );
@@ -886,6 +895,12 @@ int @COMPLEXIN@_@COMPLEXOUT@_mkl_@mode@_out(
886895

887896
assert(xout_rank == xin_rank);
888897

898+
if (xin_size == 0) {
899+
/* nothing to do */
900+
assert(xout_size == 0);
901+
return status;
902+
}
903+
889904
assert( xin_size > 0 ); /* assert that array is non-empty */
890905
assert(0 <= axis && axis < xin_rank);
891906
assert( 0 < n && n <= xin_shape[axis] );
@@ -1059,6 +1074,9 @@ int @name@_mkl_@mode@_in(PyArrayObject* x_inout, npy_intp n, int axis, DftiCache
10591074
get_basic_array_data(x_inout, &x_rank, &x_shape,
10601075
&x_strides, &x_itemsize, &x_size);
10611076

1077+
if (x_size == 0) /* nothing to do */
1078+
return status;
1079+
10621080
assert( x_size > 0 ); /* assert that */
10631081
assert(0 <= axis && axis < x_rank);
10641082
assert(x_itemsize == sizeof(@MKL_TYPE@));
@@ -1195,6 +1213,12 @@ int
11951213

11961214
assert(xout_rank == xin_rank);
11971215

1216+
if (xin_size == 0) {
1217+
/* nothing to do */
1218+
assert(xout_size == 0);
1219+
return status;
1220+
}
1221+
11981222
assert( xin_size > 0 ); /* assert that array is non-empty */
11991223
assert(0 <= axis && axis < xin_rank);
12001224
assert( 0 < n && n <= xout_shape[axis] );
@@ -1369,6 +1393,12 @@ int @name@_@name@_mkl_@mode@_out(
13691393

13701394
assert(xout_rank == xin_rank);
13711395

1396+
if(xin_size == 0) {
1397+
/* nothing to do */
1398+
assert(xout_size == 0);
1399+
return status;
1400+
}
1401+
13721402
assert( xin_size > 0 ); /* assert that array is non-empty */
13731403
assert(0 <= axis && axis < xin_rank);
13741404
assert( 0 < n && n <= xin_shape[axis] );
@@ -1543,6 +1573,9 @@ int
15431573
&x_strides, &x_itemsize, &x_size);
15441574

15451575

1576+
if (x_size == 0) /* nothing to do */
1577+
return status;
1578+
15461579
assert(x_size > 0);
15471580
assert(x_itemsize == sizeof(@MKL_IN_TYPE@));
15481581

@@ -1649,6 +1682,11 @@ int
16491682
get_basic_array_data(x_out, &xout_rank, &xout_shape,
16501683
&xout_strides, &xout_itemsize, &xout_size);
16511684

1685+
if(xin_size == 0) {
1686+
/* nothing to do */
1687+
assert(xout_size == 0);
1688+
return status;
1689+
}
16521690

16531691
assert(xin_size > 0);
16541692
assert(xin_itemsize == sizeof(@MKL_IN_TYPE@));
@@ -1778,6 +1816,11 @@ int
17781816
get_basic_array_data(x_out, &xout_rank, &xout_shape,
17791817
&xout_strides, &xout_itemsize, &xout_size);
17801818

1819+
if(xin_size == 0) {
1820+
/* nothing to do */
1821+
assert(xout_size == 0);
1822+
return status;
1823+
}
17811824

17821825
assert(xin_size > 0);
17831826
assert(xin_itemsize == sizeof(@MKL_IN_TYPE@));

0 commit comments

Comments
 (0)