Skip to content

Commit f7fac14

Browse files
authored
Merge pull request #82 from czgdp1807/array_01
Ported ``integration_tests/arrays_op_22.f90`` from LFortran
2 parents 1ba29d4 + d34dd55 commit f7fac14

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

integration_tests/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ RUN(NAME array_20.cpp LABELS gcc llvm NOFAST)
206206
RUN(NAME array_21.cpp LABELS gcc llvm NOFAST)
207207
RUN(NAME array_22.cpp LABELS gcc llvm NOFAST)
208208
RUN(NAME array_23.cpp LABELS gcc llvm NOFAST)
209+
RUN(NAME array_24.cpp LABELS gcc llvm NOFAST)
209210

210211
RUN(NAME struct_01.cpp LABELS gcc llvm NOFAST)
211212
RUN(NAME struct_02.cpp LABELS gcc llvm NOFAST)

integration_tests/array_24.cpp

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include <iostream>
2+
#include <xtensor/xtensor.hpp>
3+
#include <xtensor/xfixed.hpp>
4+
#include "xtensor/xio.hpp"
5+
6+
xt::xtensor<float, 2> copy_array(const xt::xtensor<float, 2>& input);
7+
xt::xtensor<float, 2> twice(const xt::xtensor<float, 2>& x);
8+
9+
xt::xtensor<float, 2> prg(const xt::xtensor<float, 2>& arr) {
10+
xt::xtensor<float, 2> otpt = xt::xtensor<float, 2>({arr.shape(0), arr.shape(1)});
11+
otpt = copy_array(twice(copy_array(arr)));
12+
return otpt;
13+
}
14+
15+
xt::xtensor<float, 2> twice(const xt::xtensor<float, 2>& x) {
16+
xt::xtensor<float, 2> y = xt::empty<float>({x.shape(0), x.shape(1)});
17+
y = 2.0*x;
18+
return y;
19+
}
20+
21+
xt::xtensor<float, 2> copy_array(const xt::xtensor<float, 2>& input) {
22+
xt::xtensor<float, 2> output = xt::empty<float>({input.shape(0), input.shape(1)});
23+
output = input;
24+
return output;
25+
}
26+
27+
int main() {
28+
29+
xt::xtensor<float, 2> array = xt::empty<float>({10, 10});
30+
xt::xtensor<float, 2> output = xt::empty<float>({10, 10});
31+
32+
array.fill(3.0);
33+
34+
output = prg(array);
35+
std::cout << output << std::endl;
36+
if( xt::any(xt::not_equal(output, 6.0)) ) {
37+
exit(2);
38+
}
39+
40+
}

0 commit comments

Comments
 (0)