24
24
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25
25
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
26
27
- from numpy import (half , float32 , asarray , ndarray ,
28
- longdouble , float64 , longcomplex , complex_ , float128 , complex256 )
27
+ import numpy as np
29
28
30
29
__all__ = ['__upcast_float16_array' , '__downcast_float128_array' , '__supported_array_or_not_implemented' ]
31
30
@@ -35,18 +34,18 @@ def __upcast_float16_array(x):
35
34
instead of float64, as mkl_fft would do"""
36
35
if hasattr (x , "dtype" ):
37
36
xdt = x .dtype
38
- if xdt == half :
37
+ if xdt == np . half :
39
38
# no half-precision routines, so convert to single precision
40
- return asarray (x , dtype = float32 )
41
- if xdt == longdouble and not xdt == float64 :
39
+ return np . asarray (x , dtype = np . float32 )
40
+ if xdt == np . longdouble and not xdt == np . float64 :
42
41
raise ValueError ("type %s is not supported" % xdt )
43
- if not isinstance (x , ndarray ):
44
- __x = asarray (x )
42
+ if not isinstance (x , np . ndarray ):
43
+ __x = np . asarray (x )
45
44
xdt = __x .dtype
46
- if xdt == half :
45
+ if xdt == np . half :
47
46
# no half-precision routines, so convert to single precision
48
- return asarray (__x , dtype = float32 )
49
- if xdt == longdouble and not xdt == float64 :
47
+ return np . asarray (__x , dtype = np . float32 )
48
+ if xdt == np . longdouble and not xdt == np . float64 :
50
49
raise ValueError ("type %s is not supported" % xdt )
51
50
return __x
52
51
return x
@@ -58,17 +57,17 @@ def __downcast_float128_array(x):
58
57
complex128, instead of raising an error"""
59
58
if hasattr (x , "dtype" ):
60
59
xdt = x .dtype
61
- if xdt == longdouble and not xdt == float64 :
62
- return asarray (x , dtype = float64 )
63
- elif xdt == longcomplex and not xdt == complex_ :
64
- return asarray (x , dtype = complex_ )
65
- if not isinstance (x , ndarray ):
66
- __x = asarray (x )
60
+ if xdt == np . longdouble and not xdt == np . float64 :
61
+ return np . asarray (x , dtype = np . float64 )
62
+ elif xdt == np . longcomplex and not xdt == np . complex_ :
63
+ return np . asarray (x , dtype = np . complex_ )
64
+ if not isinstance (x , np . ndarray ):
65
+ __x = np . asarray (x )
67
66
xdt = __x .dtype
68
- if xdt == longdouble and not xdt == float64 :
69
- return asarray (x , dtype = float64 )
70
- elif xdt == longcomplex and not xdt == complex_ :
71
- return asarray (x , dtype = complex_ )
67
+ if xdt == np . longdouble and not xdt == np . float64 :
68
+ return np . asarray (x , dtype = np . float64 )
69
+ elif xdt == np . longcomplex and not xdt == np . complex_ :
70
+ return np . asarray (x , dtype = np . complex_ )
72
71
return __x
73
72
return x
74
73
@@ -78,7 +77,12 @@ def __supported_array_or_not_implemented(x):
78
77
Used in _scipy_fft_backend to convert array to float32,
79
78
float64, complex64, or complex128 type or return NotImplemented
80
79
"""
81
- __x = asarray (x )
82
- if __x .dtype in [half , float128 , complex256 ]:
80
+ __x = np .asarray (x )
81
+ black_list = [np .half ]
82
+ if hasattr (np , 'float128' ):
83
+ black_list .append (np .float128 )
84
+ if hasattr (np , 'complex256' ):
85
+ black_list .append (np .complex256 )
86
+ if __x .dtype in black_list :
83
87
return NotImplemented
84
88
return __x
0 commit comments