forked from M-Labs/artiq
1
0
Fork 0

compiler: Unbreak quoting of 1D ndarrays

Lists and arrays no longer have the same representation all
the way through codegen, as used to be the case.

This could/should be made more efficient later, eliding the
temporary copies.
This commit is contained in:
David Nadlinger 2020-08-08 19:57:46 +01:00
parent df8f1c5c5a
commit 1c645d8857
2 changed files with 36 additions and 11 deletions

View File

@ -233,17 +233,7 @@ class ASTSynthesizer:
begin_loc=begin_loc, end_loc=end_loc,
loc=begin_loc.join(end_loc))
elif isinstance(value, numpy.ndarray):
begin_loc = self._add("numpy.array([")
elts = []
for index, elt in enumerate(value):
elts.append(self.quote(elt))
if index < len(value) - 1:
self._add(", ")
end_loc = self._add("])")
return asttyped.ListT(elts=elts, ctx=None, type=builtins.TArray(),
begin_loc=begin_loc, end_loc=end_loc,
loc=begin_loc.join(end_loc))
return self.call(numpy.array, [list(value)], {})
elif inspect.isfunction(value) or inspect.ismethod(value) or \
isinstance(value, pytypes.BuiltinFunctionType) or \
isinstance(value, SpecializedFunction) or \

View File

@ -0,0 +1,35 @@
# RUN: %python -m artiq.compiler.testbench.embedding %s
from artiq.language.core import *
from artiq.language.types import *
from numpy import array
int_vec = array([1, 2, 3])
float_vec = array([1.0, 2.0, 3.0])
int_mat = array([[1, 2], [3, 4]])
float_mat = array([[1.0, 2.0], [3.0, 4.0]])
@kernel
def entrypoint():
assert int_vec.shape == (3, )
assert int_vec[0] == 1
assert int_vec[1] == 2
assert int_vec[2] == 3
assert float_vec.shape == (3, )
assert float_vec[0] == 1.0
assert float_vec[1] == 2.0
assert float_vec[2] == 3.0
# assert int_mat.shape == (2, 2)
# assert int_mat[0][0] == 1
# assert int_mat[0][1] == 2
# assert int_mat[1][0] == 3
# assert int_mat[1][1] == 4
# assert float_mat.shape == (2, 2)
# assert float_mat[0][0] == 1.0
# assert float_mat[0][1] == 2.0
# assert float_mat[1][0] == 3.0
# assert float_mat[1][1] == 4.0