diff options
author | Dong-hee Na <donghee.na@python.org> | 2022-09-11 05:44:10 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-10 22:44:10 +0200 |
commit | 8d75a13fdece95ddc1bba42cad3aea3ccb396e05 (patch) | |
tree | d10fcf61314f11ecd5dd966b5c1c874808ad5727 /Lib/test/test_memoryview.py | |
parent | c4e57fb6df15266920941b732ef3a58fb619d851 (diff) | |
download | cpython-8d75a13fdece95ddc1bba42cad3aea3ccb396e05.tar.gz cpython-8d75a13fdece95ddc1bba42cad3aea3ccb396e05.zip |
gh-90751: memoryview now supports half-float (#96738)
Co-authored-by: Antoine Pitrou <antoine@python.org>
Diffstat (limited to 'Lib/test/test_memoryview.py')
-rw-r--r-- | Lib/test/test_memoryview.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/test/test_memoryview.py b/Lib/test/test_memoryview.py index 9d1e1f3063c..0eb2a367603 100644 --- a/Lib/test/test_memoryview.py +++ b/Lib/test/test_memoryview.py @@ -13,6 +13,7 @@ import array import io import copy import pickle +import struct from test.support import import_helper @@ -527,6 +528,14 @@ class OtherTest(unittest.TestCase): m[2:] = memoryview(p6).cast(format)[2:] self.assertEqual(d.value, 0.6) + def test_half_float(self): + half_data = struct.pack('eee', 0.0, -1.5, 1.5) + float_data = struct.pack('fff', 0.0, -1.5, 1.5) + half_view = memoryview(half_data).cast('e') + float_view = memoryview(float_data).cast('f') + self.assertEqual(half_view.nbytes * 2, float_view.nbytes) + self.assertListEqual(half_view.tolist(), float_view.tolist()) + def test_memoryview_hex(self): # Issue #9951: memoryview.hex() segfaults with non-contiguous buffers. x = b'0' * 200000 |