Skip to content

Commit 5d4abf6

Browse files
authored
Merge pull request #52 from czgdp1807/lc_32
Ported ``integration_tests/arrays_intrin_01.f90`` from LFortran and improve LC to compile it
2 parents 8395ad4 + 7141712 commit 5d4abf6

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

integration_tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,5 @@ RUN(NAME array_19.cpp LABELS gcc llvm NOFAST
218218
EXTRA_ARGS --extra-arg=-I${CONDA_PREFIX}/include)
219219
RUN(NAME array_20.cpp LABELS gcc llvm NOFAST
220220
EXTRA_ARGS --extra-arg=-I${CONDA_PREFIX}/include)
221+
RUN(NAME array_21.cpp LABELS gcc llvm NOFAST
222+
EXTRA_ARGS --extra-arg=-I${CONDA_PREFIX}/include)

integration_tests/array_21.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <iostream>
2+
#include <cmath>
3+
#include <xtensor/xtensor.hpp>
4+
#include <xtensor/xfixed.hpp>
5+
#include "xtensor/xio.hpp"
6+
7+
int main() {
8+
9+
xt::xtensor_fixed<int, xt::xshape<11>> nums_int = {5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5};
10+
xt::xtensor_fixed<double, xt::xshape<5>> nums_real = {1.5, -3.2, 4.5, 0.9, 7.2};
11+
12+
if (xt::amin(nums_int)() != -5) {
13+
exit(2);
14+
}
15+
if (xt::amax(nums_int)() != 5) {
16+
exit(2);
17+
}
18+
if (xt::amin(nums_real)() != -3.2) {
19+
exit(2);
20+
}
21+
if (xt::amax(nums_real)() != 7.2) {
22+
exit(2);
23+
}
24+
25+
std::cout << xt::amin(nums_int)() << " " << xt::amax(nums_int)() << std::endl;
26+
std::cout << xt::amin(nums_real)() << " " << xt::amax(nums_real)() << std::endl;
27+
28+
return 0;
29+
30+
}

src/lc/clang_ast_to_asr.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ enum SpecialFunc {
4646
Sin,
4747
Cos,
4848
AMax,
49+
AMin,
4950
Sum,
5051
Range,
5152
Size,
@@ -70,6 +71,7 @@ std::map<std::string, SpecialFunc> special_function_map = {
7071
{"sin", SpecialFunc::Sin},
7172
{"cos", SpecialFunc::Cos},
7273
{"amax", SpecialFunc::AMax},
74+
{"amin", SpecialFunc::AMin},
7375
{"sum", SpecialFunc::Sum},
7476
{"range", SpecialFunc::Range},
7577
{"size", SpecialFunc::Size},
@@ -626,6 +628,8 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
626628
array_indices.p, array_indices.size(),
627629
ASRUtils::extract_type(ASRUtils::expr_type(obj)),
628630
ASR::arraystorageType::RowMajor, nullptr);
631+
} else if( ASR::is_a<ASR::IntrinsicArrayFunction_t>(*obj) ) {
632+
tmp = (ASR::asr_t*) obj;
629633
} else {
630634
throw std::runtime_error("Only indexing arrays is supported for now with operator().");
631635
}
@@ -943,7 +947,15 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
943947
static_cast<int64_t>(ASRUtils::IntrinsicArrayFunctions::MaxVal),
944948
args.p, 1, 0, ASRUtils::extract_type(ASRUtils::expr_type(args.p[0])),
945949
nullptr);
946-
} else if( sf == SpecialFunc::Sum ) {
950+
} else if( sf == SpecialFunc::AMin ) {
951+
if( args.size() > 1 && args.p[1] != nullptr ) {
952+
throw std::runtime_error("dim argument not yet supported with " + func_name);
953+
}
954+
tmp = ASRUtils::make_IntrinsicArrayFunction_t_util(al, Lloc(x),
955+
static_cast<int64_t>(ASRUtils::IntrinsicArrayFunctions::MinVal),
956+
args.p, 1, 0, ASRUtils::extract_type(ASRUtils::expr_type(args.p[0])),
957+
nullptr);
958+
} else if( sf == SpecialFunc::Sum ) {
947959
if( args.size() > 1 && args.p[1] != nullptr ) {
948960
throw std::runtime_error("dim argument not yet supported with " + func_name);
949961
}
@@ -1531,7 +1543,7 @@ class ClangASTtoASRVisitor: public clang::RecursiveASTVisitor<ClangASTtoASRVisit
15311543
name == "range" || name == "pow" || name == "equal" ||
15321544
name == "operator<" || name == "operator<=" || name == "operator>=" ||
15331545
name == "operator!=" || name == "operator\"\"i" || name == "sin" ||
1534-
name == "cos" ) {
1546+
name == "cos" || name == "amin" ) {
15351547
if( sym != nullptr && ASR::is_a<ASR::Function_t>(
15361548
*ASRUtils::symbol_get_past_external(sym)) ) {
15371549
throw std::runtime_error("Special function " + name + " cannot be overshadowed yet.");

0 commit comments

Comments
 (0)