| 220 | }; |
| 221 | |
| 222 | struct NdarrayCallPolicies : public bp::default_call_policies { |
| 223 | typedef NdarrayConverterGenerator result_converter; |
| 224 | PyObject* postcall(PyObject* pyargs, PyObject* result) { |
| 225 | bp::object pyblob = bp::extract<bp::tuple>(pyargs)()[0]; |
| 226 | shared_ptr<Blob<Dtype> > blob = |
| 227 | bp::extract<shared_ptr<Blob<Dtype> > >(pyblob); |
| 228 | // Free the temporary pointer-holding array, and construct a new one with |
| 229 | // the shape information from the blob. |
| 230 | void* data = PyArray_DATA(reinterpret_cast<PyArrayObject*>(result)); |
| 231 | Py_DECREF(result); |
| 232 | const int num_axes = blob->num_axes(); |
| 233 | vector<npy_intp> dims(blob->shape().begin(), blob->shape().end()); |
| 234 | PyObject *arr_obj = PyArray_SimpleNewFromData(num_axes, dims.data(), |
| 235 | NPY_FLOAT32, data); |
| 236 | // SetBaseObject steals a ref, so we need to INCREF. |
| 237 | Py_INCREF(pyblob.ptr()); |
| 238 | PyArray_SetBaseObject(reinterpret_cast<PyArrayObject*>(arr_obj), |
| 239 | pyblob.ptr()); |
| 240 | return arr_obj; |
| 241 | } |
| 242 | }; |
| 243 | |
| 244 | bp::object Blob_Reshape(bp::tuple args, bp::dict kwargs) { |
| 245 | if (bp::len(kwargs) > 0) { |
no outgoing calls
no test coverage detected