From 1191c0008b55b055b8bb855330eec1cc72e9213f Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Thu, 21 Dec 2023 16:57:10 +0530 Subject: [PATCH 1/3] Following changes have been made, DEV: Fix xt::empty in initialiser statement DEV: Fix type of ArrayItem ASR node --- src/lc/clang_ast_to_asr.h | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/lc/clang_ast_to_asr.h b/src/lc/clang_ast_to_asr.h index ce187dc..3f205c0 100644 --- a/src/lc/clang_ast_to_asr.h +++ b/src/lc/clang_ast_to_asr.h @@ -477,10 +477,7 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor 0 ) { func_name = cxx_operator_name; } else if( member_name.size() > 0 ) { + if( callee == nullptr ) { + throw std::runtime_error("Callee object not available."); + } func_name = member_name; } else { ASR::Var_t* callee_Var = ASR::down_cast(callee); @@ -667,8 +667,12 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitorgetCallee()); - ASR::expr_t* callee = ASRUtils::EXPR(tmp); + ASR::expr_t* callee = nullptr; + if( tmp != nullptr ) { + callee = ASRUtils::EXPR(tmp); + } if( check_and_handle_special_function(x, callee) ) { return true; } @@ -843,7 +847,7 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitorgetInit()); assignment_target = nullptr; - if( tmp != nullptr ) { + if( tmp != nullptr && !is_stmt_created ) { ASR::expr_t* init_val = ASRUtils::EXPR(tmp); add_reshape_if_needed(init_val, var); tmp = ASR::make_Assignment_t(al, Lloc(x), var, init_val, nullptr); @@ -1060,16 +1064,17 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitorgetNameInfo().getAsString(); - if( name == "operator<<" || name == "cout" || + ASR::symbol_t* sym = resolve_symbol(name); + if( sym == nullptr && + (name == "operator<<" || name == "cout" || name == "endl" || name == "operator()" || name == "operator+" || name == "operator=" || - name == "view" || name == "empty" ) { + name == "view" || name == "empty" || name == "printf") ) { cxx_operator_name = name; return true; } - ASR::symbol_t* sym = resolve_symbol(name); - LCOMPILERS_ASSERT(sym != nullptr); tmp = ASR::make_Var_t(al, Lloc(x), sym); is_stmt_created = false; return true; From 52169386ed7f50d1f800c797f1f51a5cc8323ced Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Thu, 21 Dec 2023 17:02:38 +0530 Subject: [PATCH 2/3] TEST: Added test for xt::xtensor<...> --- integration_tests/array_08.cpp | 44 ++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 integration_tests/array_08.cpp diff --git a/integration_tests/array_08.cpp b/integration_tests/array_08.cpp new file mode 100644 index 0000000..fa0a962 --- /dev/null +++ b/integration_tests/array_08.cpp @@ -0,0 +1,44 @@ +#include +#include +#include "xtensor/xio.hpp" +#include "xtensor/xview.hpp" + +xt::xtensor matmul( + xt::xtensor& a, + xt::xtensor& b) { + xt::xtensor ab = xt::empty({a.shape(0), b.shape(1)}); + for( int i = 0; i < a.shape(0); i++ ) { + for( int j = 0; j < b.shape(1); j++ ) { + ab(i, j) = 0; + for( int k = 0; k < a.shape(1); k++ ) { + ab(i, j) += a(i, k) * b(k, j); + } + } + } + return ab; +} + +int main() { + + xt::xtensor a = xt::empty({3, 2}); + xt::xtensor b = xt::empty({2, 3}); + xt::xtensor c = xt::empty({3, 3}); + + for( int i = 0; i < a.shape(0); i++ ) { + for( int j = 0; j < a.shape(1); j++ ) { + a(i, j) = i * a.shape(0) * j; + } + } + + for( int i = 0; i < b.shape(0); i++ ) { + for( int j = 0; j < b.shape(1); j++ ) { + b(i, j) = i * b.shape(0) * j; + } + } + + std::cout << a << b << std::endl; + c = matmul(a, b); + std::cout << c << std::endl; + + return 0; +} From e321e3a94431cf772cf32903a1c95809cd403a0a Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Thu, 21 Dec 2023 17:02:50 +0530 Subject: [PATCH 3/3] TEST: Register array_08.cpp --- integration_tests/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index cfa54fd..3e6a855 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -198,3 +198,5 @@ RUN(NAME array_06.cpp LABELS gcc llvm NOFAST EXTRA_ARGS --extra-arg=-I${CONDA_PREFIX}/include) RUN(NAME array_07.cpp LABELS gcc llvm NOFAST EXTRA_ARGS --extra-arg=-I${CONDA_PREFIX}/include) +RUN(NAME array_08.cpp LABELS gcc llvm NOFAST + EXTRA_ARGS --extra-arg=-I${CONDA_PREFIX}/include)