mirror of https://github.com/m-labs/artiq.git
compiler: Implement len() for ndarrays
This commit is contained in:
parent
575be2aeca
commit
d882f8a3f0
|
@ -1170,6 +1170,10 @@ class LLVMIRGenerator:
|
|||
return get_outer(self.map(env), env.type)
|
||||
elif insn.op == "len":
|
||||
collection, = insn.operands
|
||||
if builtins.is_array(collection.type):
|
||||
# Return length of outermost dimension.
|
||||
shape = self.llbuilder.extract_value(self.map(collection), 0)
|
||||
return self.llbuilder.load(self.llbuilder.extract_value(shape, 0))
|
||||
return self.llbuilder.extract_value(self.map(collection), 1)
|
||||
elif insn.op in ("printf", "rtio_log"):
|
||||
# We only get integers, floats, pointers and strings here.
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
# REQUIRES: exceptions
|
||||
|
||||
ary = array([1, 2, 3])
|
||||
assert len(ary) == 3
|
||||
# FIXME: Implement ndarray indexing
|
||||
# assert [x*x for x in ary] == [1, 4, 9]
|
||||
|
||||
matrix = array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
|
||||
assert len(matrix) == 2
|
||||
|
|
Loading…
Reference in New Issue