Skip to content

Commit

Permalink
[needs discussion] replace store() with operator=
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardmgruber committed Feb 3, 2021
1 parent cb6e213 commit aa1e2e2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
6 changes: 3 additions & 3 deletions examples/nbody/nbody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ namespace usellama
const FP distSixth = distSqr * distSqr * distSqr;
const FP invDistCube = 1.0f / std::sqrt(distSixth);
const FP sts = pj->mass * invDistCube * TIMESTEP;
pi(1_DC).store(pi->vel + dist * sts);
pi(1_DC) = pi->vel + dist * sts;
}

template <bool UseAccumulator, typename View>
Expand Down Expand Up @@ -143,7 +143,7 @@ namespace usellama
{
LLAMA_INDEPENDENT_DATA
for (std::size_t i = 0; i < PROBLEM_SIZE; i++)
particles(i)(0_DC).store(particles(i)->pos + particles(i)->vel * TIMESTEP);
particles(i)(0_DC) = particles(i)->pos + particles(i)->vel * TIMESTEP;
}

template <int Mapping, bool UseAccumulator, std::size_t AoSoALanes = 8 /*AVX2*/>
Expand Down Expand Up @@ -211,7 +211,7 @@ namespace usellama
p.vel.y = dist(engine) / FP(10);
p.vel.z = dist(engine) / FP(10);
p.mass = dist(engine) / FP(100);
particles(i).store(p);
particles(i) = p;
}
watch.printAndReset("init");

Expand Down
29 changes: 22 additions & 7 deletions include/llama/View.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,10 +502,31 @@ namespace llama
return this->operator=<VirtualDatum>(other);
}

private:
template <typename T>
struct ConvertibleTo
{
template <typename U>
using fn = std::is_convertible<T, U>;
};

public:
// TODO: this operator does too much black magic already
template <typename T>
LLAMA_FN_HOST_ACC_INLINE auto operator=(const T& other) -> VirtualDatum&
{
return internal::virtualDatumArithOperator<internal::Assign>(*this, other);
if constexpr (
is_VirtualDatum<
T> || boost::mp11::mp_any_of_q<FlattenDatumDomain<AccessibleDatumDomain>, ConvertibleTo<T>>::value)
return internal::virtualDatumArithOperator<internal::Assign>(*this, other);
else
{
internal::assignTuples(
asTuple(),
other,
std::make_index_sequence<std::tuple_size_v<decltype(asTuple())>>{});
return *this;
}
}

template <typename T>
Expand Down Expand Up @@ -733,12 +754,6 @@ namespace llama
static_assert(supportsValueLoad);
return loadAs<ValueStruct>();
}

template <typename TupleLike>
void store(const TupleLike& t)
{
internal::assignTuples(asTuple(), t, std::make_index_sequence<std::tuple_size_v<decltype(asTuple())>>{});
}
};
} // namespace llama

Expand Down
16 changes: 8 additions & 8 deletions tests/virtualdatum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,14 +797,14 @@ TEST_CASE("VirtualDatum.convert.constref")
}
}

TEST_CASE("VirtualDatum.store.tuplelike")
TEST_CASE("VirtualDatum.operator=.tuplelike")
{
llama::One<Name> datum;

datum = 1;
{
MyPos<int> pos{2, 3};
datum(tag::Pos{}).store(pos);
datum(tag::Pos{}) = pos;
CHECK(datum(tag::Pos{}, tag::A{}) == 2);
CHECK(datum(tag::Pos{}, tag::Y{}) == 3);
CHECK(datum(tag::Vel{}, tag::X{}) == 1);
Expand All @@ -816,7 +816,7 @@ TEST_CASE("VirtualDatum.store.tuplelike")
datum = 1;
{
MyDatum<int> d{{2, 3}, {4, 5, 6}, 7};
datum.store(d);
datum = d;
CHECK(datum(tag::Pos{}, tag::A{}) == 2);
CHECK(datum(tag::Pos{}, tag::Y{}) == 3);
CHECK(datum(tag::Vel{}, tag::X{}) == 4);
Expand Down Expand Up @@ -879,7 +879,7 @@ TEST_CASE("VirtualDatum.loadAs.constref")
}
}

TEST_CASE("VirtualDatum.store.aggregate")
TEST_CASE("VirtualDatum.operator=.aggregate")
{
struct MyPosAgg
{
Expand All @@ -906,7 +906,7 @@ TEST_CASE("VirtualDatum.store.aggregate")
datum = 1;
{
MyPosAgg pos{2, 3};
datum(tag::Pos{}).store(pos);
datum(tag::Pos{}) = pos;
CHECK(datum(tag::Pos{}, tag::A{}) == 2);
CHECK(datum(tag::Pos{}, tag::Y{}) == 3);
CHECK(datum(tag::Vel{}, tag::X{}) == 1);
Expand All @@ -918,7 +918,7 @@ TEST_CASE("VirtualDatum.store.aggregate")
datum = 1;
{
MyDatumAgg d{{2, 3}, {4, 5, 6}, 7};
datum.store(d);
datum = d;
CHECK(datum(tag::Pos{}, tag::A{}) == 2);
CHECK(datum(tag::Pos{}, tag::Y{}) == 3);
CHECK(datum(tag::Vel{}, tag::X{}) == 4);
Expand Down Expand Up @@ -948,7 +948,7 @@ struct NameStruct
TEST_CASE("VirtualDatum.operator->")
{
llama::One<NameStruct> datum;
datum.store(NameStruct{1, 2, 3, 4, 5, 6});
datum = NameStruct{1, 2, 3, 4, 5, 6};

auto test = [](auto&& datum) {
using namespace llama::literals;
Expand All @@ -973,7 +973,7 @@ TEST_CASE("VirtualDatum.operator->")
TEST_CASE("VirtualDatum.operator*")
{
llama::One<NameStruct> datum;
datum.store(NameStruct{1, 2, 3, 4, 5, 6});
datum = NameStruct{1, 2, 3, 4, 5, 6};

auto test = [](auto&& datum) {
using namespace llama::literals;
Expand Down

0 comments on commit aa1e2e2

Please sign in to comment.