forked from M-Labs/artiq
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)
|
return get_outer(self.map(env), env.type)
|
||||||
elif insn.op == "len":
|
elif insn.op == "len":
|
||||||
collection, = insn.operands
|
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)
|
return self.llbuilder.extract_value(self.map(collection), 1)
|
||||||
elif insn.op in ("printf", "rtio_log"):
|
elif insn.op in ("printf", "rtio_log"):
|
||||||
# We only get integers, floats, pointers and strings here.
|
# We only get integers, floats, pointers and strings here.
|
||||||
|
@ -2,7 +2,9 @@
|
|||||||
# REQUIRES: exceptions
|
# REQUIRES: exceptions
|
||||||
|
|
||||||
ary = array([1, 2, 3])
|
ary = array([1, 2, 3])
|
||||||
|
assert len(ary) == 3
|
||||||
# FIXME: Implement ndarray indexing
|
# FIXME: Implement ndarray indexing
|
||||||
# assert [x*x for x in ary] == [1, 4, 9]
|
# assert [x*x for x in ary] == [1, 4, 9]
|
||||||
|
|
||||||
matrix = array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
|
matrix = array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
|
||||||
|
assert len(matrix) == 2
|
||||||
|
Loading…
Reference in New Issue
Block a user