@@ -299,22 +299,24 @@ template <> struct select_npy_type<uint64_t> { const static NPY_TYPES type = NPY
299
299
template <typename Numeric>
300
300
PyObject* get_array (const std::vector<Numeric>& v)
301
301
{
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 ();
303
304
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);
310
312
return varray;
311
313
}
312
-
313
- npy_intp vsize = v.size ();
314
+
314
315
PyObject* varray = PyArray_SimpleNewFromData (1 , &vsize, type, (void *)(v.data ()));
315
316
return varray;
316
317
}
317
318
319
+
318
320
template <typename Numeric>
319
321
PyObject* get_2darray (const std::vector<::std::vector<Numeric>>& v)
320
322
{
0 commit comments