Skip to content

Commit

Permalink
Merge pull request ct-clmsn#49 from STEllAR-GROUP/array
Browse files Browse the repository at this point in the history
Adding array tests
  • Loading branch information
ct-clmsn authored May 13, 2023
2 parents 85a4ac4 + 23d85d3 commit 941ed36
Show file tree
Hide file tree
Showing 24 changed files with 498 additions and 134 deletions.
37 changes: 17 additions & 20 deletions backend/src/programtree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,26 +129,26 @@ void ArrayDeclarationExpression::emit(std::ostream & os) const {
VisitQualifierPrefix(os, qualifier);
}

os << "std::vector<";
os << "chplx::Array<";
std::visit(ScalarDeclarationExpressionVisitor{os}, akref->kind);

int range_size = 1;
const auto & rngs = akref->dom.ranges;
os << ", chplx::Domain<" << rngs.size() << "> > " << identifier << "(";

bool first = true;
for(const auto & rng : rngs) {
if (!first) {
first = false;
os << ", ";
}
if(rng.points.size() == 2) {
range_size *= ( (rng.points[1] - rng.points[0]) + rng.points[0] );
os << "chplx::Range(" << rng.points[0] << ", " << rng.points[1] << ")";
}
else if(rng.points.size() == 1) {
range_size *= rng.points[0];
else if (rng.points.size() == 1) {
os << "chplx::Range(" << rng.points[0] << ")";
}
}

if(range_size > 1) {
os << "> " << identifier << "(" << range_size << ");" << std::endl;
}
else {
os << "> " << identifier << "{};" << std::endl;
}
os << ");" << std::endl;
}

