@@ -134,33 +134,58 @@ namespace x {
134134
135135} // namespace x
136136
137+ struct DeferredSetItem : public Deferred
138+ {
139+ tensor_i::future_type _a;
140+ tensor_i::future_type _b;
141+ NDSlice _slc;
142+
143+ DeferredSetItem (tensor_i::future_type & a, const tensor_i::future_type & b, const std::vector<py::slice> & v)
144+ : _a(a), _b(b), _slc(v)
145+ {}
146+
147+ void run ()
148+ {
149+ const auto a = std::move (_a.get ());
150+ const auto b = std::move (_b.get ());
151+ set_value (std::move (TypeDispatch<x::SetItem>(a, b, _slc)));
152+ }
153+ };
154+
137155tensor_i::future_type SetItem::__setitem__ (tensor_i::future_type & a, const std::vector<py::slice> & v, const tensor_i::future_type & b)
138156{
139- auto aa = std::move (a.get ());
140- auto bb = std::move (b.get ());
141- NDSlice _slc (v);
142- return defer ([aa, bb, _slc](){
143- return TypeDispatch<x::SetItem>(aa, bb, _slc);
144- });
157+ return defer<DeferredSetItem>(a, b, v);
145158}
146159
147- tensor_i::future_type GetItem::__getitem__ ( const tensor_i::future_type & a, const std::vector<py::slice> & v)
160+ struct DeferredGetItem : public Deferred
148161{
149- auto aa = std::move (a.get ());
150- NDSlice _slc (v);
151- return defer ([aa, _slc](){
152- return TypeDispatch<x::GetItem>(aa, _slc);
153- });
162+ tensor_i::future_type _a;
163+ NDSlice _slc;
164+
165+ DeferredGetItem (const tensor_i::future_type & a, const std::vector<py::slice> & v)
166+ : _a(a), _slc(v)
167+ {}
168+
169+ void run ()
170+ {
171+ const auto a = std::move (_a.get ());
172+ set_value (std::move (TypeDispatch<x::GetItem>(a, _slc)));
173+ }
174+ };
175+
176+ tensor_i::future_type GetItem::__getitem__ (const tensor_i::future_type & a, const std::vector<py::slice> & v)
177+ {
178+ return defer<DeferredGetItem>(a, v);
154179}
155180
156181py::object GetItem::get_slice (const tensor_i::future_type & a, const std::vector<py::slice> & v)
157182{
158- const auto & aa = std::move (a.get ());
183+ const auto aa = std::move (a.get ());
159184 return TypeDispatch<x::SPMD>(aa, NDSlice (v));
160185}
161186
162187py::object GetItem::get_local (const tensor_i::future_type & a, py::handle h)
163188{
164- const auto & aa = std::move (a.get ());
189+ const auto aa = std::move (a.get ());
165190 return TypeDispatch<x::SPMD>(aa, h);
166191}
0 commit comments