30
30
LD_INFO = type_info (np .longdouble )
31
31
32
32
33
+ def dtt2dict (dtt ):
34
+ """ Create info dictionary from numpy type
35
+ """
36
+ info = np .finfo (dtt )
37
+ return dict (min = info .min , max = info .max ,
38
+ nexp = info .nexp , nmant = info .nmant ,
39
+ minexp = info .minexp , maxexp = info .maxexp ,
40
+ width = np .dtype (dtt ).itemsize )
41
+
42
+
33
43
def test_type_info ():
34
44
# Test routine to get min, max, nmant, nexp
35
45
for dtt in np .sctypes ['int' ] + np .sctypes ['uint' ]:
@@ -42,42 +52,35 @@ def test_type_info():
42
52
assert_equal (infod ['min' ].dtype .type , dtt )
43
53
assert_equal (infod ['max' ].dtype .type , dtt )
44
54
for dtt in IEEE_floats + [np .complex64 , np .complex64 ]:
45
- info = np .finfo (dtt )
46
55
infod = type_info (dtt )
47
- assert_equal (dict (min = info .min , max = info .max ,
48
- nexp = info .nexp , nmant = info .nmant ,
49
- minexp = info .minexp , maxexp = info .maxexp ,
50
- width = np .dtype (dtt ).itemsize ),
51
- infod )
56
+ assert_equal (dtt2dict (dtt ), infod )
52
57
assert_equal (infod ['min' ].dtype .type , dtt )
53
58
assert_equal (infod ['max' ].dtype .type , dtt )
54
59
# What is longdouble?
55
- info = np . finfo (np .longdouble )
56
- dbl_info = np . finfo (np .float64 )
60
+ ld_dict = dtt2dict (np .longdouble )
61
+ dbl_dict = dtt2dict (np .float64 )
57
62
infod = type_info (np .longdouble )
58
- width = np .dtype (np .longdouble ).itemsize
59
- vals = (info .nmant , info .nexp , width )
63
+ vals = tuple (ld_dict [k ] for k in ('nmant' , 'nexp' , 'width' ))
60
64
# Information for PPC head / tail doubles from:
61
65
# https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man3/float.3.html
62
66
if vals in ((52 , 11 , 8 ), # longdouble is same as double
63
67
(63 , 15 , 12 ), (63 , 15 , 16 ), # intel 80 bit
64
68
(112 , 15 , 16 ), # real float128
65
69
(106 , 11 , 16 )): # PPC head, tail doubles, expected values
66
- assert_equal (dict (min = info .min , max = info .max ,
67
- minexp = info .minexp , maxexp = info .maxexp ,
68
- nexp = info .nexp , nmant = info .nmant , width = width ),
69
- infod )
70
- elif vals == (1 , 1 , 16 ): # bust info for PPC head / tail longdoubles
71
- assert_equal (dict (min = dbl_info .min , max = dbl_info .max ,
72
- minexp = - 1022 , maxexp = 1024 ,
73
- nexp = 11 , nmant = 106 , width = 16 ),
74
- infod )
70
+ pass
71
+ elif vals == (105 , 11 , 16 ): # bust info for PPC head / tail longdoubles
72
+ # min and max broken, copy from infod
73
+ ld_dict .update ({k : infod [k ] for k in ('min' , 'max' )})
74
+ elif vals == (1 , 1 , 16 ): # another bust info for PPC head / tail longdoubles
75
+ ld_dict = dbl_dict .copy ()
76
+ ld_dict .update (dict (nmant = 106 , width = 16 ))
75
77
elif vals == (52 , 15 , 12 ):
76
- exp_res = type_info ( np . float64 )
77
- exp_res [ 'width' ] = width
78
- assert_equal ( exp_res , infod )
78
+ width = ld_dict [ 'width' ]
79
+ ld_dict = dbl_dict . copy ()
80
+ ld_dict [ 'width' ] = width
79
81
else :
80
- raise ValueError ("Unexpected float type to test" )
82
+ raise ValueError ("Unexpected float type {} to test" .format (np .longdouble ))
83
+ assert_equal (ld_dict , infod )
81
84
82
85
83
86
def test_nmant ():
@@ -103,7 +106,7 @@ def test_check_nmant_nexp():
103
106
# Check against type_info
104
107
for t in ok_floats ():
105
108
ti = type_info (t )
106
- if ti ['nmant' ] != 106 : # This check does not work for PPC double pair
109
+ if ti ['nmant' ] not in ( 105 , 106 ) : # This check does not work for PPC double pair
107
110
assert_true (_check_nmant (t , ti ['nmant' ]))
108
111
# Test fails for longdouble after blacklisting of OSX powl as of numpy
109
112
# 1.12 - see https://github.com/numpy/numpy/issues/8307
0 commit comments