Skip to content

Commit aa1e2e2

Browse files
[needs discussion] replace store() with operator=
1 parent cb6e213 commit aa1e2e2

File tree

3 files changed

+33
-18
lines changed

3 files changed

+33
-18
lines changed

examples/nbody/nbody.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ namespace usellama
113113
const FP distSixth = distSqr * distSqr * distSqr;
114114
const FP invDistCube = 1.0f / std::sqrt(distSixth);
115115
const FP sts = pj->mass * invDistCube * TIMESTEP;
116-
pi(1_DC).store(pi->vel + dist * sts);
116+
pi(1_DC) = pi->vel + dist * sts;
117117
}
118118

119119
template <bool UseAccumulator, typename View>
@@ -143,7 +143,7 @@ namespace usellama
143143
{
144144
LLAMA_INDEPENDENT_DATA
145145
for (std::size_t i = 0; i < PROBLEM_SIZE; i++)
146-
particles(i)(0_DC).store(particles(i)->pos + particles(i)->vel * TIMESTEP);
146+
particles(i)(0_DC) = particles(i)->pos + particles(i)->vel * TIMESTEP;
147147
}
148148

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

include/llama/View.hpp

+22-7
Original file line numberDiff line numberDiff line change
@@ -502,10 +502,31 @@ namespace llama
502502
return this->operator=<VirtualDatum>(other);
503503
}
504504

505+
private:
506+
template <typename T>
507+
struct ConvertibleTo
508+
{
509+
template <typename U>
510+
using fn = std::is_convertible<T, U>;
511+
};
512+
513+
public:
514+
// TODO: this operator does too much black magic already
505515
template <typename T>
506516
LLAMA_FN_HOST_ACC_INLINE auto operator=(const T& other) -> VirtualDatum&
507517
{
508-
return internal::virtualDatumArithOperator<internal::Assign>(*this, other);
518+
if constexpr (
519+
is_VirtualDatum<
520+
T> || boost::mp11::mp_any_of_q<FlattenDatumDomain<AccessibleDatumDomain>, ConvertibleTo<T>>::value)
521+
return internal::virtualDatumArithOperator<internal::Assign>(*this, other);
522+
else
523+
{
524+
internal::assignTuples(
525+
asTuple(),
526+
other,
527+
std::make_index_sequence<std::tuple_size_v<decltype(asTuple())>>{});
528+
return *this;
529+
}
509530
}
510531

511532
template <typename T>
@@ -733,12 +754,6 @@ namespace llama
733754
static_assert(supportsValueLoad);
734755
return loadAs<ValueStruct>();
735756
}
736-
737-
template <typename TupleLike>
738-
void store(const TupleLike& t)
739-
{
740-
internal::assignTuples(asTuple(), t, std::make_index_sequence<std::tuple_size_v<decltype(asTuple())>>{});
741-
}
742757
};
743758
} // namespace llama
744759

tests/virtualdatum.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -797,14 +797,14 @@ TEST_CASE("VirtualDatum.convert.constref")
797797
}
798798
}
799799

800-
TEST_CASE("VirtualDatum.store.tuplelike")
800+
TEST_CASE("VirtualDatum.operator=.tuplelike")
801801
{
802802
llama::One<Name> datum;
803803

804804
datum = 1;
805805
{
806806
MyPos<int> pos{2, 3};
807-
datum(tag::Pos{}).store(pos);
807+
datum(tag::Pos{}) = pos;
808808
CHECK(datum(tag::Pos{}, tag::A{}) == 2);
809809
CHECK(datum(tag::Pos{}, tag::Y{}) == 3);
810810
CHECK(datum(tag::Vel{}, tag::X{}) == 1);
@@ -816,7 +816,7 @@ TEST_CASE("VirtualDatum.store.tuplelike")
816816
datum = 1;
817817
{
818818
MyDatum<int> d{{2, 3}, {4, 5, 6}, 7};
819-
datum.store(d);
819+
datum = d;
820820
CHECK(datum(tag::Pos{}, tag::A{}) == 2);
821821
CHECK(datum(tag::Pos{}, tag::Y{}) == 3);
822822
CHECK(datum(tag::Vel{}, tag::X{}) == 4);
@@ -879,7 +879,7 @@ TEST_CASE("VirtualDatum.loadAs.constref")
879879
}
880880
}
881881

882-
TEST_CASE("VirtualDatum.store.aggregate")
882+
TEST_CASE("VirtualDatum.operator=.aggregate")
883883
{
884884
struct MyPosAgg
885885
{
@@ -906,7 +906,7 @@ TEST_CASE("VirtualDatum.store.aggregate")
906906
datum = 1;
907907
{
908908
MyPosAgg pos{2, 3};
909-
datum(tag::Pos{}).store(pos);
909+
datum(tag::Pos{}) = pos;
910910
CHECK(datum(tag::Pos{}, tag::A{}) == 2);
911911
CHECK(datum(tag::Pos{}, tag::Y{}) == 3);
912912
CHECK(datum(tag::Vel{}, tag::X{}) == 1);
@@ -918,7 +918,7 @@ TEST_CASE("VirtualDatum.store.aggregate")
918918
datum = 1;
919919
{
920920
MyDatumAgg d{{2, 3}, {4, 5, 6}, 7};
921-
datum.store(d);
921+
datum = d;
922922
CHECK(datum(tag::Pos{}, tag::A{}) == 2);
923923
CHECK(datum(tag::Pos{}, tag::Y{}) == 3);
924924
CHECK(datum(tag::Vel{}, tag::X{}) == 4);
@@ -948,7 +948,7 @@ struct NameStruct
948948
TEST_CASE("VirtualDatum.operator->")
949949
{
950950
llama::One<NameStruct> datum;
951-
datum.store(NameStruct{1, 2, 3, 4, 5, 6});
951+
datum = NameStruct{1, 2, 3, 4, 5, 6};
952952

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

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

0 commit comments

Comments
 (0)