struct ArrayDeclarationLiteralExpressionVisitor {
Expand Down Expand Up @@ -209,14 +209,13 @@ void ArrayDeclarationLiteralExpression::emit(std::ostream & os) const {
// stored in the literal array then the
// loop needs to terminate
//
typelist << "std::vector<";
typelist << "chplx::Array<";

for(std::size_t i = 0; i < children_sz; ++i) {
const bool knt =
std::holds_alternative<std::shared_ptr<kind_node_type>>(children[i]);

if(knt) {
typelist << "std::vector<";
++vec_count;
}
else {
Expand All @@ -225,9 +224,7 @@ void ArrayDeclarationLiteralExpression::emit(std::ostream & os) const {
}
}

for(std::size_t i = 0; i < vec_count; ++i) {
typelist << ">";
}
typelist << ", chplx::Domain<" << vec_count + 1 << ">";

typelist << ">";

Expand Down Expand Up @@ -369,18 +366,18 @@ void FunctionCallExpression::emit(std::ostream & os) const {
std::visit(v, arguments[0]);

for(std::size_t i = 1; i < args_sz; ++i) {
fn_fmt_str += "[{}]";
fn_fmt_str += (i == 1) ? "{}" : ", {}";
Statement const& stmt = arguments[i];
ArgumentVisitor v{nullptr, std::stringstream{}};
std::visit(v, stmt);
store.push_back(v.os.str());
}

os << v.os.str() << fmt::vformat(fn_fmt_str, store);
os << v.os.str() << '(' << fmt::vformat(fn_fmt_str, store) << ')';
}
else {
for(std::size_t i = 1; i < args_sz; ++i) {
fn_fmt_str += (i == 1) ? "{}" : ",{}";
fn_fmt_str += (i == 1) ? "{}" : ", {}";
Statement const& stmt = arguments[i];
ArgumentVisitor v{nullptr, std::stringstream{}};
std::visit(v, stmt);
Expand Down
28 changes: 14 additions & 14 deletions backend/test/arr/arr.cpp.good
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ auto __thisModule::dd() {
void __thisModule::__main() {

#line 8 "arr.chpl"
std::vector<std::int64_t> k = {1, 2, 3, 4, 5};
chplx::Array<std::int64_t, chplx::Domain<1>> k = {1, 2, 3, 4, 5};
#line 9 "arr.chpl"
std::vector<std::vector<std::int64_t>> l = {{1, 2}, {3, 4}};
chplx::Array<std::int64_t, chplx::Domain<2>> l = {{1, 2}, {3, 4}};
#line 10 "arr.chpl"
std::vector<std::vector<std::int64_t>> m = {{1}, {2}, {3, 4, 5}};
chplx::Array<std::int64_t, chplx::Domain<2>> m = {{1}, {2}, {3, 4, 5}};
#line 11 "arr.chpl"
std::vector<std::vector<std::int64_t>> n = {{1, 2}, {1, 2}};
chplx::Array<std::int64_t, chplx::Domain<2>> n = {{1, 2}, {1, 2}};
#line 12 "arr.chpl"
std::vector<std::vector<std::vector<std::int64_t>>> o = {
{{1, 2}, {1, 2}, {3, 4}}, {{5, 6}, {7, 8}}};
chplx::Array<std::int64_t, chplx::Domain<3>> o = {{{1, 2}, {1, 2}, {3, 4}},
{{5, 6}, {7, 8}}};
#line 13 "arr.chpl"
std::vector<std::vector<std::int64_t>> p = {{1, 2, 3, 4, 5}};
chplx::Array<std::int64_t, chplx::Domain<2>> p = {{1, 2, 3, 4, 5}};
#line 14 "arr.chpl"
std::vector<std::vector<std::vector<std::int64_t>>> q = {{{1, 2, 3, 4, 5}}};
chplx::Array<std::int64_t, chplx::Domain<3>> q = {{{1, 2, 3, 4, 5}}};
#line 16 "arr.chpl"
bool u;
#line 17 "arr.chpl"
Expand All @@ -43,17 +43,17 @@ void __thisModule::__main() {
#line 21 "arr.chpl"
std::string z;
#line 23 "arr.chpl"
std::vector<std::int64_t> a(10);
chplx::Array<std::int64_t, chplx::Domain<1>> a(chplx::Range(1, 10));
#line 24 "arr.chpl"
std::vector<double> b(10);
chplx::Array<double, chplx::Domain<1>> b(chplx::Range(1, 10));
#line 25 "arr.chpl"
std::vector<std::complex<double>> c(10);
chplx::Array<std::complex<double>, chplx::Domain<1>> c(chplx::Range(1, 10));
#line 26 "arr.chpl"
std::vector<std::string> d(10);
chplx::Array<std::string, chplx::Domain<1>> d(chplx::Range(1, 10));
#line 27 "arr.chpl"
std::vector<std::uint8_t> e(10);
chplx::Array<std::uint8_t, chplx::Domain<1>> e(chplx::Range(1, 10));
#line 28 "arr.chpl"
std::vector<bool> f(10);
chplx::Array<bool, chplx::Domain<1>> f(chplx::Range(1, 10));
#line 30 "arr.chpl"
std::int64_t g = 1;
#line 31 "arr.chpl"
Expand Down
2 changes: 1 addition & 1 deletion backend/test/arr/arr_driver.hpp.good
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This program file was generated by the chplx compiler.
// The original Chapel program file can be found here: arr.cpp
// The original Chapel program file can be found here: arr.chpl
//
#pragma once

Expand Down
2 changes: 1 addition & 1 deletion backend/test/cfg/cfg_driver.hpp.good
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This program file was generated by the chplx compiler.
// The original Chapel program file can be found here: cfg.cpp
// The original Chapel program file can be found here: cfg.chpl
//
#pragma once

Expand Down
2 changes: 1 addition & 1 deletion backend/test/cond/cond_driver.hpp.good
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This program file was generated by the chplx compiler.
// The original Chapel program file can be found here: cond.cpp
// The original Chapel program file can be found here: cond.chpl
//
#pragma once

Expand Down
54 changes: 27 additions & 27 deletions backend/test/expr/expr.cpp.good
Original file line number Diff line number Diff line change
Expand Up @@ -114,59 +114,59 @@ void __thisModule::__main() {
#line 61 "expr.chpl"
a = a + ((valuea(a) + valuea(a)) + valuea(a));
#line 63 "expr.chpl"
std::vector<std::int64_t> b(10);
chplx::Array<std::int64_t, chplx::Domain<1>> b(chplx::Range(0, 10));
#line 65 "expr.chpl"
b[0] = 1;
b(0) = 1;
#line 66 "expr.chpl"
b[0] = a;
b(0) = a;
#line 67 "expr.chpl"
b[0] = a;
b(0) = a;
#line 68 "expr.chpl"
b[0] = b[0];
b(0) = b(0);
#line 69 "expr.chpl"
b[0] = b[0];
b(0) = b(0);
#line 70 "expr.chpl"
b[0] = b[0];
b(0) = b(0);
#line 71 "expr.chpl"
b[0] = b[0];
b(0) = b(0);
#line 73 "expr.chpl"
b[0 + 0] = 1;
b(0 + 0) = 1;
#line 74 "expr.chpl"
b[0 + 0] = 1;
b(0 + 0) = 1;
#line 76 "expr.chpl"
b[0 + 0] = a;
b(0 + 0) = a;
#line 77 "expr.chpl"
b[0 + 0] = a;
b(0 + 0) = a;
#line 78 "expr.chpl"
b[0 + 0] = b[0];
b(0 + 0) = b(0);
#line 79 "expr.chpl"
b[0 + 0] = b[0];
b(0 + 0) = b(0);
#line 80 "expr.chpl"
b[0 + 0] = b[0 + 0];
b(0 + 0) = b(0 + 0);
#line 81 "expr.chpl"
b[0 + 0] = b[0 + 0];
b(0 + 0) = b(0 + 0);
#line 83 "expr.chpl"
std::vector<std::vector<std::int64_t>> c = {{1, 2}, {3, 4}};
chplx::Array<std::int64_t, chplx::Domain<2>> c = {{1, 2}, {3, 4}};
#line 84 "expr.chpl"
c[0][0] = 0;
c(0, 0) = 0;
#line 85 "expr.chpl"
c[0][0] = a;
c(0, 0) = a;
#line 86 "expr.chpl"
c[0][0] = 0;
c(0, 0) = 0;
#line 87 "expr.chpl"
c[0][0] = a;
c(0, 0) = a;
#line 88 "expr.chpl"
c[0][0] = c[0][0];
c(0, 0) = c(0, 0);
#line 89 "expr.chpl"
c[0][0] = c[0][0];
c(0, 0) = c(0, 0);
#line 90 "expr.chpl"
c[0][0] = c[0][0];
c(0, 0) = c(0, 0);
#line 91 "expr.chpl"
c[0][0] = c[0][0];
c(0, 0) = c(0, 0);
#line 92 "expr.chpl"
c[0 + 0][0] = 1;
c(0 + 0, 0) = 1;
#line 93 "expr.chpl"
c[0 + 0][0] = 1;
c(0 + 0, 0) = 1;
#line 95 "expr.chpl"
std::int64_t y = valuea(1);
#line 96 "expr.chpl"
Expand Down
2 changes: 1 addition & 1 deletion backend/test/expr/expr_driver.hpp.good
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This program file was generated by the chplx compiler.
// The original Chapel program file can be found here: expr.cpp
// The original Chapel program file can be found here: expr.chpl
//
#pragma once

Expand Down
2 changes: 1 addition & 1 deletion backend/test/fn/fn_driver.hpp.good
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This program file was generated by the chplx compiler.
// The original Chapel program file can be found here: fn.cpp
// The original Chapel program file can be found here: fn.chpl
//
#pragma once

Expand Down
2 changes: 1 addition & 1 deletion backend/test/fnc/fnc_driver.hpp.good
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This program file was generated by the chplx compiler.
// The original Chapel program file can be found here: fnc.cpp
// The original Chapel program file can be found here: fnc.chpl
//
#pragma once

Expand Down
28 changes: 14 additions & 14 deletions backend/test/forall/forall.cpp.good
Original file line number Diff line number Diff line change
Expand Up @@ -10,68 +10,68 @@ struct __thisModule *__this = nullptr;
#line 19 "forall.chpl"
void __thisModule::alpha() {
#line 20 "forall.chpl"
std::vector<double> B(9);
chplx::Array<double, chplx::Domain<1>> B(chplx::Range(0, 9));
#line 21 "forall.chpl"
chplx::forLoop(chplx::Range{0, 9}, [&](auto i) {
#line 22 "forall.chpl"
B[i] = 1.000000;
B(i) = 1.000000;
});
#line 24 "forall.chpl"
chplx::forall(chplx::Range{0, 9}, [&](auto i) {
#line 25 "forall.chpl"
B[i] = 1.000000;
B(i) = 1.000000;
});
};

void __thisModule::__main() {

#line 8 "forall.chpl"
std::vector<double> A(9);
chplx::Array<double, chplx::Domain<1>> A(chplx::Range(0, 9));
#line 10 "forall.chpl"
chplx::forLoop(chplx::Range{0, 9}, [&](auto i) {
#line 11 "forall.chpl"
A[i] = i;
A(i) = i;
#line 12 "forall.chpl"
std::cout << i << std::endl;
});
#line 15 "forall.chpl"
chplx::forall(chplx::Range{0, 9}, [&](auto i) {
#line 16 "forall.chpl"
A[i] = 1.000000;
A(i) = 1.000000;
});
#line 29 "forall.chpl"
chplx::forLoop(chplx::Range{0, 9}, [&](auto i) {
#line 30 "forall.chpl"
A[i] = i;
A(i) = i;
});
#line 32 "forall.chpl"
chplx::forall(chplx::Range{0, 9}, [&](auto i) {
#line 33 "forall.chpl"
A[i] = i;
A(i) = i;
});
#line 35 "forall.chpl"
std::vector<std::int64_t> B(2);
chplx::Array<std::int64_t, chplx::Domain<1>> B(chplx::Range(0, 2));
#line 36 "forall.chpl"
chplx::coforall(chplx::Range{0, 2}, [&](auto tid) {
#line 37 "forall.chpl"
B[tid] = tid;
B(tid) = tid;
});
#line 40 "forall.chpl"
chplx::forLoop(chplx::Range{0, 2}, [&](auto i) {
#line 41 "forall.chpl"
std::cout << B[i] << std::endl;
std::cout << B(i) << std::endl;
});
#line 43 "forall.chpl"
std::vector<std::int64_t> C(2);
chplx::Array<std::int64_t, chplx::Domain<1>> C(chplx::Range(0, 2));
#line 44 "forall.chpl"
chplx::coforall(chplx::Range{0, 2}, [&](auto tid) {
#line 45 "forall.chpl"
C[tid] = tid;
C(tid) = tid;
});
#line 47 "forall.chpl"
chplx::forLoop(chplx::Range{0, 2}, [&](auto i) {
#line 48 "forall.chpl"
std::cout << C[i] << std::endl;
std::cout << C(i) << std::endl;
});
}

Expand Down
2 changes: 1 addition & 1 deletion backend/test/forall/forall_driver.hpp.good
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This program file was generated by the chplx compiler.
// The original Chapel program file can be found here: forall.cpp
// The original Chapel program file can be found here: forall.chpl
//
#pragma once

Expand Down
12 changes: 9 additions & 3 deletions library/include/chplx/adapt_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ namespace chplx {
//-----------------------------------------------------------------------------
// 1D iteration support
template <typename T, typename Domain>
hpx::generator<T&, T> iterate(
detail::IteratorGenerator<Array<T, Domain>> a) noexcept {
hpx::generator<T &, T>
iterate(detail::IteratorGenerator<Array<T, Domain>> a) noexcept {

auto size = a.size;
for (auto ilo = a.first; size-- != 0; ++ilo) {
co_yield a.target(ilo);
co_yield a.target[ilo];
}
}

Expand All @@ -36,4 +36,10 @@ decltype(auto) iterate(Array<T, Domain> const &a) noexcept {
return iterate(detail::IteratorGenerator(a));
}

template <typename T, typename Domain>
decltype(auto) iterate(Array<T, Domain> &&a) noexcept {

return iterate(detail::IteratorGenerator(std::move(a)));
}

} // namespace chplx
2 changes: 1 addition & 1 deletion library/include/chplx/adapt_range.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ hpx::generator<T> iterate(

auto size = ni.size;
for (auto ilo = ni.first; size-- != 0; ++ilo) {
co_yield ni.target.orderToIndex(ilo);
co_yield ni.target[ilo];
}
}

Expand Down
Loading

0 comments on commit 941ed36

Please sign in to comment.