3030LD_INFO = type_info (np .longdouble )
3131
3232
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+
3343def test_type_info ():
3444 # Test routine to get min, max, nmant, nexp
3545 for dtt in np .sctypes ['int' ] + np .sctypes ['uint' ]:
@@ -42,42 +52,35 @@ def test_type_info():
4252 assert_equal (infod ['min' ].dtype .type , dtt )
4353 assert_equal (infod ['max' ].dtype .type , dtt )
4454 for dtt in IEEE_floats + [np .complex64 , np .complex64 ]:
45- info = np .finfo (dtt )
4655 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 )
5257 assert_equal (infod ['min' ].dtype .type , dtt )
5358 assert_equal (infod ['max' ].dtype .type , dtt )
5459 # 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 )
5762 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' ))
6064 # Information for PPC head / tail doubles from:
6165 # https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man3/float.3.html
6266 if vals in ((52 , 11 , 8 ), # longdouble is same as double
6367 (63 , 15 , 12 ), (63 , 15 , 16 ), # intel 80 bit
6468 (112 , 15 , 16 ), # real float128
6569 (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 ))
7577 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
7981 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 )
8184
8285
8386def test_nmant ():
@@ -103,7 +106,7 @@ def test_check_nmant_nexp():
103106 # Check against type_info
104107 for t in ok_floats ():
105108 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
107110 assert_true (_check_nmant (t , ti ['nmant' ]))
108111 # Test fails for longdouble after blacklisting of OSX powl as of numpy
109112 # 1.12 - see https://github.com/numpy/numpy/issues/8307
0 commit comments