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,36 @@ 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
+ ld_dict [ ' width' ] = np .dtype (np .longdouble ).itemsize
64
+ vals = tuple ( ld_dict [ k ] for k in ( ' nmant' , ' nexp' , ' width' ) )
60
65
# Information for PPC head / tail doubles from:
61
66
# https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man3/float.3.html
62
67
if vals in ((52 , 11 , 8 ), # longdouble is same as double
63
68
(63 , 15 , 12 ), (63 , 15 , 16 ), # intel 80 bit
64
69
(112 , 15 , 16 ), # real float128
65
70
(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 )
71
+ pass
72
+ elif vals == (105 , 11 , 16 ): # bust info for PPC head / tail longdoubles
73
+ # min and max broken.
74
+ ld_dict ['min' ] = infod ['min' ]
75
+ ld_dict ['max' ] = infod ['max' ]
76
+ elif vals == (1 , 1 , 16 ): # another bust info for PPC head / tail longdoubles
77
+ ld_dict = dbl_dict .copy ()
78
+ ld_dict .update (dict (nmant = 106 , width = 16 ))
75
79
elif vals == (52 , 15 , 12 ):
76
- exp_res = type_info (np .float64 )
77
- exp_res ['width' ] = width
78
- assert_equal (exp_res , infod )
80
+ ld_dict = dbl_dict .copy ()
81
+ ld_dict ['width' ] = width
79
82
else :
80
- raise ValueError ("Unexpected float type to test" )
83
+ raise ValueError ("Unexpected float type {} to test" .format (np .longdouble ))
84
+ assert_equal (ld_dict , infod )
81
85
82
86
83
87
def test_nmant ():
@@ -103,7 +107,7 @@ def test_check_nmant_nexp():
103
107
# Check against type_info
104
108
for t in ok_floats ():
105
109
ti = type_info (t )
106
- if ti ['nmant' ] != 106 : # This check does not work for PPC double pair
110
+ if ti ['nmant' ] not in ( 105 , 106 ) : # This check does not work for PPC double pair
107
111
assert_true (_check_nmant (t , ti ['nmant' ]))
108
112
# Test fails for longdouble after blacklisting of OSX powl as of numpy
109
113
# 1.12 - see https://github.com/numpy/numpy/issues/8307
0 commit comments