From 888696f588eb09cc8943d0e0d8af71747293382f Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Sat, 20 Mar 2021 00:03:10 +0000 Subject: [PATCH] coredevice: Fix RPC typing for bool lists/arrays GitHub: Fixes #1635. --- artiq/coredevice/comm_kernel.py | 4 ++-- artiq/test/coredevice/test_embedding.py | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/artiq/coredevice/comm_kernel.py b/artiq/coredevice/comm_kernel.py index e5340d19c..12e47d938 100644 --- a/artiq/coredevice/comm_kernel.py +++ b/artiq/coredevice/comm_kernel.py @@ -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) diff --git a/artiq/test/coredevice/test_embedding.py b/artiq/test/coredevice/test_embedding.py index 23d74fd7e..275328d02 100644 --- a/artiq/test/coredevice/test_embedding.py +++ b/artiq/test/coredevice/test_embedding.py @@ -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"]))