@@ -112,9 +112,9 @@ void sync_promises() {
112112
113113// / trigger compile&run and return future value
114114#define PY_SYNC_RETURN (_f ) \
115- int vtWaitSym, vtSHARPYClass; \
116- VT (VT_classdef, " sharpy" , &vtSHARPYClass); \
117- VT (VT_funcdef, " wait" , vtSHARPYClass, &vtWaitSym); \
115+ int vtWaitSym, vtSHARPYClass; \
116+ VT (VT_classdef, " sharpy" , &vtSHARPYClass); \
117+ VT (VT_funcdef, " wait" , vtSHARPYClass, &vtWaitSym); \
118118 VT (VT_begin, vtWaitSym); \
119119 py::gil_scoped_release release; \
120120 Service::run (); \
@@ -124,22 +124,21 @@ void sync_promises() {
124124
125125// / trigger compile&run and return given attribute _x
126126#define SYNC_RETURN (_f, _a ) \
127- int vtWaitSym, vtSHARPYClass; \
128- VT (VT_classdef, " sharpy" , &vtSHARPYClass); \
129- VT (VT_funcdef, " wait" , vtSHARPYClass, &vtWaitSym); \
127+ int vtWaitSym, vtSHARPYClass; \
128+ VT (VT_classdef, " sharpy" , &vtSHARPYClass); \
129+ VT (VT_funcdef, " wait" , vtSHARPYClass, &vtWaitSym); \
130130 VT (VT_begin, vtWaitSym); \
131131 py::gil_scoped_release release; \
132132 Service::run (); \
133- auto r = (_f).get().get()-> _a (); \
133+ auto r = (_f).get().get() -> _a (); \
134134 VT (VT_end, vtWaitSym); \
135135 return r
136136
137137// / Replicate sharpy/future and SYNC_RETURN attribute _a
138138#define REPL_SYNC_RETURN (_f, _a ) \
139- auto r_ = std::unique_ptr<FutureArray>(Service::replicate(f)); \
139+ auto r_ = std::unique_ptr<FutureArray>(Service::replicate(f)); \
140140 SYNC_RETURN (r_->get (), _a)
141141
142-
143142// Finally our Python module
144143PYBIND11_MODULE(_sharpy, m) {
145144
@@ -183,13 +182,13 @@ PYBIND11_MODULE(_sharpy, m) {
183182
184183 py::class_<FutureArray>(m, " SHARPYFuture" )
185184 // attributes we can get from the future itself
186- .def_property_readonly (" dtype " ,
187- [](const FutureArray &f) { return f.get ().dtype (); })
188- .def_property_readonly (" ndim " ,
189- [](const FutureArray &f) { return f.get ().rank (); })
185+ .def_property_readonly (
186+ " dtype " , [](const FutureArray &f) { return f.get ().dtype (); })
187+ .def_property_readonly (
188+ " ndim " , [](const FutureArray &f) { return f.get ().rank (); })
190189 // attributes we can get from future without additional computation
191- .def_property_readonly (" shape " ,
192- [](const FutureArray &f) { SYNC_RETURN (f, shape); })
190+ .def_property_readonly (
191+ " shape " , [](const FutureArray &f) { SYNC_RETURN (f, shape); })
193192 .def_property_readonly (" size" ,
194193 [](const FutureArray &f) { SYNC_RETURN (f, size); })
195194 .def (" __len__" , [](const FutureArray &f) { SYNC_RETURN (f, __len__); })
@@ -199,10 +198,12 @@ PYBIND11_MODULE(_sharpy, m) {
199198 [](const FutureArray &f) { REPL_SYNC_RETURN (f, __bool__); })
200199 .def (" __float__" ,
201200 [](const FutureArray &f) { REPL_SYNC_RETURN (f, __float__); })
202- .def (" __int__" , [](const FutureArray &f) { REPL_SYNC_RETURN (f, __int__); })
201+ .def (" __int__" ,
202+ [](const FutureArray &f) { REPL_SYNC_RETURN (f, __int__); })
203203 .def (" __index__" ,
204204 [](const FutureArray &f) { REPL_SYNC_RETURN (f, __int__); })
205205 // attributes returning a new FutureArray
206+ .def (" astype" , &AsType::astype)
206207 .def (" __getitem__" , &GetItem::__getitem__)
207208 .def (" __setitem__" , &SetItem::__setitem__)
208209 .def (" map" , &SetItem::map);
@@ -213,7 +214,6 @@ PYBIND11_MODULE(_sharpy, m) {
213214 .def (" seed" , &Random::seed)
214215 .def (" uniform" , &Random::rand);
215216
216-
217217 // py::class_<dpdlpack>(m, "dpdlpack")
218218 // .def("__dlpack__", &dpdlpack.__dlpack__);
219219}
0 commit comments