Skip to content

Commit

Permalink
Replace if conditions by ternary operators in nabla
Browse files Browse the repository at this point in the history
  • Loading branch information
fthaler committed Jul 24, 2024
1 parent b6e3dce commit 37dc876
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions tests/regression/fn/fn_unstructured_nabla.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ namespace {
tuple_util::host_device::for_each(
[&](auto i) {
auto shifted_pp = shift(pp, e2v(), i);
if (can_deref(shifted_pp))
tmp += deref(shifted_pp);
GT_PROMISE(can_deref(shifted_pp));
tmp += deref(shifted_pp);
},
meta::rename<tuple, meta::make_indices_c<2>>());
tmp /= 2;
Expand All @@ -49,10 +49,10 @@ namespace {
tuple_util::host_device::for_each(
[&](auto i) {
auto shifted_zavg = shift(zavg, v2e(), i);
if (can_deref(shifted_zavg)) {
tuple_get(0_c, tmp) += tuple_get(0_c, deref(shifted_zavg)) * get<i.value>(signs);
tuple_get(1_c, tmp) += tuple_get(1_c, deref(shifted_zavg)) * get<i.value>(signs);
}
bool const edge_exists = can_deref(shifted_zavg);
auto value = edge_exists ? deref(shifted_zavg) : tuple<float_t, float_t>(0, 0);
tuple_get(0_c, tmp) += tuple_get(0_c, value) * get<i.value>(signs);
tuple_get(1_c, tmp) += tuple_get(1_c, value) * get<i.value>(signs);
},
meta::rename<tuple, meta::make_indices_c<6>>());
auto v = deref(vol);
Expand All @@ -70,22 +70,21 @@ namespace {
tuple_util::host_device::for_each(
[&](auto i) {
auto shifted_s = shift(s, v2e(), i);
if (can_deref(shifted_s)) {
float_t tmp2 = 0;
tuple_util::host_device::for_each(
[&](auto const &j) {
auto shifted_pp = shift(pp, v2e(), i, e2v(), j);
if (can_deref(shifted_pp))
tmp2 += deref(shifted_pp);
},
meta::rename<tuple, meta::make_indices_c<2>>());
tmp2 /= 2;
auto ss = deref(shifted_s);
auto zavg = tuple(tmp2 * tuple_get(0_c, ss), tmp2 * tuple_get(1_c, ss));
bool const edge_exists = can_deref(shifted_s);
float_t tmp2 = 0;
tuple_util::host_device::for_each(
[=, &tmp2](auto const &j) {
auto shifted_pp = shift(pp, v2e(), i, e2v(), j);
GT_PROMISE(can_deref(shifted_pp));
tmp2 += edge_exists ? deref(shifted_pp) : 0;
},
meta::rename<tuple, meta::make_indices_c<2>>());
tmp2 /= 2;
auto ss = edge_exists ? deref(shifted_s) : tuple<float_t, float_t>(0, 0);
auto zavg = tuple(tmp2 * tuple_get(0_c, ss), tmp2 * tuple_get(1_c, ss));

tuple_get(0_c, tmp) += tuple_get(0_c, zavg) * get<i.value>(signs);
tuple_get(1_c, tmp) += tuple_get(1_c, zavg) * get<i.value>(signs);
}
tuple_get(0_c, tmp) += tuple_get(0_c, zavg) * get<i.value>(signs);
tuple_get(1_c, tmp) += tuple_get(1_c, zavg) * get<i.value>(signs);
},
meta::rename<tuple, meta::make_indices_c<6>>());
auto v = deref(vol);
Expand Down

0 comments on commit 37dc876

Please sign in to comment.