From 632c5bc937463249d929c98ea69c73a1a67a7c7f Mon Sep 17 00:00:00 2001 From: David Nadlinger Date: Sat, 25 Jul 2020 22:58:42 +0100 Subject: [PATCH] compiler: Add ndarray .shape access --- artiq/compiler/transforms/llvm_ir_generator.py | 2 +- artiq/test/lit/integration/array.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/artiq/compiler/transforms/llvm_ir_generator.py b/artiq/compiler/transforms/llvm_ir_generator.py index 0ed3581fc..a8b85493d 100644 --- a/artiq/compiler/transforms/llvm_ir_generator.py +++ b/artiq/compiler/transforms/llvm_ir_generator.py @@ -881,7 +881,7 @@ class LLVMIRGenerator: if types.is_tuple(typ): return self.llbuilder.extract_value(self.map(insn.object()), attr, 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()), self.attr_index(typ, attr), name=insn.name) diff --git a/artiq/test/lit/integration/array.py b/artiq/test/lit/integration/array.py index d8e8ab15c..3aa090603 100644 --- a/artiq/test/lit/integration/array.py +++ b/artiq/test/lit/integration/array.py @@ -3,6 +3,7 @@ ary = array([1, 2, 3]) assert len(ary) == 3 +assert ary.shape == [3] # FIXME: Implement ndarray indexing # 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([]) assert len(empty_array) == 0 +assert empty_array.shape == [0] matrix = array([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]) assert len(matrix) == 2 +assert matrix.shape == [2, 3]