Skip to content

Commit

Permalink
Merge pull request #49 from czgdp1807/lc_29
Browse files Browse the repository at this point in the history
Ported ``integration_tests/arrays_op_11.f90`` from LFortran
  • Loading branch information
czgdp1807 authored Jan 4, 2024
2 parents 320a164 + b15e4c7 commit 4d42957
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
2 changes: 2 additions & 0 deletions integration_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,5 @@ RUN(NAME array_16.cpp LABELS gcc llvm NOFAST
EXTRA_ARGS --extra-arg=-I${CONDA_PREFIX}/include)
RUN(NAME array_17.cpp LABELS gcc llvm NOFAST
EXTRA_ARGS --extra-arg=-I${CONDA_PREFIX}/include)
RUN(NAME array_18.cpp LABELS gcc llvm NOFAST
EXTRA_ARGS --extra-arg=-I${CONDA_PREFIX}/include)
48 changes: 48 additions & 0 deletions integration_tests/array_18.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <iostream>
#include <cmath>
#include <xtensor/xtensor.hpp>
#include <xtensor/xfixed.hpp>
#include "xtensor/xio.hpp"

xt::xtensor<double, 1> solution() {
xt::xtensor<double, 1> x = xt::empty<double>({2});
x = {1.0, 2.0};
return x;
}

void compare_solutions(const xt::xtensor<double, 1>& x) {
xt::xtensor<double, 1> diff = xt::empty<double>({x.size()});

diff = solution() - x;

std::cout << diff << std::endl;

if (std::abs(diff(0) - 0.0) > 1e-6) {
exit(2);
}
if (std::abs(diff(0) - 0.0) > 1e-6) {
exit(2);
}

diff = x - solution();

std::cout << diff << std::endl;

if (diff(0) != 0.0) {
exit(2);
}
if (diff(1) != 0.0) {
exit(2);
}
}

int main() {

xt::xtensor<double, 1> z = xt::empty<double>({2});

std::cout << solution() << std::endl;
z = solution();
std::cout << z << std::endl;
compare_solutions(z);

}

0 comments on commit 4d42957

Please sign in to comment.