compiler: Add ndarray .shape access

This commit is contained in:
David Nadlinger 2020-07-25 22:58:42 +01:00
parent 40f59561f2
commit 632c5bc937
2 changed files with 4 additions and 1 deletions

View File

@ -881,7 +881,7 @@ class LLVMIRGenerator:
if types.is_tuple(typ): if types.is_tuple(typ):
return self.llbuilder.extract_value(self.map(insn.object()), attr, return self.llbuilder.extract_value(self.map(insn.object()), attr,
name=insn.name) name=insn.name)
elif not builtins.is_allocated(typ): elif builtins.is_array(typ) or not builtins.is_allocated(typ):
return self.llbuilder.extract_value(self.map(insn.object()), return self.llbuilder.extract_value(self.map(insn.object()),
self.attr_index(typ, attr), self.attr_index(typ, attr),
name=insn.name) name=insn.name)

View File

@ -3,6 +3,7 @@
ary = array([1, 2, 3]) ary = array([1, 2, 3])
assert len(ary) == 3 assert len(ary) == 3
assert ary.shape == [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]
@ -10,6 +11,8 @@ assert len(ary) == 3
empty_array = array([1]) empty_array = array([1])
empty_array = array([]) empty_array = array([])
assert len(empty_array) == 0 assert len(empty_array) == 0
assert empty_array.shape == [0]
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 assert len(matrix) == 2
assert matrix.shape == [2, 3]