2929from tripy .common .exception import TripyException
3030from tripy .common .utils import (
3131 convert_list_to_array ,
32- Float16MemoryView ,
3332 get_element_type ,
3433)
3534
@@ -50,43 +49,11 @@ def test_get_element_type():
5049 "values, dtype, expected" ,
5150 [
5251 ([True , False , True ], tripy .common .datatype .bool , b"\x01 \x00 \x01 " ),
53- ([1 , 2 , 3 ], tripy .common .datatype .int8 , b"\x01 \x02 \x03 " ),
5452 ([100000 , 200000 ], tripy .common .datatype .int32 , b"\xa0 \x86 \x01 \x00 @\x0d \x03 \x00 " ),
5553 ([1 , 2 ], tripy .common .datatype .int64 , b"\x01 \x00 \x00 \x00 \x00 \x00 \x00 \x00 \x02 \x00 \x00 \x00 \x00 \x00 \x00 \x00 " ),
56- ([1.0 , 2.0 ], tripy .common .datatype .float16 , b"\x00 <\x00 @" ),
5754 ([1.0 , 2.0 ], tripy .common .datatype .float32 , b"\x00 \x00 \x80 ?\x00 \x00 \x00 @" ),
5855 ],
5956)
60- def convert_list_to_array (values , dtype , expected ):
57+ def test_convert_list_to_array (values , dtype , expected ):
6158 result = convert_list_to_array (values , dtype )
62- assert result == expected
63-
64-
65- def test_float16_memoryview ():
66- memview = Float16MemoryView (bytearray (struct .pack ("5e" , 1.5 , 2.5 , 3.5 , 4.5 , 5.5 )))
67- assert memview .itemsize == 2
68- assert memview .format == "e"
69- len (memview ) == 5
70- assert memview [0 ] == pytest .approx (1.5 )
71- assert memview [2 ] == pytest .approx (3.5 )
72- assert memview [1 :4 ] == pytest .approx ([2.5 , 3.5 , 4.5 ])
73- expected = [1.5 , 2.5 , 3.5 , 4.5 , 5.5 ]
74- assert memview .tolist () == pytest .approx (expected )
75-
76- # Largest representable value in float16
77- large_value = 65504.0
78- buffer = struct .pack ("e" , large_value )
79- mv = Float16MemoryView (buffer )
80- assert mv [0 ] == pytest .approx (large_value )
81-
82- # Smallest positive normal number for float16
83- small_value = 6.1035e-5
84- buffer = struct .pack ("e" , small_value )
85- mv = Float16MemoryView (buffer )
86- assert mv [0 ] == pytest .approx (small_value , rel = 1e-3 )
87-
88- # Negative value
89- negative_value = - 42.5
90- buffer = struct .pack ("e" , negative_value )
91- mv = Float16MemoryView (buffer )
92- assert mv [0 ] == pytest .approx (negative_value )
59+ assert result .tobytes () == expected
0 commit comments