@@ -2008,9 +2008,11 @@ def test_roundtrip(self):
2008
2008
('l' , 'S4' ),
2009
2009
('m' , 'U4' ),
2010
2010
('n' , 'V3' ),
2011
- ('o' , '?' )]
2011
+ ('o' , '?' ),
2012
+ ('p' , np .half ),
2013
+ ]
2012
2014
x = np .array ([(1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
2013
- asbytes ('aaaa' ), 'bbbb' , asbytes ('xxx' ), True )],
2015
+ asbytes ('aaaa' ), 'bbbb' , asbytes ('xxx' ), True , 1.0 )],
2014
2016
dtype = dt )
2015
2017
self ._check_roundtrip (x )
2016
2018
@@ -2042,6 +2044,25 @@ def test_roundtrip(self):
2042
2044
x = np .array ([1 ,2 ,3 ], dtype = '<q' )
2043
2045
assert_raises (ValueError , self ._check_roundtrip , x )
2044
2046
2047
+ def test_roundtrip_half (self ):
2048
+ half_list = [
2049
+ 1.0 ,
2050
+ - 2.0 ,
2051
+ 6.5504 * 10 ** 4 , # (max half precision)
2052
+ 2 ** - 14 , # ~= 6.10352 * 10**-5 (minimum positive normal)
2053
+ 2 ** - 24 , # ~= 5.96046 * 10**-8 (minimum strictly positive subnormal)
2054
+ 0.0 ,
2055
+ - 0.0 ,
2056
+ float ('+inf' ),
2057
+ float ('-inf' ),
2058
+ 0.333251953125 , # ~= 1/3
2059
+ ]
2060
+
2061
+ x = np .array (half_list , dtype = '>e' )
2062
+ self ._check_roundtrip (x )
2063
+ x = np .array (half_list , dtype = '<e' )
2064
+ self ._check_roundtrip (x )
2065
+
2045
2066
def test_export_simple_1d (self ):
2046
2067
x = np .array ([1 ,2 ,3 ,4 ,5 ], dtype = 'i' )
2047
2068
y = memoryview (x )
@@ -2092,9 +2113,11 @@ def test_export_record(self):
2092
2113
('l' , 'S4' ),
2093
2114
('m' , 'U4' ),
2094
2115
('n' , 'V3' ),
2095
- ('o' , '?' )]
2116
+ ('o' , '?' ),
2117
+ ('p' , np .half ),
2118
+ ]
2096
2119
x = np .array ([(1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ,
2097
- asbytes ('aaaa' ), 'bbbb' , asbytes (' ' ), True )],
2120
+ asbytes ('aaaa' ), 'bbbb' , asbytes (' ' ), True , 1.0 )],
2098
2121
dtype = dt )
2099
2122
y = memoryview (x )
2100
2123
assert_equal (y .shape , (1 ,))
@@ -2103,9 +2126,9 @@ def test_export_record(self):
2103
2126
2104
2127
sz = sum ([dtype (b ).itemsize for a , b in dt ])
2105
2128
if dtype ('l' ).itemsize == 4 :
2106
- assert_equal (y .format , 'T{b:a:=h:b:i:c:l:d:^q:dx:B:e:@H:f:=I:g:L:h:^Q:hx:=f:i:d:j:^g:k:=Zf:ix:Zd:jx:^Zg:kx:4s:l:=4w:m:3x:n:?:o:}' )
2129
+ assert_equal (y .format , 'T{b:a:=h:b:i:c:l:d:^q:dx:B:e:@H:f:=I:g:L:h:^Q:hx:=f:i:d:j:^g:k:=Zf:ix:Zd:jx:^Zg:kx:4s:l:=4w:m:3x:n:?:o:@e:p: }' )
2107
2130
else :
2108
- assert_equal (y .format , 'T{b:a:=h:b:i:c:q:d:^q:dx:B:e:@H:f:=I:g:Q:h:^Q:hx:=f:i:d:j:^g:k:=Zf:ix:Zd:jx:^Zg:kx:4s:l:=4w:m:3x:n:?:o:}' )
2131
+ assert_equal (y .format , 'T{b:a:=h:b:i:c:q:d:^q:dx:B:e:@H:f:=I:g:Q:h:^Q:hx:=f:i:d:j:^g:k:=Zf:ix:Zd:jx:^Zg:kx:4s:l:=4w:m:3x:n:?:o:@e:p: }' )
2109
2132
assert_equal (y .strides , (sz ,))
2110
2133
assert_equal (y .itemsize , sz )
2111
2134
0 commit comments