Skip to content

Commit

Permalink
Merge pull request #82 from czgdp1807/array_01
Browse files Browse the repository at this point in the history
Ported ``integration_tests/arrays_op_22.f90`` from LFortran
  • Loading branch information
czgdp1807 authored Feb 1, 2024
2 parents 1ba29d4 + d34dd55 commit f7fac14
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ RUN(NAME array_20.cpp LABELS gcc llvm NOFAST)
RUN(NAME array_21.cpp LABELS gcc llvm NOFAST)
RUN(NAME array_22.cpp LABELS gcc llvm NOFAST)
RUN(NAME array_23.cpp LABELS gcc llvm NOFAST)
RUN(NAME array_24.cpp LABELS gcc llvm NOFAST)

RUN(NAME struct_01.cpp LABELS gcc llvm NOFAST)
RUN(NAME struct_02.cpp LABELS gcc llvm NOFAST)
Expand Down
40 changes: 40 additions & 0 deletions integration_tests/array_24.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <iostream>
#include <xtensor/xtensor.hpp>
#include <xtensor/xfixed.hpp>
#include "xtensor/xio.hpp"

xt::xtensor<float, 2> copy_array(const xt::xtensor<float, 2>& input);
xt::xtensor<float, 2> twice(const xt::xtensor<float, 2>& x);

xt::xtensor<float, 2> prg(const xt::xtensor<float, 2>& arr) {
xt::xtensor<float, 2> otpt = xt::xtensor<float, 2>({arr.shape(0), arr.shape(1)});
otpt = copy_array(twice(copy_array(arr)));
return otpt;
}

xt::xtensor<float, 2> twice(const xt::xtensor<float, 2>& x) {
xt::xtensor<float, 2> y = xt::empty<float>({x.shape(0), x.shape(1)});
y = 2.0*x;
return y;
}

xt::xtensor<float, 2> copy_array(const xt::xtensor<float, 2>& input) {
xt::xtensor<float, 2> output = xt::empty<float>({input.shape(0), input.shape(1)});
output = input;
return output;
}

int main() {

xt::xtensor<float, 2> array = xt::empty<float>({10, 10});
xt::xtensor<float, 2> output = xt::empty<float>({10, 10});

array.fill(3.0);

output = prg(array);
std::cout << output << std::endl;
if( xt::any(xt::not_equal(output, 6.0)) ) {
exit(2);
}

}

0 comments on commit f7fac14

Please sign in to comment.