From 6b5c390d48c0238e19eb8d019a0dd33bd921e4d8 Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Thu, 21 Apr 2022 23:43:20 +0100 Subject: [PATCH] compiler: Fix #1871 (array() breaks math functions) GitHub: Fixes #1871. --- artiq/compiler/builtins.py | 4 +++- artiq/test/coredevice/test_embedding.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/artiq/compiler/builtins.py b/artiq/compiler/builtins.py index 4524d87dd..fdd5286e1 100644 --- a/artiq/compiler/builtins.py +++ b/artiq/compiler/builtins.py @@ -174,7 +174,9 @@ def fn_list(): return types.TConstructor(TList()) def fn_array(): - return types.TConstructor(TArray()) + # numpy.array() is actually a "magic" macro that is expanded in-place, but + # just as for builtin functions, we do not want to quote it, etc. + return types.TBuiltinFunction("array") def fn_Exception(): return types.TExceptionConstructor(TException("Exception")) diff --git a/artiq/test/coredevice/test_embedding.py b/artiq/test/coredevice/test_embedding.py index 4e86e9aa5..3f2ca96c9 100644 --- a/artiq/test/coredevice/test_embedding.py +++ b/artiq/test/coredevice/test_embedding.py @@ -538,3 +538,19 @@ class _Alignment(EnvExperiment): class AlignmentTest(ExperimentCase): def test_tuple(self): self.create(_Alignment).run() + + +class _NumpyQuoting(EnvExperiment): + def build(self): + self.setattr_device("core") + + @kernel + def run(self): + a = np.array([10, 20]) + b = np.sqrt(4.0) + + +class NumpyQuotingTest(ExperimentCase): + def test_issue_1871(self): + """Ensure numpy.array() does not break NumPy math functions""" + self.create(_NumpyQuoting).run()