coredevice: Fix RPC typing for bool lists/arrays

GitHub: Fixes #1635.
This commit is contained in:
David Nadlinger 2021-03-20 00:03:10 +00:00 committed by Sebastien Bourdeauducq
parent c1413a9945
commit ca6db87895
2 changed files with 6 additions and 2 deletions

View File

@ -66,7 +66,7 @@ def _receive_list(kernel, embedding_map):
tag = chr(kernel._read_int8())
if tag == "b":
buffer = kernel._read(length)
return list(buffer)
return [bool(a) for a in buffer]
elif tag == "i":
buffer = kernel._read(4 * length)
return list(struct.unpack(kernel.endian + "%sl" % length, buffer))
@ -96,7 +96,7 @@ def _receive_array(kernel, embedding_map):
length = numpy.prod(shape)
if tag == "b":
buffer = kernel._read(length)
elems = numpy.ndarray((length, ), 'B', buffer)
elems = numpy.ndarray((length, ), '?', buffer)
elif tag == "i":
buffer = kernel._read(4 * length)
elems = numpy.ndarray((length, ), kernel.endian + 'i4', buffer)

View File

@ -55,6 +55,9 @@ class RoundtripTest(ExperimentCase):
def test_list(self):
self.assertRoundtrip([10])
def test_bool_list(self):
self.assertRoundtrip([True, False])
def test_object(self):
obj = object()
self.assertRoundtrip(obj)
@ -69,6 +72,7 @@ class RoundtripTest(ExperimentCase):
self.assertRoundtrip([(0x12345678, [("foo", [0.0, 1.0], [0, 1])])])
def test_array_1d(self):
self.assertArrayRoundtrip(numpy.array([True, False]))
self.assertArrayRoundtrip(numpy.array([1, 2, 3], dtype=numpy.int32))
self.assertArrayRoundtrip(numpy.array([1.0, 2.0, 3.0]))
self.assertArrayRoundtrip(numpy.array(["a", "b", "c"]))