@@ -299,22 +299,24 @@ template <> struct select_npy_type<uint64_t> { const static NPY_TYPES type = NPY
299299template <typename Numeric>
300300PyObject* get_array (const std::vector<Numeric>& v)
301301{
302- detail::_interpreter::get (); // interpreter needs to be initialized for the numpy commands to work
302+ detail::_interpreter::get (); // interpreter needs to be initialized for the numpy commands to work
303+ npy_intp vsize = v.size ();
303304 NPY_TYPES type = select_npy_type<Numeric>::type;
304- if (type == NPY_NOTYPE)
305- {
306- std::vector<double > vd (v.size ());
307- npy_intp vsize = v.size ();
308- std::copy (v.begin (),v.end (),vd.begin ());
309- PyObject* varray = PyArray_SimpleNewFromData (1 , &vsize, NPY_DOUBLE, (void *)(vd.data ()));
305+ if (type == NPY_NOTYPE) {
306+ size_t memsize = v.size ()*sizeof (double );
307+ double * dp = static_cast <double *>(::malloc (memsize));
308+ for (size_t i=0 ; i<v.size (); ++i)
309+ dp[i] = v[i];
310+ PyObject* varray = PyArray_SimpleNewFromData (1 , &vsize, NPY_DOUBLE, dp);
311+ PyArray_UpdateFlags (reinterpret_cast <PyArrayObject*>(varray), NPY_ARRAY_OWNDATA);
310312 return varray;
311313 }
312-
313- npy_intp vsize = v.size ();
314+
314315 PyObject* varray = PyArray_SimpleNewFromData (1 , &vsize, type, (void *)(v.data ()));
315316 return varray;
316317}
317318
319+
318320template <typename Numeric>
319321PyObject* get_2darray (const std::vector<::std::vector<Numeric>>& v)
320322{
0 commit comments