From 9b99b13ff408c8caac3fc2c437fb73d97b14c607 Mon Sep 17 00:00:00 2001 From: Shaikh Ubaid Date: Thu, 24 Aug 2023 09:28:37 +0530 Subject: [PATCH 01/18] ASR: Process shape and dtype in empty() --- src/lpython/semantics/python_ast_to_asr.cpp | 38 +++++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index cc8137cb23..d64f1b92a9 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -7510,9 +7510,41 @@ class BodyVisitor : public CommonVisitor { tmp = ASRUtils::make_ArraySize_t_util(al, loc, var, dim, int_type, nullptr); return; } else if (call_name == "empty") { - // TODO: check that the `empty` arguments are compatible - // with the type - tmp = nullptr; + if (x.n_args != 1 || x.n_keywords != 1) { + throw SemanticError("empty() expects 1 positional argument for shape" + " and 1 keyword argument for 'dtype'", + x.base.base.loc); + } + + ASR::ttype_t* type = nullptr; + Vec dims; + dims.reserve(al, 0); + + visit_expr(*x.m_args[0]); + ASR::expr_t* shape = ASRUtils::EXPR(tmp); + fill_dims_for_asr_type(dims, shape, shape->base.loc); + + std::string keyword_arg = x.m_keywords[0].m_arg; + if (keyword_arg != "dtype") { + throw SemanticError("Unexpected keyword argument '" + keyword_arg + "', expected 'dtype'", + x.m_keywords[0].loc); + } + + std::string dtype_np = ""; + if( AST::is_a(*x.m_keywords[0].m_value) ) { + AST::Name_t* name_t = AST::down_cast(x.m_keywords[0].m_value); + dtype_np = name_t->m_id; + } else { + LCOMPILERS_ASSERT(false); + } + LCOMPILERS_ASSERT(numpy2lpythontypes.find(dtype_np) != numpy2lpythontypes.end()); + type = get_type_from_var_annotation( + numpy2lpythontypes[dtype_np], x.base.base.loc, dims); + + Vec arr_args; + arr_args.reserve(al, 0); + tmp = ASRUtils::make_ArrayConstant_t_util(al, x.base.base.loc, + arr_args.p, arr_args.size(), type, ASR::arraystorageType::RowMajor); return; } else if (call_name == "c_p_pointer") { tmp = create_CPtrToPointer(x); From 5eab8a7e881dc119fea5d25ff64243775bee8511 Mon Sep 17 00:00:00 2001 From: Shaikh Ubaid Date: Thu, 24 Aug 2023 17:33:26 +0530 Subject: [PATCH 02/18] ASR: Support ListConstant in fill_dims_for_asr_type() --- src/lpython/semantics/python_ast_to_asr.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index d64f1b92a9..4eaab3ade4 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -1645,6 +1645,12 @@ class CommonVisitor : public AST::BaseVisitor { ASR::expr_t *value = tuple_constant->m_elements[i]; fill_dims_for_asr_type(dims, value, loc); } + } else if(ASR::is_a(*value)) { + ASR::ListConstant_t* list_constant = ASR::down_cast(value); + for( size_t i = 0; i < list_constant->n_args; i++ ) { + ASR::expr_t *value = list_constant->m_args[i]; + fill_dims_for_asr_type(dims, value, loc); + } } else if(ASR::is_a(*value)) { ASR::expr_t* enum_value = ASRUtils::expr_value( ASR::down_cast(value)->m_value); From fd78f277663e5e309605785a52e55d9d36b53807 Mon Sep 17 00:00:00 2001 From: Shaikh Ubaid Date: Thu, 24 Aug 2023 19:51:45 +0530 Subject: [PATCH 03/18] ASR: Check for dims as well when comparing types --- src/lpython/semantics/python_ast_to_asr.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index 4eaab3ade4..cea2a7a31b 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -3051,7 +3051,7 @@ class CommonVisitor : public AST::BaseVisitor { underlying_type = ASRUtils::get_contained_type(type); } cast_helper(underlying_type, value, value->base.loc); - if (!ASRUtils::check_equal_type(underlying_type, ASRUtils::expr_type(value))) { + if (!ASRUtils::check_equal_type(underlying_type, ASRUtils::expr_type(value), true)) { std::string ltype = ASRUtils::type_to_str_python(underlying_type); std::string rtype = ASRUtils::type_to_str_python(ASRUtils::expr_type(value)); diag.add(diag::Diagnostic( From a053339a1a5fa45e61dd70caf52bf4e98759d703 Mon Sep 17 00:00:00 2001 From: Shaikh Ubaid Date: Thu, 24 Aug 2023 19:52:35 +0530 Subject: [PATCH 04/18] ASRUtils: Simple and (hopefully) robust dims comparison --- src/libasr/asr_utils.h | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/libasr/asr_utils.h b/src/libasr/asr_utils.h index 86a2ee5d26..4ba68ee64c 100644 --- a/src/libasr/asr_utils.h +++ b/src/libasr/asr_utils.h @@ -2430,21 +2430,13 @@ inline bool dimension_expr_equal(ASR::expr_t* dim_a, ASR::expr_t* dim_b) { if( !(dim_a && dim_b) ) { return true; } - ASR::expr_t* dim_a_fallback = nullptr; - ASR::expr_t* dim_b_fallback = nullptr; - if( ASR::is_a(*dim_a) && - ASR::is_a( - *ASR::down_cast(dim_a)->m_v) ) { - dim_a_fallback = ASRUtils::EXPR2VAR(dim_a)->m_symbolic_value; - } - if( ASR::is_a(*dim_b) && - ASR::is_a( - *ASR::down_cast(dim_b)->m_v) ) { - dim_b_fallback = ASRUtils::EXPR2VAR(dim_b)->m_symbolic_value; - } - if( !ASRUtils::expr_equal(dim_a, dim_b) && - !(dim_a_fallback && ASRUtils::expr_equal(dim_a_fallback, dim_b)) && - !(dim_b_fallback && ASRUtils::expr_equal(dim_a, dim_b_fallback)) ) { + int dim_a_int, dim_b_int; + if (ASRUtils::extract_value(ASRUtils::expr_value(dim_a), dim_a_int) + && ASRUtils::extract_value(ASRUtils::expr_value(dim_b), dim_b_int)) { + return dim_a_int == dim_b_int; + } + + if( !ASRUtils::expr_equal(dim_a, dim_b) ) { return false; } return true; From f0b6ee1049ac10bb161f8477d971b416c9e24e24 Mon Sep 17 00:00:00 2001 From: Shaikh Ubaid Date: Thu, 24 Aug 2023 19:53:33 +0530 Subject: [PATCH 05/18] ASRUtils: Support constructing string for multi-dims --- src/libasr/asr_utils.h | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/src/libasr/asr_utils.h b/src/libasr/asr_utils.h index 4ba68ee64c..d92c8349bf 100644 --- a/src/libasr/asr_utils.h +++ b/src/libasr/asr_utils.h @@ -1070,20 +1070,28 @@ static inline bool extract_value(ASR::expr_t* value_expr, T& value) { return true; } -static inline std::string type_python_1dim_helper(const std::string & res, - const ASR::dimension_t* e ) -{ - if( !e->m_length && !e->m_start ) { - return res + "[:]"; +static inline std::string extract_dim_value(ASR::expr_t* dim) { + int64_t length_dim = 0; + if( dim == nullptr || + !ASRUtils::extract_value(ASRUtils::expr_value(dim), length_dim)) { + return ":"; } - if( ASRUtils::expr_value(e->m_length) ) { - int64_t length_dim = 0; - ASRUtils::extract_value(ASRUtils::expr_value(e->m_length), length_dim); - return res + "[" + std::to_string(length_dim) + "]"; - } + return std::to_string(length_dim); +} - return res; +static inline std::string type_encode_dims(size_t n_dims, ASR::dimension_t* m_dims ) +{ + std::string dims_str = ""; + for( size_t i = 0; i < n_dims; i++ ) { + ASR::dimension_t dim = m_dims[i]; + dims_str += "["; + dims_str += extract_dim_value(dim.m_start); + dims_str += ","; + dims_str += extract_dim_value(dim.m_length); + dims_str += "]"; + } + return dims_str; } static inline std::string get_type_code(const ASR::ttype_t *t, bool use_underscore_sep=false, @@ -1261,9 +1269,8 @@ static inline std::string type_to_str_python(const ASR::ttype_t *t, case ASR::ttypeType::Array: { ASR::Array_t* array_t = ASR::down_cast(t); std::string res = type_to_str_python(array_t->m_type, for_error_message); - if (array_t->n_dims == 1 && for_error_message) { - res = type_python_1dim_helper(res, array_t->m_dims); - } + std::string dim_info = type_encode_dims(array_t->n_dims, array_t->m_dims); + res += dim_info; return res; } case ASR::ttypeType::Integer: { From 455de7ee6027ea21b22c66b466d6460e66d8e42f Mon Sep 17 00:00:00 2001 From: Shaikh Ubaid Date: Thu, 24 Aug 2023 21:04:03 +0530 Subject: [PATCH 06/18] ASR: Support struct types in empty() --- src/lpython/semantics/python_ast_to_asr.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index cea2a7a31b..af3828ca7c 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -7543,10 +7543,12 @@ class BodyVisitor : public CommonVisitor { } else { LCOMPILERS_ASSERT(false); } - LCOMPILERS_ASSERT(numpy2lpythontypes.find(dtype_np) != numpy2lpythontypes.end()); - type = get_type_from_var_annotation( - numpy2lpythontypes[dtype_np], x.base.base.loc, dims); + if (numpy2lpythontypes.find(dtype_np) != numpy2lpythontypes.end()) { + dtype_np = numpy2lpythontypes[dtype_np]; + } + + type = get_type_from_var_annotation(dtype_np, x.m_keywords[0].m_value->base.loc, dims); Vec arr_args; arr_args.reserve(al, 0); tmp = ASRUtils::make_ArrayConstant_t_util(al, x.base.base.loc, From b36a37daf825fb4f874d2c2bbb70ba427d46e200 Mon Sep 17 00:00:00 2001 From: Shaikh Ubaid Date: Thu, 24 Aug 2023 21:05:05 +0530 Subject: [PATCH 07/18] PASS: Support extracting arr size from ttype_t in implied_do_loops --- src/libasr/pass/implied_do_loops.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libasr/pass/implied_do_loops.cpp b/src/libasr/pass/implied_do_loops.cpp index 0ee132d16f..1b297c83ac 100644 --- a/src/libasr/pass/implied_do_loops.cpp +++ b/src/libasr/pass/implied_do_loops.cpp @@ -86,7 +86,7 @@ class ReplaceArrayConstant: public ASR::BaseExprReplacer { ASR::expr_t* get_ArrayConstant_size(ASR::ArrayConstant_t* x, bool& is_allocatable) { ASR::ttype_t* int_type = ASRUtils::TYPE(ASR::make_Integer_t(al, x->base.base.loc, 4)); ASR::expr_t* array_size = nullptr; - size_t constant_size = 0; + int64_t constant_size = 0; const Location& loc = x->base.base.loc; ASRUtils::ASRBuilder builder(al, loc); for( size_t i = 0; i < x->n_args; i++ ) { @@ -162,7 +162,10 @@ class ReplaceArrayConstant: public ASR::BaseExprReplacer { } } ASR::expr_t* constant_size_asr = nullptr; - if( constant_size != 0 ) { + if (constant_size == 0) { + constant_size = ASRUtils::get_fixed_size_of_array(x->m_type); + } + if( constant_size > 0 ) { constant_size_asr = make_ConstantWithType(make_IntegerConstant_t, constant_size, int_type, x->base.base.loc); if( array_size == nullptr ) { From eaec0acf0d93b1d8320c8be8fb374726bbfa13da Mon Sep 17 00:00:00 2001 From: Shaikh Ubaid Date: Thu, 24 Aug 2023 22:01:09 +0530 Subject: [PATCH 08/18] ASR: Support TypeParameter in numpy2lpythontypes --- src/lpython/semantics/python_ast_to_asr.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index af3828ca7c..ef8d7a0b29 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -525,6 +525,7 @@ class CommonVisitor : public AST::BaseVisitor { {"complex64", "c32"}, {"complex128", "c64"}, {"complex_", "c64"}, + {"object", "T"} }; CommonVisitor(Allocator &al, LocationManager &lm, SymbolTable *symbol_table, From 26a5b35bdb302ddc9e3a8a5b71a3ffedc0f6c811 Mon Sep 17 00:00:00 2001 From: Shaikh Ubaid Date: Thu, 24 Aug 2023 21:45:12 +0530 Subject: [PATCH 09/18] ASRUtils: Support TypeParameter in types_equal() --- src/libasr/asr_utils.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/libasr/asr_utils.h b/src/libasr/asr_utils.h index d92c8349bf..b72c0e23c3 100644 --- a/src/libasr/asr_utils.h +++ b/src/libasr/asr_utils.h @@ -2492,6 +2492,13 @@ inline bool types_equal(ASR::ttype_t *a, ASR::ttype_t *b, a2->m_dims, a2->n_dims, b2->m_dims, b2->n_dims); } + case (ASR::ttypeType::TypeParameter) : { + ASR::TypeParameter_t* left_tp = ASR::down_cast(a); + ASR::TypeParameter_t* right_tp = ASR::down_cast(b); + std::string left_param = left_tp->m_param; + std::string right_param = right_tp->m_param; + return left_param == right_param; + } case (ASR::ttypeType::Integer) : { ASR::Integer_t *a2 = ASR::down_cast(a); ASR::Integer_t *b2 = ASR::down_cast(b); From 5171314e1a69c4e50a4229314f28a05424a167e6 Mon Sep 17 00:00:00 2001 From: Shaikh Ubaid Date: Mon, 28 Aug 2023 03:36:04 +0530 Subject: [PATCH 10/18] ASR: Support runtime dimensions for allocatable targets --- src/lpython/semantics/python_ast_to_asr.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index ef8d7a0b29..2627d7ae72 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -1615,7 +1615,8 @@ class CommonVisitor : public AST::BaseVisitor { } void fill_dims_for_asr_type(Vec& dims, - ASR::expr_t* value, const Location& loc) { + ASR::expr_t* value, const Location& loc, + bool is_allocatable=false) { ASR::dimension_t dim; dim.loc = loc; if (ASR::is_a(*value) || @@ -1627,7 +1628,7 @@ class CommonVisitor : public AST::BaseVisitor { ASR::expr_t* comptime_val = nullptr; int64_t value_int = -1; if( !ASRUtils::extract_value(ASRUtils::expr_value(value), value_int) && - contains_local_variable(value) ) { + contains_local_variable(value) && !is_allocatable) { throw SemanticError("Only those local variables which can be reduced to compile " "time constant should be used in dimensions of an array.", value->base.loc); @@ -1644,13 +1645,13 @@ class CommonVisitor : public AST::BaseVisitor { ASR::TupleConstant_t* tuple_constant = ASR::down_cast(value); for( size_t i = 0; i < tuple_constant->n_elements; i++ ) { ASR::expr_t *value = tuple_constant->m_elements[i]; - fill_dims_for_asr_type(dims, value, loc); + fill_dims_for_asr_type(dims, value, loc, is_allocatable); } } else if(ASR::is_a(*value)) { ASR::ListConstant_t* list_constant = ASR::down_cast(value); for( size_t i = 0; i < list_constant->n_args; i++ ) { ASR::expr_t *value = list_constant->m_args[i]; - fill_dims_for_asr_type(dims, value, loc); + fill_dims_for_asr_type(dims, value, loc, is_allocatable); } } else if(ASR::is_a(*value)) { ASR::expr_t* enum_value = ASRUtils::expr_value( @@ -1659,7 +1660,7 @@ class CommonVisitor : public AST::BaseVisitor { throw SemanticError("Only constant enumeration values are " "supported as array dimensions.", loc); } - fill_dims_for_asr_type(dims, enum_value, loc); + fill_dims_for_asr_type(dims, enum_value, loc, is_allocatable); } else { throw SemanticError("Only Integer, `:` or identifier in [] in " "Subscript supported for now in annotation " @@ -7524,12 +7525,13 @@ class BodyVisitor : public CommonVisitor { } ASR::ttype_t* type = nullptr; + bool is_allocatable = ASRUtils::is_allocatable(assign_asr_target); Vec dims; dims.reserve(al, 0); visit_expr(*x.m_args[0]); ASR::expr_t* shape = ASRUtils::EXPR(tmp); - fill_dims_for_asr_type(dims, shape, shape->base.loc); + fill_dims_for_asr_type(dims, shape, shape->base.loc, is_allocatable); std::string keyword_arg = x.m_keywords[0].m_arg; if (keyword_arg != "dtype") { From c59961b8843519eca169846ad980dd40c9ec73a2 Mon Sep 17 00:00:00 2001 From: Shaikh Ubaid Date: Mon, 28 Aug 2023 05:29:12 +0530 Subject: [PATCH 11/18] ASR: Merge assign_ast_target, ann_assign_target_type to assign_asr_target --- src/lpython/semantics/python_ast_to_asr.cpp | 51 ++++++++++----------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index 2627d7ae72..66015f1bcd 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -496,8 +496,7 @@ class CommonVisitor : public AST::BaseVisitor { current_body does not exist for Modules, ClassDef/Structs. */ Vec *current_body; - ASR::ttype_t* ann_assign_target_type; - AST::expr_t* assign_ast_target; + ASR::expr_t* assign_asr_target; std::map generic_func_nums; std::map> generic_func_subs; @@ -534,8 +533,7 @@ class CommonVisitor : public AST::BaseVisitor { std::vector import_paths, bool allow_implicit_casting_) : diag{diagnostics}, al{al}, lm{lm}, current_scope{symbol_table}, main_module{main_module}, module_name{module_name}, ast_overload{ast_overload}, parent_dir{parent_dir}, import_paths{import_paths}, - current_body{nullptr}, ann_assign_target_type{nullptr}, - assign_ast_target{nullptr}, allow_implicit_casting{allow_implicit_casting_} { + current_body{nullptr}, assign_asr_target{nullptr}, allow_implicit_casting{allow_implicit_casting_} { current_module_dependencies.reserve(al, 4); global_init.reserve(al, 1); } @@ -1177,8 +1175,9 @@ class CommonVisitor : public AST::BaseVisitor { } if (call_name == "list" && (args.size() == 0 || args[0].m_value == nullptr)) { - if (ann_assign_target_type) { - ASR::ttype_t *type = ASRUtils::get_contained_type(ann_assign_target_type); + if (assign_asr_target) { + ASR::ttype_t *type = ASRUtils::get_contained_type( + ASRUtils::type_get_past_const(ASRUtils::expr_type(assign_asr_target))); ASR::ttype_t* list_type = ASRUtils::TYPE(ASR::make_List_t(al, loc, type)); Vec list; list.reserve(al, 1); @@ -2821,8 +2820,7 @@ class CommonVisitor : public AST::BaseVisitor { } this->visit_expr(*x.m_args[0]); ASR::expr_t* cptr = ASRUtils::EXPR(tmp); - this->visit_expr(*assign_ast_target); - ASR::expr_t* pptr = ASRUtils::EXPR(tmp); + ASR::expr_t* pptr = assign_asr_target; ASR::expr_t* target_shape = nullptr; if( x.n_args == 3 ) { this->visit_expr(*x.m_args[2]); @@ -3020,8 +3018,6 @@ class CommonVisitor : public AST::BaseVisitor { handle_lambda_function_declaration(var_name, fn_type, x.m_value, x.base.base.loc); return; } - ASR::ttype_t* ann_assign_target_type_copy = ann_assign_target_type; - ann_assign_target_type = type; if( ASR::is_a(*type) && wrap_derived_type_in_pointer ) { type = ASRUtils::TYPE(ASR::make_Pointer_t(al, type->base.loc, type)); @@ -3035,6 +3031,10 @@ class CommonVisitor : public AST::BaseVisitor { create_add_variable_to_scope(var_name, type, x.base.base.loc, abi, storage_type); + ASR::expr_t* assign_asr_target_copy = assign_asr_target; + this->visit_expr(*x.m_target); + assign_asr_target = ASRUtils::EXPR(tmp); + if( !init_expr ) { tmp = nullptr; if (x.m_value) { @@ -3086,7 +3086,7 @@ class CommonVisitor : public AST::BaseVisitor { ASR::is_a(*ASR::down_cast(tmp))) ) { tmp = nullptr; } - ann_assign_target_type = ann_assign_target_type_copy; + assign_asr_target = assign_asr_target_copy; } void visit_ClassMembers(const AST::ClassDef_t& x, @@ -5063,8 +5063,6 @@ class BodyVisitor : public CommonVisitor { // We treat this as a declaration std::string var_name; std::string var_annotation; - AST::expr_t* assign_ast_target_copy = assign_ast_target; - assign_ast_target = x.m_target; if (AST::is_a(*x.m_target)) { AST::Name_t *n = AST::down_cast(x.m_target); var_name = n->m_id; @@ -5085,7 +5083,6 @@ class BodyVisitor : public CommonVisitor { } ASR::expr_t *init_expr = nullptr; visit_AnnAssignUtil(x, var_name, init_expr); - assign_ast_target = assign_ast_target_copy; } void visit_Delete(const AST::Delete_t &x) { @@ -5250,10 +5247,11 @@ class BodyVisitor : public CommonVisitor { void visit_Assign(const AST::Assign_t &x) { ASR::expr_t *target, *assign_value = nullptr, *tmp_value; - AST::expr_t* assign_ast_target_copy = assign_ast_target; - assign_ast_target = x.m_targets[0]; + ASR::expr_t* assign_asr_target_copy = assign_asr_target; + this->visit_expr(*x.m_targets[0]); + assign_asr_target = ASRUtils::EXPR(tmp); this->visit_expr(*x.m_value); - assign_ast_target = assign_ast_target_copy; + assign_asr_target = assign_asr_target_copy; if (tmp) { if (ASR::is_a(*tmp)) { // This happens for c_p_pointer() @@ -5406,11 +5404,12 @@ class BodyVisitor : public CommonVisitor { list.push_back(al, expr); } } else { - if( ann_assign_target_type == nullptr ) { + if( assign_asr_target == nullptr ) { tmp = nullptr; return ; } - type = ASRUtils::get_contained_type(ann_assign_target_type); + type = ASRUtils::get_contained_type( + ASRUtils::type_get_past_const(ASRUtils::expr_type(assign_asr_target))); } ASR::ttype_t* list_type = ASRUtils::TYPE(ASR::make_List_t(al, x.base.base.loc, type)); tmp = ASR::make_ListConstant_t(al, x.base.base.loc, list.p, @@ -6190,9 +6189,9 @@ class BodyVisitor : public CommonVisitor { void visit_Dict(const AST::Dict_t &x) { LCOMPILERS_ASSERT(x.n_keys == x.n_values); if( x.n_keys == 0 ) { - if( ann_assign_target_type != nullptr ) { + if( assign_asr_target != nullptr ) { tmp = ASR::make_DictConstant_t(al, x.base.base.loc, nullptr, 0, - nullptr, 0, ann_assign_target_type); + nullptr, 0, ASRUtils::expr_type(assign_asr_target)); } else { tmp = nullptr; @@ -6584,10 +6583,10 @@ class BodyVisitor : public CommonVisitor { if( ASR::is_a(*target_type) ) { target_type = ASRUtils::get_contained_type(target_type); } - ASR::ttype_t* ann_assign_target_type_copy = ann_assign_target_type; - ann_assign_target_type = target_type; + ASR::expr_t* assign_asr_target_copy = assign_asr_target; + assign_asr_target = target; this->visit_expr(*x.m_value); - ann_assign_target_type = ann_assign_target_type_copy; + assign_asr_target = assign_asr_target_copy; ASR::expr_t *value = ASRUtils::EXPR(tmp); ASR::ttype_t *value_type = ASRUtils::expr_type(value); if( ASR::is_a(*value_type) ) { @@ -7567,8 +7566,8 @@ class BodyVisitor : public CommonVisitor { // TODO: check that `empty_c_void_p uses` has arguments that are compatible // with the type ASR::ttype_t* type; - if (ann_assign_target_type) { - type = ann_assign_target_type; + if (assign_asr_target) { + type = ASRUtils::expr_type(assign_asr_target); } else { type = ASRUtils::TYPE(ASR::make_CPtr_t(al, x.base.base.loc)); } From ca516bc9ce0aeaf822ef4f8ad3d3c9a2e0510c63 Mon Sep 17 00:00:00 2001 From: Shaikh Ubaid Date: Mon, 28 Aug 2023 05:37:09 +0530 Subject: [PATCH 12/18] ASR: Support Allocate statement using empty() We handle Allocatable statement with empty() in visit_Call(). This removes the need of check_to_allocate_array() and extra checking needed for it in visit_AnnAssignUtil(), visit_Assign(). Thus, making code clean. --- src/lpython/semantics/python_ast_to_asr.cpp | 101 +++++--------------- 1 file changed, 25 insertions(+), 76 deletions(-) diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index 66015f1bcd..6223cf774c 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -2866,56 +2866,6 @@ class CommonVisitor : public AST::BaseVisitor { pptr, target_shape, lower_bounds); } - ASR::asr_t* check_to_allocate_array(AST::expr_t *value, std::string var_name, - const Location &loc) { - if (AST::is_a(*value)) { - AST::Call_t *ct = AST::down_cast(value); - if (AST::is_a(*ct->m_func)) { - std::string call_name = AST::down_cast(ct->m_func)->m_id; - if (call_name == "empty") { - LCOMPILERS_ASSERT(ct->n_args > 0); - if (AST::is_a(*ct->m_args[0])) { - AST::Tuple_t *tt = AST::down_cast(ct->m_args[0]); - Vec alloc_args_vec; - alloc_args_vec.reserve(al, 1); - ASR::alloc_arg_t new_arg; - new_arg.loc = loc; - new_arg.m_len_expr = nullptr; - new_arg.m_type = nullptr; - ASR::ttype_t *int32_type = ASRUtils::TYPE(ASR::make_Integer_t(al, loc, 4)); - ASR::expr_t* const_0 = ASRUtils::EXPR(ASR::make_IntegerConstant_t(al, - loc, 0, int32_type)); - Vec dims_vec; - dims_vec.reserve(al, tt->n_elts); - for (size_t i=0; in_elts; i++) { - ASR::dimension_t new_dim; - new_dim.loc = loc; - this->visit_expr(*tt->m_elts[0]); - new_dim.m_start = const_0; - new_dim.m_length = ASRUtils::EXPR(tmp); - dims_vec.push_back(al, new_dim); - } - new_arg.m_dims = dims_vec.p; - new_arg.n_dims = dims_vec.size(); - ASR::symbol_t *v_sym = current_scope->resolve_symbol(var_name); - ASR::expr_t* v_expr = ASRUtils::EXPR(ASR::make_Var_t(al, - loc, v_sym)); - new_arg.m_a = v_expr; - alloc_args_vec.push_back(al, new_arg); - tmp = ASR::make_Allocate_t(al, loc, - alloc_args_vec.p, alloc_args_vec.size(), - nullptr, nullptr, nullptr); - return tmp; - } else { - throw SemanticError("Only tuple argument is accepted as dimensions " - "for allocating using empty()", ct->base.base.loc); - } - } - } - } - return nullptr; - } - void handle_lambda_function_declaration(std::string &var_name, ASR::FunctionType_t* fn_type, AST::expr_t* value, const Location &loc) { if (value == nullptr) { throw SemanticError("Callback functions must have a value", loc); @@ -3075,15 +3025,9 @@ class CommonVisitor : public AST::BaseVisitor { process_variable_init_val(current_scope->get_symbol(var_name), x.base.base.loc, init_expr); } - if (is_allocatable && x.m_value && AST::is_a(*x.m_value)) { - tmp = check_to_allocate_array(x.m_value, var_name, x.base.base.loc); - if( current_body && tmp) { - current_body->push_back(al, ASRUtils::STMT(tmp)); - } - } - if ( !(tmp && ASR::is_a(*tmp) && - ASR::is_a(*ASR::down_cast(tmp))) ) { + (ASR::is_a(*ASR::down_cast(tmp)) || + ASR::is_a(*ASR::down_cast(tmp)))) ) { tmp = nullptr; } assign_asr_target = assign_asr_target_copy; @@ -5254,7 +5198,8 @@ class BodyVisitor : public CommonVisitor { assign_asr_target = assign_asr_target_copy; if (tmp) { if (ASR::is_a(*tmp)) { - // This happens for c_p_pointer() + // This happens for c_p_pointer() and + // empty() (if target is of type allocatable) return; } // This happens if `m.m_value` is `empty`, such as in: @@ -5307,19 +5252,6 @@ class BodyVisitor : public CommonVisitor { dict_ele.size(), dict_ele.p, dict_ele.size(), target_type)); } } - if (tmp_value == nullptr && ASR::is_a(*target)) { - ASR::Var_t *var_tar = ASR::down_cast(target); - if (ASR::is_a(*var_tar->m_v)) { - if ( ASR::is_a(*ASR::down_cast(var_tar->m_v)->m_type) ) { - ASR::asr_t *st = check_to_allocate_array(x.m_value, ASRUtils::symbol_name(var_tar->m_v), - x.base.base.loc); - if (st) { - tmp_vec.push_back(st); - continue; - } - } - } - } if (!tmp_value) continue; ASR::ttype_t *value_type = ASRUtils::expr_type(tmp_value); if( ASR::is_a(*target_type) && @@ -7551,10 +7483,27 @@ class BodyVisitor : public CommonVisitor { } type = get_type_from_var_annotation(dtype_np, x.m_keywords[0].m_value->base.loc, dims); - Vec arr_args; - arr_args.reserve(al, 0); - tmp = ASRUtils::make_ArrayConstant_t_util(al, x.base.base.loc, - arr_args.p, arr_args.size(), type, ASR::arraystorageType::RowMajor); + if (is_allocatable) { + const Location& loc = x.base.base.loc; + Vec alloc_args_vec; + alloc_args_vec.reserve(al, 1); + ASR::alloc_arg_t new_arg; + new_arg.loc = loc; + new_arg.m_len_expr = nullptr; + new_arg.m_type = nullptr; + new_arg.m_dims = dims.p; + new_arg.n_dims = dims.size(); + new_arg.m_a = assign_asr_target; + alloc_args_vec.push_back(al, new_arg); + tmp = ASR::make_Allocate_t(al, loc, + alloc_args_vec.p, alloc_args_vec.size(), + nullptr, nullptr, nullptr); + } else { + Vec arr_args; + arr_args.reserve(al, 0); + tmp = ASRUtils::make_ArrayConstant_t_util(al, x.base.base.loc, + arr_args.p, arr_args.size(), type, ASR::arraystorageType::RowMajor); + } return; } else if (call_name == "c_p_pointer") { tmp = create_CPtrToPointer(x); From a6741b56bd80a0bcce3c49f38f66ac6c7078df6e Mon Sep 17 00:00:00 2001 From: Shaikh Ubaid Date: Mon, 28 Aug 2023 07:29:32 +0530 Subject: [PATCH 13/18] ASRUtils: Support ListConstant in is_value_constant() --- src/libasr/asr_utils.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/libasr/asr_utils.h b/src/libasr/asr_utils.h index b72c0e23c3..60db756019 100644 --- a/src/libasr/asr_utils.h +++ b/src/libasr/asr_utils.h @@ -813,6 +813,15 @@ static inline bool is_value_constant(ASR::expr_t *a_value) { } } return true; + } else if(ASR::is_a(*a_value)) { + ASR::ListConstant_t* list_constant = ASR::down_cast(a_value); + for( size_t i = 0; i < list_constant->n_args; i++ ) { + if( !ASRUtils::is_value_constant(list_constant->m_args[i]) && + !ASRUtils::is_value_constant(ASRUtils::expr_value(list_constant->m_args[i])) ) { + return false; + } + } + return true; } else if(ASR::is_a(*a_value)) { ASR::FunctionCall_t* func_call_t = ASR::down_cast(a_value); if( !ASRUtils::is_intrinsic_symbol(ASRUtils::symbol_get_past_external(func_call_t->m_name)) ) { From 8d6a57933bb3ee4e936c7e1a25a15388bdcbb70c Mon Sep 17 00:00:00 2001 From: Shaikh Ubaid Date: Thu, 24 Aug 2023 19:54:03 +0530 Subject: [PATCH 14/18] TEST: Fix tests to use dtype in empty() --- integration_tests/array_01.py | 4 +- integration_tests/array_02.py | 4 +- integration_tests/array_02_decl.py | 14 +++---- integration_tests/array_03_decl.py | 4 +- integration_tests/array_expr_01.py | 16 +++---- integration_tests/array_size_01.py | 10 ++--- integration_tests/array_size_02.py | 18 ++++---- integration_tests/bindpy_02.py | 10 ++--- integration_tests/bindpy_04.py | 10 ++--- integration_tests/elemental_01.py | 34 +++++++-------- integration_tests/elemental_02.py | 22 +++++----- integration_tests/elemental_03.py | 20 ++++----- integration_tests/elemental_04.py | 12 +++--- integration_tests/elemental_05.py | 22 +++++----- integration_tests/elemental_06.py | 58 +++++++++++++------------- integration_tests/elemental_07.py | 10 ++--- integration_tests/elemental_08.py | 10 ++--- integration_tests/elemental_09.py | 20 ++++----- integration_tests/elemental_11.py | 12 +++--- integration_tests/elemental_12.py | 30 ++++++------- integration_tests/expr_06.py | 4 +- integration_tests/generics_array_01.py | 6 +-- integration_tests/generics_array_02.py | 12 +++--- integration_tests/generics_array_03.py | 12 +++--- integration_tests/test_numpy_01.py | 6 +-- integration_tests/test_numpy_02.py | 8 ++-- integration_tests/test_numpy_03.py | 28 ++++++------- integration_tests/vec_01.py | 6 +-- 28 files changed, 209 insertions(+), 213 deletions(-) diff --git a/integration_tests/array_01.py b/integration_tests/array_01.py index 7549a3975e..c492d6b31c 100644 --- a/integration_tests/array_01.py +++ b/integration_tests/array_01.py @@ -1,9 +1,9 @@ from lpython import i32 -from numpy import empty +from numpy import empty, int32 def main0(): Nx: i32 = 600; Ny: i32 = 450 - arr: i32[450, 600] = empty([Ny, Nx]) + arr: i32[450, 600] = empty([450, 600], dtype=int32) i: i32 j: i32 for i in range(Ny): diff --git a/integration_tests/array_02.py b/integration_tests/array_02.py index cdc2135099..6c9c2ea5c2 100644 --- a/integration_tests/array_02.py +++ b/integration_tests/array_02.py @@ -1,9 +1,9 @@ from lpython import i32 -from numpy import empty +from numpy import empty, int32 def main0(): Nx: i32 = 60; Ny: i32 = 45; Nz: i32 = 20 - arr: i32[45, 60, 20] = empty([Ny, Nx, Nz]) + arr: i32[45, 60, 20] = empty([45, 60, 20], dtype=int32) i: i32 j: i32 k: i32 diff --git a/integration_tests/array_02_decl.py b/integration_tests/array_02_decl.py index 78acf1b115..1f5c07d76c 100644 --- a/integration_tests/array_02_decl.py +++ b/integration_tests/array_02_decl.py @@ -1,5 +1,5 @@ from lpython import i32, i64, f32, f64, c32, c64 -from numpy import empty +from numpy import empty, int32, int64, float32, float64, complex64, complex128 def accept_multidim_i32_array(xi32: i32[:, :]) -> i32: return xi32[0, 0] @@ -14,12 +14,12 @@ def accept_multidim_f64_array(xf64: f64[:, :]) -> f64: return xf64[0, 1] def declare_arrays(): - ai32: i32[3, 3] = empty([3, 3]) - ai64: i64[10, 10, 10] = empty([10, 10, 10]) - af32: f32[3] = empty(3) - af64: f64[10, 4] = empty([10, 4]) - ac32: c32[3, 5, 99] = empty([3, 5, 99]) - ac64: c64[10, 13, 11, 16] = empty([10, 13, 11, 16]) + ai32: i32[3, 3] = empty([3, 3], dtype=int32) + ai64: i64[10, 10, 10] = empty([10, 10, 10], dtype=int64) + af32: f32[3] = empty(3, dtype=float32) + af64: f64[10, 4] = empty([10, 4], dtype=float64) + ac32: c32[3, 5, 99] = empty([3, 5, 99], dtype=complex64) + ac64: c64[10, 13, 11, 16] = empty([10, 13, 11, 16], dtype=complex128) print(accept_multidim_i32_array(ai32)) print(accept_multidim_i64_array(ai64)) print(accept_multidim_f32_array(af32)) diff --git a/integration_tests/array_03_decl.py b/integration_tests/array_03_decl.py index e2d0d75581..9fb02782ca 100644 --- a/integration_tests/array_03_decl.py +++ b/integration_tests/array_03_decl.py @@ -12,8 +12,8 @@ class Truck: wheels: i32 def declare_struct_array(): - cars: Car[1] = empty(10, dtype=Car) - trucks: Truck[2] = empty(20, dtype=Truck) + cars: Car[1] = empty(1, dtype=Car) + trucks: Truck[2] = empty(2, dtype=Truck) cars[0] = Car(100000, 800.0) trucks[0] = Truck(1000000, 8) trucks[1] = Truck(5000000, 12) diff --git a/integration_tests/array_expr_01.py b/integration_tests/array_expr_01.py index 97ed54365b..0136710c93 100644 --- a/integration_tests/array_expr_01.py +++ b/integration_tests/array_expr_01.py @@ -1,22 +1,18 @@ -from lpython import i32, f32, f64 +from lpython import Const, i32, f32, f64 from numpy import empty, reshape, int32, float64 def array_expr_01(): - dim1: i32 - dim2: i32 - dim3: i32 - dim1d: i32 + dim1: Const[i32] = 10 + dim2: Const[i32] = 10 + dim3: Const[i32] = 5 + dim1d: Const[i32] = dim1 * dim2 * dim3 + i: i32 shape1d: i32[1] = empty(1, dtype=int32) shape3d: i32[3] = empty(3, dtype=int32) eps: f64 eps = 1e-12 - dim1 = 10 - dim2 = 10 - dim3 = 5 - dim1d = dim1 * dim2 * dim3 - e: f64[10, 10, 5] = empty((dim1, dim2, dim3), dtype=float64) f: f64[10, 10, 5] = empty((dim1, dim2, dim3), dtype=float64) g: f64[500] = empty(dim1d, dtype=float64) diff --git a/integration_tests/array_size_01.py b/integration_tests/array_size_01.py index bfa33f9eac..17135ee098 100644 --- a/integration_tests/array_size_01.py +++ b/integration_tests/array_size_01.py @@ -1,9 +1,9 @@ from lpython import i32, f64, c32, c64 -from numpy import empty +from numpy import empty, int32, float64, complex64, complex128 def main0(): - x: i32[4, 5, 2] = empty([4, 5, 2]) - y: f64[24, 100, 2, 5] = empty([24, 100, 2, 5]) + x: i32[4, 5, 2] = empty([4, 5, 2], dtype=int32) + y: f64[24, 100, 2, 5] = empty([24, 100, 2, 5], dtype=float64) print(x.size) print(y.size) @@ -11,8 +11,8 @@ def main0(): assert y.size == 24000 def main1(): - a: c32[12] = empty([12]) - b: c64[15, 15, 10] = empty([15, 15, 10]) + a: c32[12] = empty([12], dtype=complex64) + b: c64[15, 15, 10] = empty([15, 15, 10], dtype=complex128) print(a.size) print(b.size) diff --git a/integration_tests/array_size_02.py b/integration_tests/array_size_02.py index 07bd7af0d7..1d238926fd 100644 --- a/integration_tests/array_size_02.py +++ b/integration_tests/array_size_02.py @@ -1,9 +1,9 @@ -from lpython import i32, f64, c32, c64, u32 -from numpy import empty, size +from lpython import i32, f64, c32, c64, u32, u64 +from numpy import empty, size, int32, uint32, uint64, float64, complex64, complex128 def main0(): - x: i32[4, 5, 2] = empty([4, 5, 2]) - y: f64[24, 100, 2, 5] = empty([24, 100, 2, 5]) + x: i32[4, 5, 2] = empty([4, 5, 2], dtype=int32) + y: f64[24, 100, 2, 5] = empty([24, 100, 2, 5], dtype=float64) z: i32 w: i32 z = 2 @@ -29,8 +29,8 @@ def main0(): assert size(y, w) == 5 def main1(): - a: c32[12] = empty([12]) - b: c64[15, 15, 10] = empty([15, 15, 10]) + a: c32[12] = empty([12], dtype=complex64) + b: c64[15, 15, 10] = empty([15, 15, 10], dtype=complex128) c: i32 d: i32 c = 1 @@ -50,7 +50,7 @@ def main1(): assert size(b, d) == 10 def main2(): - a: i32[2, 3] = empty([2, 3]) + a: i32[2, 3] = empty([2, 3], dtype=int32) print(size(a)) print(size(a, 0)) print(size(a, 1)) @@ -60,8 +60,8 @@ def main2(): assert size(a, 1) == 3 def main3(): - a: u32[2, 3, 4] = empty([2, 3, 4]) - b: u64[10, 5] = empty([10, 5]) + a: u32[2, 3, 4] = empty([2, 3, 4], dtype=uint32) + b: u64[10, 5] = empty([10, 5], dtype=uint64) c: i32 d: i32 c = 1 diff --git a/integration_tests/bindpy_02.py b/integration_tests/bindpy_02.py index 40e29b23ea..9328029200 100644 --- a/integration_tests/bindpy_02.py +++ b/integration_tests/bindpy_02.py @@ -1,5 +1,5 @@ from lpython import i32, f64, pythoncall, Const -from numpy import empty +from numpy import empty, int32, float64 @pythoncall(module = "bindpy_02_module") def get_cpython_version() -> str: @@ -28,7 +28,7 @@ def show_array_dot_product(a: i32[:], b: f64[:]): # Integers: def test_array_ints(): n: Const[i32] = 5 - a: i32[n] = empty([n], dtype=int) + a: i32[n] = empty([n], dtype=int32) i: i32 for i in range(n): @@ -41,7 +41,7 @@ def test_array_ints(): def test_array_floats(): n: Const[i32] = 3 m: Const[i32] = 5 - b: f64[n, m] = empty([n, m], dtype=float) + b: f64[n, m] = empty([n, m], dtype=float64) i: i32 j: i32 @@ -56,8 +56,8 @@ def test_array_floats(): def test_array_broadcast(): n: Const[i32] = 3 m: Const[i32] = 5 - a: i32[n] = empty([n], dtype=int) - b: f64[n, m] = empty([n, m], dtype=float) + a: i32[n] = empty([n], dtype=int32) + b: f64[n, m] = empty([n, m], dtype=float64) i: i32 j: i32 diff --git a/integration_tests/bindpy_04.py b/integration_tests/bindpy_04.py index 5128c84d4e..0c38baa6f2 100644 --- a/integration_tests/bindpy_04.py +++ b/integration_tests/bindpy_04.py @@ -1,5 +1,5 @@ from lpython import i1, i32, u32, f64, c64, pythoncall, Const, TypeVar -from numpy import empty, uint32, complex64 +from numpy import empty, uint32, complex128 n = TypeVar("n") m = TypeVar("m") @@ -102,8 +102,8 @@ def test_2D_array_bools(): # Complex def test_array_complexes(): n: Const[i32] = 5 - a: c64[n] = empty([n], dtype=complex64) - b: c64[n] = empty([n], dtype=complex64) + a: c64[n] = empty([n], dtype=complex128) + b: c64[n] = empty([n], dtype=complex128) i: i32 for i in range(n): @@ -122,8 +122,8 @@ def test_array_complexes(): def test_2D_array_complexes(): n: Const[i32] = 3 m: Const[i32] = 4 - a: c64[n, m] = empty([n, m], dtype=complex64) - b: c64[n, m] = empty([n, m], dtype=complex64) + a: c64[n, m] = empty([n, m], dtype=complex128) + b: c64[n, m] = empty([n, m], dtype=complex128) i: i32 j: i32 diff --git a/integration_tests/elemental_01.py b/integration_tests/elemental_01.py index bc2f65b785..4925fc6165 100644 --- a/integration_tests/elemental_01.py +++ b/integration_tests/elemental_01.py @@ -1,5 +1,5 @@ from lpython import i32, f64, f32 -from numpy import empty, sin, cos, reshape +from numpy import empty, sin, cos, reshape, int32, float32, float64 def verify1d(array: f32[:], result: f32[:], size: i32): i: i32 @@ -55,9 +55,9 @@ def elemental_sum(): j: i32 k: i32 - array_a: f64[100] = empty(100) - array_b: f64[100] = empty(100) - array_c: f64[100] = empty(100) + array_a: f64[100] = empty(100, dtype=float64) + array_b: f64[100] = empty(100, dtype=float64) + array_c: f64[100] = empty(100, dtype=float64) for i in range(100): array_a[i] = float(i) @@ -74,9 +74,9 @@ def elemental_mul(): j: i32 k: i32 - array_a: f64[100] = empty(100) - array_b: f64[100] = empty(100) - array_c: f64[100] = empty(100) + array_a: f64[100] = empty(100, dtype=float64) + array_b: f64[100] = empty(100, dtype=float64) + array_c: f64[100] = empty(100, dtype=float64) for i in range(100): array_a[i] = float(i) @@ -93,8 +93,8 @@ def elemental_sin(): j: i32 k: i32 - array1d: f32[256] = empty(256) - sin1d: f32[256] = empty(256) + array1d: f32[256] = empty(256, dtype=float32) + sin1d: f32[256] = empty(256, dtype=float32) for i in range(256): array1d[i] = f32(i) @@ -103,8 +103,8 @@ def elemental_sin(): verify1d(array1d, sin1d, 256) - arraynd: f64[256, 64, 16] = empty((256, 64, 16)) - sinnd: f64[256, 64, 16] = empty((256, 64, 16)) + arraynd: f64[256, 64, 16] = empty((256, 64, 16), dtype=float64) + sinnd: f64[256, 64, 16] = empty((256, 64, 16), dtype=float64) for i in range(256): for j in range(64): @@ -119,8 +119,8 @@ def elemental_cos(): i: i32 j: i32 - array2d: f64[256, 64] = empty((256, 64)) - cos2d: f64[256, 64] = empty((256, 64)) + array2d: f64[256, 64] = empty((256, 64), dtype=float64) + cos2d: f64[256, 64] = empty((256, 64), dtype=float64) for i in range(256): for j in range(64): @@ -138,9 +138,9 @@ def elemental_trig_identity(): eps: f32 eps = f32(1e-6) - arraynd: f32[64, 32, 8, 4] = empty((64, 32, 8, 4)) - observed: f32[64, 32, 8, 4] = empty((64, 32, 8, 4)) - observed1d: f32[65536] = empty(65536) + arraynd: f32[64, 32, 8, 4] = empty((64, 32, 8, 4), dtype=float32) + observed: f32[64, 32, 8, 4] = empty((64, 32, 8, 4), dtype=float32) + observed1d: f32[65536] = empty(65536, dtype=float32) for i in range(64): for j in range(32): @@ -150,7 +150,7 @@ def elemental_trig_identity(): observed = sin(arraynd)**f32(2) + cos(arraynd)**f32(2) - newshape: i32[1] = empty(1, dtype=int) + newshape: i32[1] = empty(1, dtype=int32) newshape[0] = 65536 observed1d = reshape(observed, newshape) diff --git a/integration_tests/elemental_02.py b/integration_tests/elemental_02.py index 4467dea8f8..2c73cecd19 100644 --- a/integration_tests/elemental_02.py +++ b/integration_tests/elemental_02.py @@ -1,12 +1,12 @@ from lpython import i32, f64, f32 -from numpy import empty, tan, sin, cos, reshape +from numpy import empty, tan, sin, cos, reshape, int32, float32, float64 def elemental_tan64(): - theta: f64[16, 8, 4, 2, 1] = empty((16, 8, 4, 2, 1)) - theta1d: f64[1024] = empty(1024) - tantheta: f64[16, 8, 4, 2, 1] = empty((16, 8, 4, 2, 1)) - observed: f64[16, 8, 4, 2, 1] = empty((16, 8, 4, 2, 1)) - shapend: i32[5] = empty(5, dtype=int) + theta: f64[16, 8, 4, 2, 1] = empty((16, 8, 4, 2, 1), dtype=float64) + theta1d: f64[1024] = empty(1024, dtype=float64) + tantheta: f64[16, 8, 4, 2, 1] = empty((16, 8, 4, 2, 1), dtype=float64) + observed: f64[16, 8, 4, 2, 1] = empty((16, 8, 4, 2, 1), dtype=float64) + shapend: i32[5] = empty(5, dtype=int32) i: i32 j: i32 k: i32 @@ -31,11 +31,11 @@ def elemental_tan64(): assert abs(tantheta[i, j, k, l, 0] - observed[i, j, k, l, 0]) <= eps def elemental_tan32(): - theta: f32[5, 5] = empty((5, 5)) - theta1d: f32[25] = empty(25) - tantheta: f32[5, 5] = empty((5, 5)) - observed: f32[5, 5] = empty((5, 5)) - shapend: i32[2] = empty(2, dtype=int) + theta: f32[5, 5] = empty((5, 5), dtype=float32) + theta1d: f32[25] = empty(25, dtype=float32) + tantheta: f32[5, 5] = empty((5, 5), dtype=float32) + observed: f32[5, 5] = empty((5, 5), dtype=float32) + shapend: i32[2] = empty(2, dtype=int32) i: i32 j: i32 eps: f32 diff --git a/integration_tests/elemental_03.py b/integration_tests/elemental_03.py index 240b1d4289..2638505344 100644 --- a/integration_tests/elemental_03.py +++ b/integration_tests/elemental_03.py @@ -1,10 +1,10 @@ from lpython import i32, f32, f64 -from numpy import empty, sqrt, reshape +from numpy import empty, sqrt, reshape, int32, float32, float64 def elemental_sqrt64(): - array: f64[16, 16, 16] = empty((16, 16, 16)) - observed: f64[4096] = empty(4096) - shape: i32[1] = empty(1, dtype=int) + array: f64[16, 16, 16] = empty((16, 16, 16), dtype=float64) + observed: f64[4096] = empty(4096, dtype=float64) + shape: i32[1] = empty(1, dtype=int32) eps: f64 eps = 1e-12 i: i32 @@ -26,9 +26,9 @@ def elemental_sqrt64(): assert abs(observed[l]**2.0 - f64(i + j + k)) <= eps def elemental_sqrt32(): - array: f32[16, 16] = empty((16, 16)) - observed: f32[256] = empty(256) - shape: i32[1] = empty(1, dtype=int) + array: f32[16, 16] = empty((16, 16), dtype=float32) + observed: f32[256] = empty(256, dtype=float32) + shape: i32[1] = empty(1, dtype=int32) eps: f32 eps = f32(5e-6) i: i32 @@ -48,9 +48,9 @@ def elemental_sqrt32(): def elemental_norm(): - array_a: f64[100] = empty(100) - array_b: f64[100] = empty(100) - array_c: f64[100] = empty(100) + array_a: f64[100] = empty(100, dtype=float64) + array_b: f64[100] = empty(100, dtype=float64) + array_c: f64[100] = empty(100, dtype=float64) i: i32 j: i32 diff --git a/integration_tests/elemental_04.py b/integration_tests/elemental_04.py index 6f2055c69e..d51e5d7a4f 100644 --- a/integration_tests/elemental_04.py +++ b/integration_tests/elemental_04.py @@ -1,10 +1,10 @@ from lpython import i32, f32, f64 -from numpy import empty, log, log10, log2, reshape +from numpy import empty, log, log10, log2, reshape, int32, float32, float64 from math import exp def elemental_log(): - array: f64[100] = empty(100) - observed: f64[100] = empty(100) + array: f64[100] = empty(100, dtype=float64) + observed: f64[100] = empty(100, dtype=float64) i: i32 eps: f64 eps = 1e-12 @@ -28,9 +28,9 @@ def verify(observed: f32[:], base: i32, eps: f32): assert abs(f32(base)**(observed[k]) - f32(i + j + 1)) <= eps def elemental_log2_log10(): - array: f32[10, 10] = empty((10, 10)) - observed: f32[100] = empty(100) - shape: i32[1] = empty(1, dtype=int) + array: f32[10, 10] = empty((10, 10), dtype=float32) + observed: f32[100] = empty(100, dtype=float32) + shape: i32[1] = empty(1, dtype=int32) i: i32 j: i32 eps: f32 diff --git a/integration_tests/elemental_05.py b/integration_tests/elemental_05.py index 53b6d1f1db..4e91b8eaa2 100644 --- a/integration_tests/elemental_05.py +++ b/integration_tests/elemental_05.py @@ -1,5 +1,5 @@ from lpython import i32, f64, f32 -from numpy import empty, sinh, cosh, reshape, int32, float64, sin +from numpy import empty, sinh, cosh, reshape, int32, float32, float64, sin def verify1d(array: f32[:], result: f32[:], size: i32): i: i32 @@ -24,8 +24,8 @@ def verifynd(array: f64[:, :, :, :], result: f64[:, :, :, :], size1: i32, size2: def elemental_sinh(): i: i32; j: i32; k: i32; l: i32; size: i32; - array1d: f32[10] = empty(10) - sinh1d: f32[10] = empty(10) + array1d: f32[10] = empty(10, dtype=float32) + sinh1d: f32[10] = empty(10, dtype=float32) for i in range(10): array1d[i] = f32(f64(i)/10.0) @@ -33,8 +33,8 @@ def elemental_sinh(): sinh1d = sinh(sinh(array1d)) verify1d(array1d, sinh1d, 10) - arraynd: f64[40, 10, 16, 2] = empty((40, 10, 16, 2)) - sinhnd: f64[40, 10, 16, 2] = empty((40, 10, 16, 2)) + arraynd: f64[40, 10, 16, 2] = empty((40, 10, 16, 2), dtype=float64) + sinhnd: f64[40, 10, 16, 2] = empty((40, 10, 16, 2), dtype=float64) size = 40 * 10 * 16 * 2 for i in range(40): @@ -58,12 +58,12 @@ def verify2d(array: f64[:, :], result: f64[:, :], size1: i32, size2: i32): def elemental_cosh(): i: i32; j: i32 - array2d: f64[20, 10] = empty((20, 10)) - cosh2d: f64[20, 10] = empty((20, 10)) + array2d: f64[20, 10] = empty((20, 10), dtype=float64) + cosh2d: f64[20, 10] = empty((20, 10), dtype=float64) for i in range(20): for j in range(10): - array2d[i, j] = float(i + 2*j)/200.0 + array2d[i, j] = float(i + 2*j)/200.0 cosh2d = cosh(5.0 + (array2d))**2.0 verify2d(array2d, cosh2d, 20, 10) @@ -72,8 +72,8 @@ def elemental_cosh_(): i: i32 j: i32 - array2d: f64[20, 10] = empty((20, 10)) - cosh2d: f64[20, 10] = empty((20, 10)) + array2d: f64[20, 10] = empty((20, 10), dtype=float64) + cosh2d: f64[20, 10] = empty((20, 10), dtype=float64) for i in range(20): for j in range(10): @@ -111,7 +111,7 @@ def elemental_trig_identity(): cosh(arraynd/4.0) * cosh(arraynd/2.0) - sinh(arraynd/4.0) * sinh(arraynd/2.0)) - newshape: i32[1] = empty(1, dtype=int) + newshape: i32[1] = empty(1, dtype=int32) newshape[0] = 400 observed1d_1 = reshape(identity1, newshape) diff --git a/integration_tests/elemental_06.py b/integration_tests/elemental_06.py index 1ecd78bf74..06b6117652 100644 --- a/integration_tests/elemental_06.py +++ b/integration_tests/elemental_06.py @@ -1,5 +1,5 @@ from lpython import i32, f32, f64 -from numpy import empty, arcsin, arccos, sin, cos, sqrt, arctan, tan, degrees, radians +from numpy import empty, arcsin, arccos, sin, cos, sqrt, arctan, tan, degrees, radians, float32, float64 from math import pi def verify1d_same(array: f32[:], result: f32[:], size: i32): @@ -60,15 +60,15 @@ def verify_arctan_2d(array: f64[:, :], result: f64[:, :], size1:i32, size2:i32): def elemental_arcsin(): i: i32 j: i32 - array1d: f32[201] = empty(201) - arcsin1d: f32[201] = empty(201) + array1d: f32[201] = empty(201, dtype=float32) + arcsin1d: f32[201] = empty(201, dtype=float32) for i in range(201): array1d[i] = f32((i - 100)/100) arcsin1d = arcsin(array1d) ** f32(2.0) verify_arcsin_1d(array1d, arcsin1d, 201) - array2d: f64[64, 64] = empty((64, 64)) - arcsin2d: f64[64, 64] = empty((64, 64)) + array2d: f64[64, 64] = empty((64, 64), dtype=float64) + arcsin2d: f64[64, 64] = empty((64, 64), dtype=float64) for i in range(64): for j in range(64): # 2048 = 64 * 32 array2d[i,j]= float((i * 64 + j - 2048 )/2048) @@ -79,15 +79,15 @@ def elemental_arcsin(): def elemental_arccos(): i: i32 j: i32 - array1d: f32[201] = empty(201) - arccos1d: f32[201] = empty(201) + array1d: f32[201] = empty(201, dtype=float32) + arccos1d: f32[201] = empty(201, dtype=float32) for i in range(201): array1d[i] = f32((i - 100)/100) arccos1d = arccos(array1d) ** f32(2.0) verify_arccos_1d(array1d, arccos1d, 201) - array2d: f64[64, 64] = empty((64, 64)) - arccos2d: f64[64, 64] = empty((64, 64)) + array2d: f64[64, 64] = empty((64, 64), dtype=float64) + arccos2d: f64[64, 64] = empty((64, 64), dtype=float64) for i in range(64): for j in range(64): # 2048 = 64 * 32 array2d[i,j]= float((i * 64 + j - 2048 )/2048) @@ -100,9 +100,9 @@ def elemental_arctan(): j: i32 eps: f32 eps = f32(1e-6) - array1d: f32[201] = empty(201) - array1d_rec: f32[201] = empty(201) - arctan1d: f32[201] = empty(201) + array1d: f32[201] = empty(201, dtype=float32) + array1d_rec: f32[201] = empty(201, dtype=float32) + arctan1d: f32[201] = empty(201, dtype=float32) for i in range(201): array1d[i] = f32(i - 100) arctan1d = arctan(array1d) ** f32(2.0) @@ -115,8 +115,8 @@ def elemental_arctan(): for i in range(201): assert abs(arctan1d[i] - f32(f64(pi) / 2.0)) <= eps - array2d: f64[64, 64] = empty((64, 64)) - arctan2d: f64[64, 64] = empty((64, 64)) + array2d: f64[64, 64] = empty((64, 64), dtype=float64) + arctan2d: f64[64, 64] = empty((64, 64), dtype=float64) for i in range(64): for j in range(64): array2d[i,j]= float(64*i + j - 2048) @@ -128,8 +128,8 @@ def elemental_trig_identity(): i: i32 eps: f32 eps = f32(1e-6) - array1d: f32[201] = empty(201) - observed1d: f32[201] = empty(201) + array1d: f32[201] = empty(201, dtype=float32) + observed1d: f32[201] = empty(201, dtype=float32) for i in range(201): array1d[i] = f32((i - 100)/100) @@ -139,8 +139,8 @@ def elemental_trig_identity(): def elemental_reverse(): i: i32 - array1d: f32[201] = empty(201) - observed1d: f32[201] = empty(201) + array1d: f32[201] = empty(201, dtype=float32) + observed1d: f32[201] = empty(201, dtype=float32) for i in range(201): array1d[i] = f32((i - 100)/100) observed1d = sin(arcsin(array1d)) @@ -157,9 +157,9 @@ def elemental_reverse(): def elemental_trig_identity_extra(): i: i32 - array1d: f32[201] = empty(201) - array_x: f32[201] = empty(201) - array_y: f32[201] = empty(201) + array1d: f32[201] = empty(201, dtype=float32) + array_x: f32[201] = empty(201, dtype=float32) + array_y: f32[201] = empty(201, dtype=float32) for i in range(201): array1d[i] = f32((i - 100)/100) array_x = sin(arccos(array1d)) @@ -177,8 +177,8 @@ def elemental_degrees(): eps_64: f64 eps_32 = f32(1e-6) eps_64 = 1e-12 - array1d: f32[200] = empty(200) - degrees1d: f32[200] = empty(200) + array1d: f32[200] = empty(200, dtype=float32) + degrees1d: f32[200] = empty(200, dtype=float32) for i in range(200): array1d[i] = f32(i) degrees1d = sin(degrees(array1d)) @@ -186,8 +186,8 @@ def elemental_degrees(): for i in range(200): assert abs(degrees1d[i] - sin(degrees(array1d[i]))) <= eps_32 - array2d: f64[64, 64] = empty((64, 64)) - degrees2d: f64[64, 64] = empty((64, 64)) + array2d: f64[64, 64] = empty((64, 64), dtype=float64) + degrees2d: f64[64, 64] = empty((64, 64), dtype=float64) for i in range(64): for j in range(64): array2d[i,j]= float(i*64+j) @@ -203,8 +203,8 @@ def elemental_radians(): eps_64: f64 eps_32 = f32(1e-6) eps_64 = 1e-12 - array1d: f32[200] = empty(200) - radians1d: f32[200] = empty(200) + array1d: f32[200] = empty(200, dtype=float32) + radians1d: f32[200] = empty(200, dtype=float32) for i in range(200): array1d[i] = f32(i) radians1d = cos(radians(array1d)) @@ -212,8 +212,8 @@ def elemental_radians(): for i in range(200): assert abs(radians1d[i] - cos(radians(array1d[i]))) <= eps_32 - array2d: f64[64, 64] = empty((64, 64)) - radians2d: f64[64, 64] = empty((64, 64)) + array2d: f64[64, 64] = empty((64, 64), dtype=float64) + radians2d: f64[64, 64] = empty((64, 64), dtype=float64) for i in range(64): for j in range(64): array2d[i,j]= float(i*64+j) diff --git a/integration_tests/elemental_07.py b/integration_tests/elemental_07.py index fcae022601..b458eab989 100644 --- a/integration_tests/elemental_07.py +++ b/integration_tests/elemental_07.py @@ -1,5 +1,5 @@ from lpython import i32, f64, f32 -from numpy import empty, tanh, reshape, int32, float64, sin, log10 +from numpy import empty, tanh, reshape, int32, float32, float64, sin def verify1d(array: f32[:], result: f32[:], size: i32): i: i32 @@ -24,8 +24,8 @@ def verifynd(array: f64[:, :, :, :], result: f64[:, :, :, :], size1: i32, size2: def elemental_tanh(): i: i32; j: i32; k: i32; l: i32; size: i32; - array1d: f32[80] = empty(80) - tanh1d: f32[80] = empty(80) + array1d: f32[80] = empty(80, dtype=float32) + tanh1d: f32[80] = empty(80, dtype=float32) for i in range(80): array1d[i] = f32(f64(i) / 10.0) @@ -33,8 +33,8 @@ def elemental_tanh(): tanh1d = tanh(sin(array1d)) verify1d(array1d, tanh1d, 10) - arraynd: f64[16, 8, 4, 2] = empty((16, 8, 4, 2)) - tanhnd: f64[16, 8, 4, 2] = empty((16, 8, 4, 2)) + arraynd: f64[16, 8, 4, 2] = empty((16, 8, 4, 2), dtype=float64) + tanhnd: f64[16, 8, 4, 2] = empty((16, 8, 4, 2), dtype=float64) size = 16 * 8 * 4 * 2 for i in range(16): diff --git a/integration_tests/elemental_08.py b/integration_tests/elemental_08.py index 9d1e8f0003..1903e93cd1 100644 --- a/integration_tests/elemental_08.py +++ b/integration_tests/elemental_08.py @@ -1,5 +1,5 @@ from lpython import i32, f64, f32 -from numpy import empty, reshape, int32, exp +from numpy import empty, reshape, int32, float32, float64, exp def verify1d(array: f32[:], result: f32[:], size: i32): i: i32 @@ -23,8 +23,8 @@ def verifynd(array: f64[:, :, :, :], result: f64[:, :, :, :], size1: i32, size2: def elemental_exp(): i: i32; j: i32; k: i32; l: i32; size: i32; - array1d: f32[80] = empty(80) - exp1d: f32[80] = empty(80) + array1d: f32[80] = empty(80, dtype=float32) + exp1d: f32[80] = empty(80, dtype=float32) for i in range(80): array1d[i] = f32(f64(i) / 50.0) @@ -32,8 +32,8 @@ def elemental_exp(): exp1d = exp(array1d) verify1d(array1d, exp1d, 80) - arraynd: f64[16, 8, 4, 2] = empty((16, 8, 4, 2)) - expnd: f64[16, 8, 4, 2] = empty((16, 8, 4, 2)) + arraynd: f64[16, 8, 4, 2] = empty((16, 8, 4, 2), dtype=float64) + expnd: f64[16, 8, 4, 2] = empty((16, 8, 4, 2), dtype=float64) size = 32 for i in range(16): diff --git a/integration_tests/elemental_09.py b/integration_tests/elemental_09.py index 1e537f391d..a821177463 100644 --- a/integration_tests/elemental_09.py +++ b/integration_tests/elemental_09.py @@ -1,5 +1,5 @@ from lpython import i32, f64, f32 -from numpy import empty, arcsinh, arccosh, reshape, float64, sinh, sqrt, sin, cosh +from numpy import empty, arcsinh, arccosh, reshape, int32, float32, float64, sinh, sqrt, sin def verify1d_arcsinh(array: f32[:], result: f32[:], size: i32): i: i32 @@ -27,8 +27,8 @@ def elemental_arcsinh(): j: i32 k: i32 - array1d: f32[256] = empty(256) - arcsinh1d: f32[256] = empty(256) + array1d: f32[256] = empty(256, dtype=float32) + arcsinh1d: f32[256] = empty(256, dtype=float32) for i in range(256): array1d[i] = f32(i) @@ -36,8 +36,8 @@ def elemental_arcsinh(): arcsinh1d = arcsinh(arcsinh(array1d)) verify1d_arcsinh(array1d, arcsinh1d, 256) - arraynd: f64[256, 64, 16] = empty((256, 64, 16)) - arcsinhnd: f64[256, 64, 16] = empty((256, 64, 16)) + arraynd: f64[256, 64, 16] = empty((256, 64, 16), dtype=float64) + arcsinhnd: f64[256, 64, 16] = empty((256, 64, 16), dtype=float64) for i in range(256): for j in range(64): @@ -77,8 +77,8 @@ def elemental_arccosh(): k: i32 l: i32 - array2d: f64[256, 64] = empty((256, 64)) - arccosh2d: f64[256, 64] = empty((256, 64)) + array2d: f64[256, 64] = empty((256, 64), dtype=float64) + arccosh2d: f64[256, 64] = empty((256, 64), dtype=float64) for i in range(256): for j in range(64): @@ -87,8 +87,8 @@ def elemental_arccosh(): arccosh2d = arccosh(array2d)**2.0 verify2d_arccosh(array2d, arccosh2d, 256, 64) - arraynd: f64[32, 16, 4, 2] = empty((32, 16, 4, 2)) - arccosh_nd: f64[32, 16, 4, 2] = empty((32, 16, 4, 2)) + arraynd: f64[32, 16, 4, 2] = empty((32, 16, 4, 2), dtype=float64) + arccosh_nd: f64[32, 16, 4, 2] = empty((32, 16, 4, 2), dtype=float64) for i in range(32): for j in range(16): @@ -126,7 +126,7 @@ def elemental_trig_identity(): identity3 = 2.0 * arcsinh(arraynd) - arccosh((arraynd**2.0) * 2.0 + 1.0) - newshape: i32[1] = empty(1, dtype=int) + newshape: i32[1] = empty(1, dtype=int32) newshape[0] = 400 observed1d_1 = reshape(identity1, newshape) diff --git a/integration_tests/elemental_11.py b/integration_tests/elemental_11.py index c66335a8da..ca6b111902 100644 --- a/integration_tests/elemental_11.py +++ b/integration_tests/elemental_11.py @@ -1,5 +1,5 @@ from lpython import i32, f64, f32 -from numpy import empty, arctanh, reshape, float64, sinh, sqrt, sin, cosh +from numpy import empty, arctanh, reshape, int32, float32, float64, sinh, sqrt, sin, cosh def verify1d_arctanh(array: f32[:], result: f32[:], size: i32): i: i32 @@ -27,8 +27,8 @@ def elemental_arctanh(): j: i32 k: i32 - array1d: f32[999] = empty(999) - arctanh1d: f32[999] = empty(999) + array1d: f32[999] = empty(999, dtype=float32) + arctanh1d: f32[999] = empty(999, dtype=float32) for i in range(999): array1d[i] = f32(f64((-1)**i) * (float(i)/1000.0)) @@ -36,8 +36,8 @@ def elemental_arctanh(): arctanh1d = arctanh(array1d) verify1d_arctanh(array1d, arctanh1d, 999) - arraynd: f64[100, 50, 10] = empty((100, 50, 10)) - arctanhnd: f64[100, 50, 10] = empty((100, 50, 10)) + arraynd: f64[100, 50, 10] = empty((100, 50, 10), dtype=float64) + arctanhnd: f64[100, 50, 10] = empty((100, 50, 10), dtype=float64) for i in range(100): for j in range(50): @@ -70,7 +70,7 @@ def elemental_trig_identity(): identity1 = 2.0 * arctanh(arraynd) - arctanh((2.0 * arraynd) / ( 1.0 + arraynd**2.0)) identity2 = cosh(arctanh(arraynd)) - (sqrt(1.0 - (arraynd**2.0)))**(-1.0) - newshape: i32[1] = empty(1, dtype=int) + newshape: i32[1] = empty(1, dtype=int32) newshape[0] = 400 observed1d_1 = reshape(identity1, newshape) diff --git a/integration_tests/elemental_12.py b/integration_tests/elemental_12.py index 93991c2579..d81baf7293 100644 --- a/integration_tests/elemental_12.py +++ b/integration_tests/elemental_12.py @@ -1,5 +1,5 @@ from lpython import i32, f32, f64 -from numpy import empty, floor, ceil, sqrt, reshape +from numpy import empty, floor, ceil, sqrt, reshape, int32, float32, float64 def elemental_floor64(): i: i32 @@ -9,9 +9,9 @@ def elemental_floor64(): eps: f32 eps = f32(1e-6) - arraynd: f64[32, 16, 8, 4] = empty((32, 16, 8, 4)) + arraynd: f64[32, 16, 8, 4] = empty((32, 16, 8, 4), dtype=float64) - newshape: i32[1] = empty(1, dtype=int) + newshape: i32[1] = empty(1, dtype=int32) newshape[0] = 16384 for i in range(32): @@ -20,13 +20,13 @@ def elemental_floor64(): for l in range(4): arraynd[i, j, k, l] = f64((-1)**l) * sqrt(float(i + j + k + l)) - observed: f64[32, 16, 8, 4] = empty((32, 16, 8, 4)) + observed: f64[32, 16, 8, 4] = empty((32, 16, 8, 4), dtype=float64) observed = floor(arraynd) - observed1d: f64[16384] = empty(16384) + observed1d: f64[16384] = empty(16384, dtype=float64) observed1d = reshape(observed, newshape) - array: f64[16384] = empty(16384) + array: f64[16384] = empty(16384, dtype=float64) array = reshape(arraynd, newshape) for i in range(16384): @@ -41,7 +41,7 @@ def elemental_floor32(): eps: f32 eps = f32(1e-6) - arraynd: f32[32, 16, 8, 4] = empty((32, 16, 8, 4)) + arraynd: f32[32, 16, 8, 4] = empty((32, 16, 8, 4), dtype=float32) for i in range(32): for j in range(16): @@ -49,7 +49,7 @@ def elemental_floor32(): for l in range(4): arraynd[i, j, k, l] = f32(f64((-1)**l) * sqrt(float(i + j + k + l))) - observed: f32[32, 16, 8, 4] = empty((32, 16, 8, 4)) + observed: f32[32, 16, 8, 4] = empty((32, 16, 8, 4), dtype=float32) observed = floor(arraynd) for i in range(32): @@ -67,9 +67,9 @@ def elemental_ceil64(): eps: f32 eps = f32(1e-6) - arraynd: f64[32, 16, 8, 4] = empty((32, 16, 8, 4)) + arraynd: f64[32, 16, 8, 4] = empty((32, 16, 8, 4), dtype=float64) - newshape: i32[1] = empty(1, dtype=int) + newshape: i32[1] = empty(1, dtype=int32) newshape[0] = 16384 for i in range(32): @@ -78,13 +78,13 @@ def elemental_ceil64(): for l in range(4): arraynd[i, j, k, l] = f64((-1)**l) * sqrt(float(i + j + k + l)) - observed: f64[32, 16, 8, 4] = empty((32, 16, 8, 4)) + observed: f64[32, 16, 8, 4] = empty((32, 16, 8, 4), dtype=float64) observed = ceil(arraynd) - observed1d: f64[16384] = empty(16384) + observed1d: f64[16384] = empty(16384, dtype=float64) observed1d = reshape(observed, newshape) - array: f64[16384] = empty(16384) + array: f64[16384] = empty(16384, dtype=float64) array = reshape(arraynd, newshape) for i in range(16384): @@ -99,7 +99,7 @@ def elemental_ceil32(): eps: f32 eps = f32(1e-6) - arraynd: f32[32, 16, 8, 4] = empty((32, 16, 8, 4)) + arraynd: f32[32, 16, 8, 4] = empty((32, 16, 8, 4), dtype=float32) for i in range(32): for j in range(16): @@ -107,7 +107,7 @@ def elemental_ceil32(): for l in range(4): arraynd[i, j, k, l] = f32(f64((-1)**l) * sqrt(float(i + j + k + l))) - observed: f32[32, 16, 8, 4] = empty((32, 16, 8, 4)) + observed: f32[32, 16, 8, 4] = empty((32, 16, 8, 4), dtype=float32) observed = ceil(arraynd) for i in range(32): diff --git a/integration_tests/expr_06.py b/integration_tests/expr_06.py index 546aad4ec1..566530ddb1 100644 --- a/integration_tests/expr_06.py +++ b/integration_tests/expr_06.py @@ -1,11 +1,11 @@ from lpython import i32, f32, f64 -from numpy import empty, cos, sin +from numpy import empty, cos, sin, int32 def main0(): x: i32 = 25 y: i32 = (2 + 3) * 5 z: f32 = (f32(2.0) + f32(3)) * f32(5.0) - xa: i32[3] = empty(3) + xa: i32[3] = empty(3, dtype=int32) assert x == 25 assert y == 25 assert z == f32(25.0) diff --git a/integration_tests/generics_array_01.py b/integration_tests/generics_array_01.py index 65bb7d8435..3ae77260ee 100644 --- a/integration_tests/generics_array_01.py +++ b/integration_tests/generics_array_01.py @@ -1,5 +1,5 @@ from lpython import TypeVar, i32 -from numpy import empty +from numpy import empty, int32 T = TypeVar('T') @@ -9,9 +9,9 @@ def f(lst: T[:], i: T) -> T: def use_array(): array: i32[1] - array = empty(1) + array = empty(1, dtype=int32) x: i32 x = 69 print(f(array, x)) -use_array() \ No newline at end of file +use_array() diff --git a/integration_tests/generics_array_02.py b/integration_tests/generics_array_02.py index 3d1427ec38..2315582ca0 100644 --- a/integration_tests/generics_array_02.py +++ b/integration_tests/generics_array_02.py @@ -1,5 +1,5 @@ from lpython import TypeVar, restriction, i32, f32 -from numpy import empty +from numpy import empty, int32, float32 n = TypeVar("n") T = TypeVar('T') @@ -16,21 +16,21 @@ def add_float(x: f32, y: f32) -> f32: def g(n: i32, a: T[n], b: T[n], **kwargs): r: T[n] - r = empty(n) + r = empty(n, dtype=object) i: i32 for i in range(n): r[i] = add(a[i], b[i]) print(r[0]) def main(): - a_int: i32[1] = empty(1) + a_int: i32[1] = empty(1, dtype=int32) a_int[0] = 400 - b_int: i32[1] = empty(1) + b_int: i32[1] = empty(1, dtype=int32) b_int[0] = 20 g(1, a_int, b_int, add=add_integer) - a_float: f32[1] = empty(1) + a_float: f32[1] = empty(1, dtype=float32) a_float[0] = f32(400.0) - b_float: f32[1] = empty(1) + b_float: f32[1] = empty(1, dtype=float32) b_float[0] = f32(20.0) g(1, a_float, b_float, add=add_float) diff --git a/integration_tests/generics_array_03.py b/integration_tests/generics_array_03.py index 8cda3a9840..ebc5875220 100644 --- a/integration_tests/generics_array_03.py +++ b/integration_tests/generics_array_03.py @@ -1,5 +1,5 @@ from lpython import TypeVar, restriction, i32, f32 -from numpy import empty +from numpy import empty, int32, float32 n = TypeVar("n") m = TypeVar("m") @@ -17,7 +17,7 @@ def add_float(x: f32, y: f32) -> f32: def g(n: i32, m: i32, a: T[n,m], b: T[n,m], **kwargs) -> T[n,m]: r: T[n,m] - r = empty([n,m]) + r = empty([n,m], dtype=object) i: i32 j: i32 for i in range(n): @@ -26,14 +26,14 @@ def g(n: i32, m: i32, a: T[n,m], b: T[n,m], **kwargs) -> T[n,m]: print(r[0,0]) def main(): - a_int: i32[1,1] = empty([1,1]) + a_int: i32[1,1] = empty([1,1], dtype=int32) a_int[0,0] = 400 - b_int: i32[1,1] = empty([1,1]) + b_int: i32[1,1] = empty([1,1], dtype=int32) b_int[0,0] = 20 g(1, 1, a_int, b_int, add=add_integer) - a_float: f32[1,1] = empty([1,1]) + a_float: f32[1,1] = empty([1,1], dtype=float32) a_float[0,0] = f32(400) - b_float: f32[1,1] = empty([1,1]) + b_float: f32[1,1] = empty([1,1], dtype=float32) b_float[0,0] = f32(20) g(1, 1, a_float, b_float, add=add_float) diff --git a/integration_tests/test_numpy_01.py b/integration_tests/test_numpy_01.py index 97d4a2405a..85685d01df 100644 --- a/integration_tests/test_numpy_01.py +++ b/integration_tests/test_numpy_01.py @@ -1,11 +1,11 @@ # This test handles various aspects of local arrays using the `numpy.empty()` # function from lpython import f64, i32 -from numpy import empty +from numpy import empty, float64 def test_local_arrays(): a: f64[16] - a = empty(16) + a = empty(16, dtype=float64) i: i32 for i in range(16): a[i] = f64(i) + 0.5 @@ -18,7 +18,7 @@ def test_local_arrays(): def f() -> f64[4]: a: f64[4] - a = empty(4) + a = empty(4, dtype=float64) i: i32 for i in range(4): a[i] = 1.0 * f64(i) diff --git a/integration_tests/test_numpy_02.py b/integration_tests/test_numpy_02.py index 592a0d92e4..920b102dbf 100644 --- a/integration_tests/test_numpy_02.py +++ b/integration_tests/test_numpy_02.py @@ -1,7 +1,7 @@ # This test handles actual LPython implementations of functions from the numpy # module. from lpython import i32, i64, f32, f64, c32, c64, TypeVar, overload -from numpy import empty, int64 +from numpy import empty, int64, float64 e: f64 = 2.718281828459045 pi: f64 = 3.141592653589793 @@ -16,7 +16,7 @@ def zeros(n: i32) -> f64[n]: A: f64[n] - A = empty(n) + A = empty(n, dtype=float64) i: i32 for i in range(n): A[i] = 0.0 @@ -24,7 +24,7 @@ def zeros(n: i32) -> f64[n]: def ones(n: i32) -> f64[n]: A: f64[n] - A = empty(n) + A = empty(n, dtype=float64) i: i32 for i in range(n): A[i] = 1.0 @@ -128,7 +128,7 @@ def fabs(b: bool) -> f64: num = TypeVar("num") def linspace(start: f64, stop: f64, num: i32) -> f64[num]: A: f64[num] - A = empty(num) + A = empty(num, dtype=float64) i: i32 for i in range(num): A[i] = start + (stop-start)*f64(i)/f64(num-1) diff --git a/integration_tests/test_numpy_03.py b/integration_tests/test_numpy_03.py index 04587d0c89..82faf76db4 100644 --- a/integration_tests/test_numpy_03.py +++ b/integration_tests/test_numpy_03.py @@ -1,5 +1,5 @@ from lpython import f64, i32 -from numpy import reshape, empty +from numpy import reshape, empty, int32, float64 def test_nd_to_1d(a: f64[:, :]): i: i32 @@ -9,8 +9,8 @@ def test_nd_to_1d(a: f64[:, :]): eps: f64 eps = 1e-12 - b: f64[256] = empty(256) - newshape: i32[1] = empty(1, dtype=int) + b: f64[256] = empty(256, dtype=float64) + newshape: i32[1] = empty(1, dtype=int32) newshape[0] = 256 b = reshape(a, newshape) for k in range(256): @@ -18,15 +18,15 @@ def test_nd_to_1d(a: f64[:, :]): j = k - i*16 assert abs(b[k] - f64(i + j) - 0.5) <= eps - c: f64[16, 16, 16] = empty((16, 16, 16)) - c = empty((16, 16, 16)) + c: f64[16, 16, 16] = empty((16, 16, 16), dtype=float64) + c = empty((16, 16, 16), dtype=float64) for i in range(16): for j in range(16): for k in range(16): c[i, j, k] = f64(i + j + k) + 0.5 - d: f64[4096] = empty(4096) - newshape1: i32[1] = empty(1, dtype=int) + d: f64[4096] = empty(4096, dtype=float64) + newshape1: i32[1] = empty(1, dtype=int32) newshape1[0] = 4096 d = reshape(c, newshape1) for l in range(4096): @@ -43,15 +43,15 @@ def test_1d_to_nd(d: f64[:]): eps: f64 eps = 1e-12 - b: f64[256] = empty(256) + b: f64[256] = empty(256, dtype=float64) for k in range(256): i = k//16 j = k - i*16 b[k] = f64(i + j) + 0.5 a: f64[16, 16] - a = empty((16, 16)) - newshape: i32[2] = empty(2, dtype=int) + a = empty((16, 16), dtype=float64) + newshape: i32[2] = empty(2, dtype=int32) newshape[0] = 16 newshape[1] = 16 a = reshape(b, newshape) @@ -60,8 +60,8 @@ def test_1d_to_nd(d: f64[:]): assert abs(a[i, j] - f64(i + j) - 0.5) <= eps c: f64[16, 16, 16] - c = empty((16, 16, 16)) - newshape1: i32[3] = empty(3, dtype=int) + c = empty((16, 16, 16), dtype=float64) + newshape1: i32[3] = empty(3, dtype=int32) newshape1[0] = 16 newshape1[1] = 16 newshape1[2] = 16 @@ -78,14 +78,14 @@ def test_reshape_with_argument(): l: i32 a: f64[16, 16] - a = empty((16, 16)) + a = empty((16, 16), dtype=float64) for i in range(16): for j in range(16): a[i, j] = f64(i + j) + 0.5 test_nd_to_1d(a) - d: f64[4096] = empty(4096) + d: f64[4096] = empty(4096, dtype=float64) for l in range(4096): i = i32(l/256) j = (l - i*256)//16 diff --git a/integration_tests/vec_01.py b/integration_tests/vec_01.py index 198fdba803..8d93b8b9c2 100644 --- a/integration_tests/vec_01.py +++ b/integration_tests/vec_01.py @@ -1,9 +1,9 @@ from lpython import f64, i32 -from numpy import empty +from numpy import empty, float64 def loop_vec(): - a: f64[9216] = empty(9216) - b: f64[9216] = empty(9216) + a: f64[9216] = empty(9216, dtype=float64) + b: f64[9216] = empty(9216, dtype=float64) i: i32 for i in range(9216): From 976905fb4a995e3b5beb452df9f2f2f46bcbcf0f Mon Sep 17 00:00:00 2001 From: Shaikh Ubaid Date: Thu, 24 Aug 2023 22:17:54 +0530 Subject: [PATCH 15/18] TEST: Fix error tests to use dtype --- tests/errors/bindc_04.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/errors/bindc_04.py b/tests/errors/bindc_04.py index a8f1ddce0d..ec2c207226 100644 --- a/tests/errors/bindc_04.py +++ b/tests/errors/bindc_04.py @@ -1,15 +1,15 @@ from lpython import CPtr, i32, Pointer, i16 -from numpy import empty, int32 +from numpy import empty, int16 def fill_A(k: i32, n: i32) -> None: - A: i16[n*k] = empty(n*k, dtype=int32) + A: i16[n*k] = empty(n*k, dtype=int16) i: i32; j: i32 for j in range(k): for i in range(n): A[j*n+i] = i16((i+j)) def fill_B(k: i32, n: i32) -> None: - B: i16[k*n] = empty(k*n, dtype=int32) + B: i16[k*n] = empty(k*n, dtype=int16) i: i32; j: i32 for j in range(k): for i in range(n): @@ -17,7 +17,7 @@ def fill_B(k: i32, n: i32) -> None: def fill_C(k: i32, n: i32, b: CPtr) -> None: nk: i32 = n * k - C: i16[nk] = empty(nk, dtype=int32) + C: i16[nk] = empty(nk, dtype=int16) i: i32; j: i32 for j in range(k): for i in range(n): From 289e6e2f83b472a35e31708e36eb202971cc9129 Mon Sep 17 00:00:00 2001 From: Shaikh Ubaid Date: Thu, 24 Aug 2023 23:52:55 +0530 Subject: [PATCH 16/18] TEST: Make err bound less stricter for elemental_02 Previously, the test was using float64 (which is the default value for dtype). After providing the value of dtype=float32 the test seems to fail sometimes. Therefore, making the error bound less stricter. --- integration_tests/elemental_02.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration_tests/elemental_02.py b/integration_tests/elemental_02.py index 2c73cecd19..e0df66ea50 100644 --- a/integration_tests/elemental_02.py +++ b/integration_tests/elemental_02.py @@ -39,7 +39,7 @@ def elemental_tan32(): i: i32 j: i32 eps: f32 - eps = f32(1e-6) + eps = f32(1e-4) for i in range(25): theta1d[i] = f32(i + 1) From a3151c614e77d2a2df1e33236bd72196c72d1281 Mon Sep 17 00:00:00 2001 From: Shaikh Ubaid Date: Mon, 28 Aug 2023 22:32:24 +0530 Subject: [PATCH 17/18] ASRUtils: Do not encode start dimensions --- src/libasr/asr_utils.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libasr/asr_utils.h b/src/libasr/asr_utils.h index 60db756019..bec72ef52b 100644 --- a/src/libasr/asr_utils.h +++ b/src/libasr/asr_utils.h @@ -1095,8 +1095,8 @@ static inline std::string type_encode_dims(size_t n_dims, ASR::dimension_t* m_di for( size_t i = 0; i < n_dims; i++ ) { ASR::dimension_t dim = m_dims[i]; dims_str += "["; - dims_str += extract_dim_value(dim.m_start); - dims_str += ","; + // dims_str += extract_dim_value(dim.m_start); + // dims_str += ","; dims_str += extract_dim_value(dim.m_length); dims_str += "]"; } From d0b31d5da733bcf67d9ef707d4a176ab1a9dc4cc Mon Sep 17 00:00:00 2001 From: Shaikh Ubaid Date: Thu, 24 Aug 2023 22:20:57 +0530 Subject: [PATCH 18/18] TEST: Update reference tests --- .../reference/asr-array_01_decl-39cf894.json | 2 +- .../asr-array_01_decl-39cf894.stdout | 100 ++++++- .../reference/asr-array_02_decl-e8f6874.json | 4 +- .../asr-array_02_decl-e8f6874.stdout | 104 ++++++- tests/reference/asr-bindc_02-bc1a7ea.json | 2 +- tests/reference/asr-bindc_02-bc1a7ea.stdout | 14 + tests/reference/asr-bindc_04-06bd800.json | 4 +- tests/reference/asr-bindc_04-06bd800.stderr | 2 +- tests/reference/asr-cast-435c233.json | 2 +- tests/reference/asr-cast-435c233.stdout | 34 +++ tests/reference/asr-elemental_01-b58df26.json | 4 +- .../reference/asr-elemental_01-b58df26.stdout | 256 +++++++++++++++++- .../asr-generics_array_01-682b1b2.json | 4 +- .../asr-generics_array_01-682b1b2.stdout | 14 + .../asr-generics_array_02-22c8dc1.json | 4 +- .../asr-generics_array_02-22c8dc1.stdout | 110 +++++++- .../asr-generics_array_03-fb3706c.json | 4 +- .../asr-generics_array_03-fb3706c.stdout | 124 ++++++++- tests/reference/asr-structs_05-fa98307.json | 2 +- tests/reference/asr-structs_05-fa98307.stdout | 16 ++ tests/reference/asr-test_dict2-4587f02.json | 2 +- tests/reference/asr-test_dict2-4587f02.stderr | 4 +- .../reference/asr-test_numpy_03-e600a49.json | 4 +- .../asr-test_numpy_03-e600a49.stdout | 200 +++++++++++++- tests/reference/asr-vec_01-66ac423.json | 4 +- tests/reference/asr-vec_01-66ac423.stdout | 30 +- .../pass_loop_vectorise-vec_01-be9985e.json | 4 +- .../pass_loop_vectorise-vec_01-be9985e.stdout | 38 ++- 28 files changed, 1047 insertions(+), 45 deletions(-) diff --git a/tests/reference/asr-array_01_decl-39cf894.json b/tests/reference/asr-array_01_decl-39cf894.json index 825d79b97f..e941aee6f8 100644 --- a/tests/reference/asr-array_01_decl-39cf894.json +++ b/tests/reference/asr-array_01_decl-39cf894.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-array_01_decl-39cf894.stdout", - "stdout_hash": "b45d33de49ca7e90f8327f100d88a858c8449acf8d8fa2bc527b346f", + "stdout_hash": "137a0c427925ba7da2e7151f2cf52bfa9a64fede11fe8d2653f20b64", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-array_01_decl-39cf894.stdout b/tests/reference/asr-array_01_decl-39cf894.stdout index da599193dd..6b949b3767 100644 --- a/tests/reference/asr-array_01_decl-39cf894.stdout +++ b/tests/reference/asr-array_01_decl-39cf894.stdout @@ -779,7 +779,105 @@ accept_f32_array accept_f64_array] [] - [(Print + [(= + (Var 206 ai16) + (ArrayConstant + [] + (Array + (Integer 2) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 3 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (= + (Var 206 ai32) + (ArrayConstant + [] + (Array + (Integer 4) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 3 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (= + (Var 206 ai64) + (ArrayConstant + [] + (Array + (Integer 8) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 10 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (= + (Var 206 af32) + (ArrayConstant + [] + (Array + (Real 4) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 3 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (= + (Var 206 af64) + (ArrayConstant + [] + (Array + (Real 8) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 10 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (= + (Var 206 ac32) + (ArrayConstant + [] + (Array + (Complex 4) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 3 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (= + (Var 206 ac64) + (ArrayConstant + [] + (Array + (Complex 8) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 10 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (Print () [(FunctionCall 2 accept_i16_array diff --git a/tests/reference/asr-array_02_decl-e8f6874.json b/tests/reference/asr-array_02_decl-e8f6874.json index ca47548f8a..5e35c0376d 100644 --- a/tests/reference/asr-array_02_decl-e8f6874.json +++ b/tests/reference/asr-array_02_decl-e8f6874.json @@ -2,11 +2,11 @@ "basename": "asr-array_02_decl-e8f6874", "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", "infile": "tests/../integration_tests/array_02_decl.py", - "infile_hash": "8daa77dd2d5fe6c6f5f3ce867746c5e13290305ef7e1723ac9669285", + "infile_hash": "9a398864499c7a3b4e2a480faf3a5dccaa65f9771a8de27f55f11ca4", "outfile": null, "outfile_hash": null, "stdout": "asr-array_02_decl-e8f6874.stdout", - "stdout_hash": "40e73d0d895210f7571f8a31ef8d426401f5cb57819271790fb4f7d6", + "stdout_hash": "6d98d2f4ac58c6ca1bc2b750ba97877dc53c41604be606b931fee5b5", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-array_02_decl-e8f6874.stdout b/tests/reference/asr-array_02_decl-e8f6874.stdout index 2e28134ef3..d51a7871c5 100644 --- a/tests/reference/asr-array_02_decl-e8f6874.stdout +++ b/tests/reference/asr-array_02_decl-e8f6874.stdout @@ -581,7 +581,109 @@ accept_multidim_f32_array accept_multidim_f64_array] [] - [(Print + [(= + (Var 204 ai32) + (ArrayConstant + [] + (Array + (Integer 4) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 3 (Integer 4))) + ((IntegerConstant 0 (Integer 4)) + (IntegerConstant 3 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (= + (Var 204 ai64) + (ArrayConstant + [] + (Array + (Integer 8) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 10 (Integer 4))) + ((IntegerConstant 0 (Integer 4)) + (IntegerConstant 10 (Integer 4))) + ((IntegerConstant 0 (Integer 4)) + (IntegerConstant 10 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (= + (Var 204 af32) + (ArrayConstant + [] + (Array + (Real 4) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 3 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (= + (Var 204 af64) + (ArrayConstant + [] + (Array + (Real 8) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 10 (Integer 4))) + ((IntegerConstant 0 (Integer 4)) + (IntegerConstant 4 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (= + (Var 204 ac32) + (ArrayConstant + [] + (Array + (Complex 4) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 3 (Integer 4))) + ((IntegerConstant 0 (Integer 4)) + (IntegerConstant 5 (Integer 4))) + ((IntegerConstant 0 (Integer 4)) + (IntegerConstant 99 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (= + (Var 204 ac64) + (ArrayConstant + [] + (Array + (Complex 8) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 10 (Integer 4))) + ((IntegerConstant 0 (Integer 4)) + (IntegerConstant 13 (Integer 4))) + ((IntegerConstant 0 (Integer 4)) + (IntegerConstant 11 (Integer 4))) + ((IntegerConstant 0 (Integer 4)) + (IntegerConstant 16 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (Print () [(FunctionCall 2 accept_multidim_i32_array diff --git a/tests/reference/asr-bindc_02-bc1a7ea.json b/tests/reference/asr-bindc_02-bc1a7ea.json index a31c193d76..b64888ebd3 100644 --- a/tests/reference/asr-bindc_02-bc1a7ea.json +++ b/tests/reference/asr-bindc_02-bc1a7ea.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-bindc_02-bc1a7ea.stdout", - "stdout_hash": "e7c1aac9ae8d0cc269135f3d79b99fbda0574b09d8d7d20bced754ec", + "stdout_hash": "26ddb69777a0721425e5264d3958b187bc23290470d872b10f7b341a", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-bindc_02-bc1a7ea.stdout b/tests/reference/asr-bindc_02-bc1a7ea.stdout index 02c6ea5e87..a26794ab41 100644 --- a/tests/reference/asr-bindc_02-bc1a7ea.stdout +++ b/tests/reference/asr-bindc_02-bc1a7ea.stdout @@ -164,6 +164,20 @@ ) () ) + (= + (Var 200 y) + (ArrayConstant + [] + (Array + (Integer 2) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 2 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) (= (ArrayItem (Var 200 y) diff --git a/tests/reference/asr-bindc_04-06bd800.json b/tests/reference/asr-bindc_04-06bd800.json index bb9b63077c..4772e98aa9 100644 --- a/tests/reference/asr-bindc_04-06bd800.json +++ b/tests/reference/asr-bindc_04-06bd800.json @@ -2,12 +2,12 @@ "basename": "asr-bindc_04-06bd800", "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", "infile": "tests/errors/bindc_04.py", - "infile_hash": "cf66037fcd7e8cfdd63dc5800b73e5c398afda99cf83ed51a6e70c51", + "infile_hash": "009fad63ac85061e603f011869c2439b67409edcf8cc633d1fde9013", "outfile": null, "outfile_hash": null, "stdout": null, "stdout_hash": null, "stderr": "asr-bindc_04-06bd800.stderr", - "stderr_hash": "3468ddf2bd723ff316c68d930a74ca8cad2dc3b4458bee1028752848", + "stderr_hash": "20c105d0189cd06a197a6b1dda073a58f5c8ee0104230cf187960c46", "returncode": 2 } \ No newline at end of file diff --git a/tests/reference/asr-bindc_04-06bd800.stderr b/tests/reference/asr-bindc_04-06bd800.stderr index 73a520c196..1a05ab5e55 100644 --- a/tests/reference/asr-bindc_04-06bd800.stderr +++ b/tests/reference/asr-bindc_04-06bd800.stderr @@ -1,5 +1,5 @@ semantic error: Only those local variables which can be reduced to compile time constant should be used in dimensions of an array. --> tests/errors/bindc_04.py:20:12 | -20 | C: i16[nk] = empty(nk, dtype=int32) +20 | C: i16[nk] = empty(nk, dtype=int16) | ^^ diff --git a/tests/reference/asr-cast-435c233.json b/tests/reference/asr-cast-435c233.json index f4296b9da0..f43d66172e 100644 --- a/tests/reference/asr-cast-435c233.json +++ b/tests/reference/asr-cast-435c233.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-cast-435c233.stdout", - "stdout_hash": "fe198b3570faed74e1d6babc91b93c715f90a21cf5e19b40351e3299", + "stdout_hash": "601d0fda929bc1ee47ec591680476f69f32af980624d2fd504094091", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-cast-435c233.stdout b/tests/reference/asr-cast-435c233.stdout index 3227a8b72f..813f39ee04 100644 --- a/tests/reference/asr-cast-435c233.stdout +++ b/tests/reference/asr-cast-435c233.stdout @@ -185,6 +185,40 @@ ) () ) + (= + (Var 3 x) + (ListConstant + [] + (List + (Character 1 -2 ()) + ) + ) + () + ) + (= + (Var 3 x) + (FunctionCall + 3 list + () + [((ListConstant + [] + (List + (Character 1 -2 ()) + ) + ))] + (List + (Character 1 -2 ()) + ) + (ListConstant + [] + (List + (Character 1 -2 ()) + ) + ) + () + ) + () + ) (= (Var 3 x) (FunctionCall diff --git a/tests/reference/asr-elemental_01-b58df26.json b/tests/reference/asr-elemental_01-b58df26.json index b08b7d9464..8b0b1daea7 100644 --- a/tests/reference/asr-elemental_01-b58df26.json +++ b/tests/reference/asr-elemental_01-b58df26.json @@ -2,11 +2,11 @@ "basename": "asr-elemental_01-b58df26", "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", "infile": "tests/../integration_tests/elemental_01.py", - "infile_hash": "52f31862d51b5fa967b8eafbaf9335d38a6ba9a480d9ea4cda212ace", + "infile_hash": "1d1eb8ce26df5817c1e474e4f69b0b96e53df362a31f1b722efaadf0", "outfile": null, "outfile_hash": null, "stdout": "asr-elemental_01-b58df26.stdout", - "stdout_hash": "6fd3b9bf7ded59e56672127135e71ffe94a3e2715eb5ae6c1d77ea82", + "stdout_hash": "4b612dbd2c85f1c034649fea72db6f24742e86f41b5fef2d6924125b", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-elemental_01-b58df26.stdout b/tests/reference/asr-elemental_01-b58df26.stdout index 2f65df2e15..791d04415e 100644 --- a/tests/reference/asr-elemental_01-b58df26.stdout +++ b/tests/reference/asr-elemental_01-b58df26.stdout @@ -193,7 +193,39 @@ [cos@__lpython_overloaded_0__cos verify2d] [] - [(DoLoop + [(= + (Var 208 array2d) + (ArrayConstant + [] + (Array + (Real 8) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 256 (Integer 4))) + ((IntegerConstant 0 (Integer 4)) + (IntegerConstant 64 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (= + (Var 208 cos2d) + (ArrayConstant + [] + (Array + (Real 8) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 256 (Integer 4))) + ((IntegerConstant 0 (Integer 4)) + (IntegerConstant 64 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (DoLoop () ((Var 208 i) (IntegerConstant 0 (Integer 4)) @@ -456,7 +488,49 @@ ) [verify1d_mul] [] - [(DoLoop + [(= + (Var 206 array_a) + (ArrayConstant + [] + (Array + (Real 8) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 100 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (= + (Var 206 array_b) + (ArrayConstant + [] + (Array + (Real 8) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 100 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (= + (Var 206 array_c) + (ArrayConstant + [] + (Array + (Real 8) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 100 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (DoLoop () ((Var 206 i) (IntegerConstant 0 (Integer 4)) @@ -816,7 +890,35 @@ sin@__lpython_overloaded_0__sin verifynd] [] - [(DoLoop + [(= + (Var 207 array1d) + (ArrayConstant + [] + (Array + (Real 4) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 256 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (= + (Var 207 sin1d) + (ArrayConstant + [] + (Array + (Real 4) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 256 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (DoLoop () ((Var 207 i) (IntegerConstant 0 (Integer 4)) @@ -906,6 +1008,42 @@ ((IntegerConstant 256 (Integer 4)))] () ) + (= + (Var 207 arraynd) + (ArrayConstant + [] + (Array + (Real 8) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 256 (Integer 4))) + ((IntegerConstant 0 (Integer 4)) + (IntegerConstant 64 (Integer 4))) + ((IntegerConstant 0 (Integer 4)) + (IntegerConstant 16 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (= + (Var 207 sinnd) + (ArrayConstant + [] + (Array + (Real 8) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 256 (Integer 4))) + ((IntegerConstant 0 (Integer 4)) + (IntegerConstant 64 (Integer 4))) + ((IntegerConstant 0 (Integer 4)) + (IntegerConstant 16 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) (DoLoop () ((Var 207 i) @@ -1200,7 +1338,49 @@ ) [verify1d_sum] [] - [(DoLoop + [(= + (Var 205 array_a) + (ArrayConstant + [] + (Array + (Real 8) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 100 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (= + (Var 205 array_b) + (ArrayConstant + [] + (Array + (Real 8) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 100 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (= + (Var 205 array_c) + (ArrayConstant + [] + (Array + (Real 8) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 100 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (DoLoop () ((Var 205 i) (IntegerConstant 0 (Integer 4)) @@ -1610,6 +1790,60 @@ ) () ) + (= + (Var 209 arraynd) + (ArrayConstant + [] + (Array + (Real 4) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 64 (Integer 4))) + ((IntegerConstant 0 (Integer 4)) + (IntegerConstant 32 (Integer 4))) + ((IntegerConstant 0 (Integer 4)) + (IntegerConstant 8 (Integer 4))) + ((IntegerConstant 0 (Integer 4)) + (IntegerConstant 4 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (= + (Var 209 observed) + (ArrayConstant + [] + (Array + (Real 4) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 64 (Integer 4))) + ((IntegerConstant 0 (Integer 4)) + (IntegerConstant 32 (Integer 4))) + ((IntegerConstant 0 (Integer 4)) + (IntegerConstant 8 (Integer 4))) + ((IntegerConstant 0 (Integer 4)) + (IntegerConstant 4 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (= + (Var 209 observed1d) + (ArrayConstant + [] + (Array + (Real 4) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 65536 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) (DoLoop () ((Var 209 i) @@ -1815,6 +2049,20 @@ ) () ) + (= + (Var 209 newshape) + (ArrayConstant + [] + (Array + (Integer 4) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 1 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) (= (ArrayItem (Var 209 newshape) diff --git a/tests/reference/asr-generics_array_01-682b1b2.json b/tests/reference/asr-generics_array_01-682b1b2.json index 7b8f3ac990..0242bdd484 100644 --- a/tests/reference/asr-generics_array_01-682b1b2.json +++ b/tests/reference/asr-generics_array_01-682b1b2.json @@ -2,11 +2,11 @@ "basename": "asr-generics_array_01-682b1b2", "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", "infile": "tests/../integration_tests/generics_array_01.py", - "infile_hash": "c6df2de74d7c7d6c34034bba81ec72f26fb3fbab9f6651f0caced593", + "infile_hash": "6e943dd0e26ab4d1ffb6ed6909a365b4135b6f5295957b2478cfb479", "outfile": null, "outfile_hash": null, "stdout": "asr-generics_array_01-682b1b2.stdout", - "stdout_hash": "a775edc9db3eb3909fe9e1d7738fac8ba0bbf37b539dcca81dfa0e9e", + "stdout_hash": "b3a9a482b35d36061d76f5383b2e89c56e884351e8e118dd7133a508", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-generics_array_01-682b1b2.stdout b/tests/reference/asr-generics_array_01-682b1b2.stdout index 2a2afe2d98..863e45d5f1 100644 --- a/tests/reference/asr-generics_array_01-682b1b2.stdout +++ b/tests/reference/asr-generics_array_01-682b1b2.stdout @@ -370,6 +370,20 @@ [__asr_generic_f_0] [] [(= + (Var 201 array) + (ArrayConstant + [] + (Array + (Integer 4) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 1 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (= (Var 201 x) (IntegerConstant 69 (Integer 4)) () diff --git a/tests/reference/asr-generics_array_02-22c8dc1.json b/tests/reference/asr-generics_array_02-22c8dc1.json index 27f4ed59a4..f9d77dee08 100644 --- a/tests/reference/asr-generics_array_02-22c8dc1.json +++ b/tests/reference/asr-generics_array_02-22c8dc1.json @@ -2,11 +2,11 @@ "basename": "asr-generics_array_02-22c8dc1", "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", "infile": "tests/../integration_tests/generics_array_02.py", - "infile_hash": "5dd7062ca6070e6bb8b4f489688532981af7fed12b494315d54f3c2c", + "infile_hash": "54b5f1d4b8fc7543c292ac0d6f7a39939816a657173937fa7dc02f07", "outfile": null, "outfile_hash": null, "stdout": "asr-generics_array_02-22c8dc1.stdout", - "stdout_hash": "09d9897aaa20a1b3c1c89d8738012e8294157d00c1c8f5051e397386", + "stdout_hash": "2132824b968d01dc0f0c0943bbdeb17e3c6a04caf2775065a397e1b2", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-generics_array_02-22c8dc1.stdout b/tests/reference/asr-generics_array_02-22c8dc1.stdout index 83ce5d8e92..f1ecb28551 100644 --- a/tests/reference/asr-generics_array_02-22c8dc1.stdout +++ b/tests/reference/asr-generics_array_02-22c8dc1.stdout @@ -165,7 +165,23 @@ [(Var 206 n) (Var 206 a) (Var 206 b)] - [(DoLoop + [(= + (Var 206 r) + (ArrayConstant + [] + (Array + (TypeParameter + T + ) + [((IntegerConstant 0 (Integer 4)) + (Var 206 n))] + PointerToDataArray + ) + RowMajor + ) + () + ) + (DoLoop () ((Var 206 i) (IntegerConstant 0 (Integer 4)) @@ -375,7 +391,23 @@ [(Var 207 n) (Var 207 a) (Var 207 b)] - [(DoLoop + [(= + (Var 207 r) + (ArrayConstant + [] + (Array + (TypeParameter + T + ) + [((IntegerConstant 0 (Integer 4)) + (Var 207 n))] + PointerToDataArray + ) + RowMajor + ) + () + ) + (DoLoop () ((Var 207 i) (IntegerConstant 0 (Integer 4)) @@ -905,7 +937,23 @@ [(Var 203 n) (Var 203 a) (Var 203 b)] - [(DoLoop + [(= + (Var 203 r) + (ArrayConstant + [] + (Array + (TypeParameter + T + ) + [((IntegerConstant 0 (Integer 4)) + (Var 203 n))] + PointerToDataArray + ) + RowMajor + ) + () + ) + (DoLoop () ((Var 203 i) (IntegerConstant 0 (Integer 4)) @@ -1094,6 +1142,20 @@ __asr_generic_g_1] [] [(= + (Var 204 a_int) + (ArrayConstant + [] + (Array + (Integer 4) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 1 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (= (ArrayItem (Var 204 a_int) [(() @@ -1106,6 +1168,20 @@ (IntegerConstant 400 (Integer 4)) () ) + (= + (Var 204 b_int) + (ArrayConstant + [] + (Array + (Integer 4) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 1 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) (= (ArrayItem (Var 204 b_int) @@ -1149,6 +1225,20 @@ ))] () ) + (= + (Var 204 a_float) + (ArrayConstant + [] + (Array + (Real 4) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 1 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) (= (ArrayItem (Var 204 a_float) @@ -1173,6 +1263,20 @@ ) () ) + (= + (Var 204 b_float) + (ArrayConstant + [] + (Array + (Real 4) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 1 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) (= (ArrayItem (Var 204 b_float) diff --git a/tests/reference/asr-generics_array_03-fb3706c.json b/tests/reference/asr-generics_array_03-fb3706c.json index 809e16c414..b635abef38 100644 --- a/tests/reference/asr-generics_array_03-fb3706c.json +++ b/tests/reference/asr-generics_array_03-fb3706c.json @@ -2,11 +2,11 @@ "basename": "asr-generics_array_03-fb3706c", "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", "infile": "tests/../integration_tests/generics_array_03.py", - "infile_hash": "3d5fbb269900547c29a6a63155177215bffd56721e0285671b6129da", + "infile_hash": "5b415ae64a527ce3ab3b6878141238e227258bc2b2b8c37af6d23ff5", "outfile": null, "outfile_hash": null, "stdout": "asr-generics_array_03-fb3706c.stdout", - "stdout_hash": "86d2c72679993c975ec6e7b98748749863fb5db1dfda78010ac7207b", + "stdout_hash": "34635ce31c2595c83083daa522e86fa0b4fa7e1b9916dfa49808583f", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-generics_array_03-fb3706c.stdout b/tests/reference/asr-generics_array_03-fb3706c.stdout index 70b397f227..93e1c3820b 100644 --- a/tests/reference/asr-generics_array_03-fb3706c.stdout +++ b/tests/reference/asr-generics_array_03-fb3706c.stdout @@ -259,7 +259,25 @@ (Var 207 m) (Var 207 a) (Var 207 b)] - [(DoLoop + [(= + (Var 207 r) + (ArrayConstant + [] + (Array + (TypeParameter + T + ) + [((IntegerConstant 0 (Integer 4)) + (Var 207 n)) + ((IntegerConstant 0 (Integer 4)) + (Var 207 m))] + PointerToDataArray + ) + RowMajor + ) + () + ) + (DoLoop () ((Var 207 i) (IntegerConstant 0 (Integer 4)) @@ -588,7 +606,25 @@ (Var 208 m) (Var 208 a) (Var 208 b)] - [(DoLoop + [(= + (Var 208 r) + (ArrayConstant + [] + (Array + (TypeParameter + T + ) + [((IntegerConstant 0 (Integer 4)) + (Var 208 n)) + ((IntegerConstant 0 (Integer 4)) + (Var 208 m))] + PointerToDataArray + ) + RowMajor + ) + () + ) + (DoLoop () ((Var 208 i) (IntegerConstant 0 (Integer 4)) @@ -1241,7 +1277,25 @@ (Var 203 m) (Var 203 a) (Var 203 b)] - [(DoLoop + [(= + (Var 203 r) + (ArrayConstant + [] + (Array + (TypeParameter + T + ) + [((IntegerConstant 0 (Integer 4)) + (Var 203 n)) + ((IntegerConstant 0 (Integer 4)) + (Var 203 m))] + PointerToDataArray + ) + RowMajor + ) + () + ) + (DoLoop () ((Var 203 i) (IntegerConstant 0 (Integer 4)) @@ -1527,6 +1581,22 @@ __asr_generic_g_1] [] [(= + (Var 204 a_int) + (ArrayConstant + [] + (Array + (Integer 4) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 1 (Integer 4))) + ((IntegerConstant 0 (Integer 4)) + (IntegerConstant 1 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (= (ArrayItem (Var 204 a_int) [(() @@ -1542,6 +1612,22 @@ (IntegerConstant 400 (Integer 4)) () ) + (= + (Var 204 b_int) + (ArrayConstant + [] + (Array + (Integer 4) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 1 (Integer 4))) + ((IntegerConstant 0 (Integer 4)) + (IntegerConstant 1 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) (= (ArrayItem (Var 204 b_int) @@ -1606,6 +1692,22 @@ ) () ) + (= + (Var 204 a_float) + (ArrayConstant + [] + (Array + (Real 4) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 1 (Integer 4))) + ((IntegerConstant 0 (Integer 4)) + (IntegerConstant 1 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) (= (ArrayItem (Var 204 a_float) @@ -1630,6 +1732,22 @@ ) () ) + (= + (Var 204 b_float) + (ArrayConstant + [] + (Array + (Real 4) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 1 (Integer 4))) + ((IntegerConstant 0 (Integer 4)) + (IntegerConstant 1 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) (= (ArrayItem (Var 204 b_float) diff --git a/tests/reference/asr-structs_05-fa98307.json b/tests/reference/asr-structs_05-fa98307.json index 2fd40b217c..22710dd31d 100644 --- a/tests/reference/asr-structs_05-fa98307.json +++ b/tests/reference/asr-structs_05-fa98307.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "asr-structs_05-fa98307.stdout", - "stdout_hash": "9a947180189938b72d890313d7745a3f4a41d546b6dba9e19e7a9c20", + "stdout_hash": "e0f42936c8e2ba9b29e2bab6eb4d0ed2609305ea3fed9f058a9e53b1", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-structs_05-fa98307.stdout b/tests/reference/asr-structs_05-fa98307.stdout index c2f191904d..f9b4b44627 100644 --- a/tests/reference/asr-structs_05-fa98307.stdout +++ b/tests/reference/asr-structs_05-fa98307.stdout @@ -233,6 +233,22 @@ update_2] [] [(= + (Var 204 y) + (ArrayConstant + [] + (Array + (Struct + 2 A + ) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 2 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (= (ArrayItem (Var 204 y) [(() diff --git a/tests/reference/asr-test_dict2-4587f02.json b/tests/reference/asr-test_dict2-4587f02.json index 296c0bbe09..270d51c545 100644 --- a/tests/reference/asr-test_dict2-4587f02.json +++ b/tests/reference/asr-test_dict2-4587f02.json @@ -8,6 +8,6 @@ "stdout": null, "stdout_hash": null, "stderr": "asr-test_dict2-4587f02.stderr", - "stderr_hash": "00d00b6323fa903c677ea2bf60b453ed2ad4cc0f0aa1886154359dd8", + "stderr_hash": "9de5d75622644a0cb98bdd3f73249772c25c293f508343b31cc34607", "returncode": 2 } \ No newline at end of file diff --git a/tests/reference/asr-test_dict2-4587f02.stderr b/tests/reference/asr-test_dict2-4587f02.stderr index 465bf0562d..dde39a40a8 100644 --- a/tests/reference/asr-test_dict2-4587f02.stderr +++ b/tests/reference/asr-test_dict2-4587f02.stderr @@ -1,5 +1,5 @@ -semantic error: Type mismatch in dictionary key, the types must be compatible +semantic error: Key type should be 'str' instead of 'i32' --> tests/errors/test_dict2.py:4:7 | 4 | y[1] = -3 - | ^ type mismatch (found: 'i32', expected: 'str') + | ^ diff --git a/tests/reference/asr-test_numpy_03-e600a49.json b/tests/reference/asr-test_numpy_03-e600a49.json index ddbf4a99ac..5a0b26f3d0 100644 --- a/tests/reference/asr-test_numpy_03-e600a49.json +++ b/tests/reference/asr-test_numpy_03-e600a49.json @@ -2,11 +2,11 @@ "basename": "asr-test_numpy_03-e600a49", "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", "infile": "tests/../integration_tests/test_numpy_03.py", - "infile_hash": "c0ff0b1ddaee26393573088dbfd8babf9e0c95c3b2cfddbe36c2b633", + "infile_hash": "5c3ea7436668441c056bd576ea77cdfb49e44a5f0e95088d0f62184e", "outfile": null, "outfile_hash": null, "stdout": "asr-test_numpy_03-e600a49.stdout", - "stdout_hash": "835121cdfc4e1a33435c47fa2170d19d4a0dfc986b2a72dbbd6e944f", + "stdout_hash": "e25ea5256401169097ee80115a3e30f83aa58693f36a9efeb7210de0", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-test_numpy_03-e600a49.stdout b/tests/reference/asr-test_numpy_03-e600a49.stdout index e481348c05..923e73965e 100644 --- a/tests/reference/asr-test_numpy_03-e600a49.stdout +++ b/tests/reference/asr-test_numpy_03-e600a49.stdout @@ -382,6 +382,20 @@ ) () ) + (= + (Var 201 b) + (ArrayConstant + [] + (Array + (Real 8) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 256 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) (DoLoop () ((Var 201 k) @@ -399,6 +413,36 @@ 201 block )] ) + (= + (Var 201 a) + (ArrayConstant + [] + (Array + (Real 8) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 16 (Integer 4))) + ((IntegerConstant 0 (Integer 4)) + (IntegerConstant 16 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (= + (Var 201 newshape) + (ArrayConstant + [] + (Array + (Integer 4) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 2 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) (= (ArrayItem (Var 201 newshape) @@ -530,6 +574,38 @@ )] )] ) + (= + (Var 201 c) + (ArrayConstant + [] + (Array + (Real 8) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 16 (Integer 4))) + ((IntegerConstant 0 (Integer 4)) + (IntegerConstant 16 (Integer 4))) + ((IntegerConstant 0 (Integer 4)) + (IntegerConstant 16 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (= + (Var 201 newshape1) + (ArrayConstant + [] + (Array + (Integer 4) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 3 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) (= (ArrayItem (Var 201 newshape1) @@ -1227,6 +1303,34 @@ ) () ) + (= + (Var 200 b) + (ArrayConstant + [] + (Array + (Real 8) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 256 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (= + (Var 200 newshape) + (ArrayConstant + [] + (Array + (Integer 4) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 1 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) (= (ArrayItem (Var 200 newshape) @@ -1283,6 +1387,42 @@ 200 block )] ) + (= + (Var 200 c) + (ArrayConstant + [] + (Array + (Real 8) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 16 (Integer 4))) + ((IntegerConstant 0 (Integer 4)) + (IntegerConstant 16 (Integer 4))) + ((IntegerConstant 0 (Integer 4)) + (IntegerConstant 16 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (= + (Var 200 c) + (ArrayConstant + [] + (Array + (Real 8) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 16 (Integer 4))) + ((IntegerConstant 0 (Integer 4)) + (IntegerConstant 16 (Integer 4))) + ((IntegerConstant 0 (Integer 4)) + (IntegerConstant 16 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) (DoLoop () ((Var 200 i) @@ -1367,6 +1507,34 @@ )] )] ) + (= + (Var 200 d) + (ArrayConstant + [] + (Array + (Real 8) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 4096 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (= + (Var 200 newshape1) + (ArrayConstant + [] + (Array + (Integer 4) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 1 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) (= (ArrayItem (Var 200 newshape1) @@ -1712,7 +1880,23 @@ test_nd_to_1d test_1d_to_nd] [] - [(DoLoop + [(= + (Var 202 a) + (ArrayConstant + [] + (Array + (Real 8) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 16 (Integer 4))) + ((IntegerConstant 0 (Integer 4)) + (IntegerConstant 16 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (DoLoop () ((Var 202 i) (IntegerConstant 0 (Integer 4)) @@ -1793,6 +1977,20 @@ ))] () ) + (= + (Var 202 d) + (ArrayConstant + [] + (Array + (Real 8) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 4096 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) (DoLoop () ((Var 202 l) diff --git a/tests/reference/asr-vec_01-66ac423.json b/tests/reference/asr-vec_01-66ac423.json index 446ef14a6c..c80b15245d 100644 --- a/tests/reference/asr-vec_01-66ac423.json +++ b/tests/reference/asr-vec_01-66ac423.json @@ -2,11 +2,11 @@ "basename": "asr-vec_01-66ac423", "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", "infile": "tests/../integration_tests/vec_01.py", - "infile_hash": "b22cabe2248cf58c7ffaad83dd8dc5b2433f244ee23b0703b536547b", + "infile_hash": "f85ca108780c53c54878d119822d56fb834cf4b5121511cbaca2c2fe", "outfile": null, "outfile_hash": null, "stdout": "asr-vec_01-66ac423.stdout", - "stdout_hash": "a8b2e65b405cfab777d35efd6f739b9bd4041478a831ba3470468a54", + "stdout_hash": "3402504a3f0b4a88086bfc539e39621b54ab4af006d2492d60079802", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/asr-vec_01-66ac423.stdout b/tests/reference/asr-vec_01-66ac423.stdout index a623b96d7d..76ebf063c6 100644 --- a/tests/reference/asr-vec_01-66ac423.stdout +++ b/tests/reference/asr-vec_01-66ac423.stdout @@ -124,7 +124,35 @@ ) [] [] - [(DoLoop + [(= + (Var 200 a) + (ArrayConstant + [] + (Array + (Real 8) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 9216 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (= + (Var 200 b) + (ArrayConstant + [] + (Array + (Real 8) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 9216 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (DoLoop () ((Var 200 i) (IntegerConstant 0 (Integer 4)) diff --git a/tests/reference/pass_loop_vectorise-vec_01-be9985e.json b/tests/reference/pass_loop_vectorise-vec_01-be9985e.json index 9384826e82..0b874231b3 100644 --- a/tests/reference/pass_loop_vectorise-vec_01-be9985e.json +++ b/tests/reference/pass_loop_vectorise-vec_01-be9985e.json @@ -2,11 +2,11 @@ "basename": "pass_loop_vectorise-vec_01-be9985e", "cmd": "lpython --pass=loop_vectorise --show-asr --no-color {infile} -o {outfile}", "infile": "tests/../integration_tests/vec_01.py", - "infile_hash": "b22cabe2248cf58c7ffaad83dd8dc5b2433f244ee23b0703b536547b", + "infile_hash": "f85ca108780c53c54878d119822d56fb834cf4b5121511cbaca2c2fe", "outfile": null, "outfile_hash": null, "stdout": "pass_loop_vectorise-vec_01-be9985e.stdout", - "stdout_hash": "1450eb1e82f1e03ee2c1ab8cf46b7cc5fb4a44df5af0d598b3779df3", + "stdout_hash": "9df340522b788e007b7faaab8f51ce7dc1736b0774a900c1694b86be", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/pass_loop_vectorise-vec_01-be9985e.stdout b/tests/reference/pass_loop_vectorise-vec_01-be9985e.stdout index e5181704df..1061629654 100644 --- a/tests/reference/pass_loop_vectorise-vec_01-be9985e.stdout +++ b/tests/reference/pass_loop_vectorise-vec_01-be9985e.stdout @@ -106,7 +106,7 @@ Required .false. ), - vector_copy_f64f64i32@IntrinsicOptimization: + vector_copy_f64[9216]f64[9216]i32@IntrinsicOptimization: (Function (SymbolTable 206 @@ -234,7 +234,7 @@ .false. ) }) - vector_copy_f64f64i32@IntrinsicOptimization + vector_copy_f64[9216]f64[9216]i32@IntrinsicOptimization (FunctionType [(Array (Real 8) @@ -352,9 +352,37 @@ [] .false. ) - [vector_copy_f64f64i32@IntrinsicOptimization] + [vector_copy_f64[9216]f64[9216]i32@IntrinsicOptimization] [] - [(DoLoop + [(= + (Var 200 a) + (ArrayConstant + [] + (Array + (Real 8) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 9216 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (= + (Var 200 b) + (ArrayConstant + [] + (Array + (Real 8) + [((IntegerConstant 0 (Integer 4)) + (IntegerConstant 9216 (Integer 4)))] + FixedSizeArray + ) + RowMajor + ) + () + ) + (DoLoop () ((Var 200 i) (IntegerConstant 0 (Integer 4)) @@ -390,7 +418,7 @@ (IntegerConstant 1151 (Integer 4)) (IntegerConstant 1 (Integer 4))) [(SubroutineCall - 200 vector_copy_f64f64i32@IntrinsicOptimization + 200 vector_copy_f64[9216]f64[9216]i32@IntrinsicOptimization () [((Var 200 a)) ((Var 200 b))