| 320 | |
| 321 | template<typename Numeric> |
| 322 | PyObject* get_array(const std::vector<Numeric>& v) |
| 323 | { |
| 324 | npy_intp vsize = v.size(); |
| 325 | NPY_TYPES type = select_npy_type<Numeric>::type; |
| 326 | if (type == NPY_NOTYPE) { |
| 327 | size_t memsize = v.size()*sizeof(double); |
| 328 | double* dp = static_cast<double*>(::malloc(memsize)); |
| 329 | for (size_t i=0; i<v.size(); ++i) |
| 330 | dp[i] = v[i]; |
| 331 | PyObject* varray = PyArray_SimpleNewFromData(1, &vsize, NPY_DOUBLE, dp); |
| 332 | PyArray_UpdateFlags(reinterpret_cast<PyArrayObject*>(varray), NPY_ARRAY_OWNDATA); |
| 333 | return varray; |
| 334 | } |
| 335 | |
| 336 | PyObject* varray = PyArray_SimpleNewFromData(1, &vsize, type, (void*)(v.data())); |
| 337 | return varray; |
| 338 | } |
| 339 | |
| 340 | |
| 341 | template<typename Numeric> |
no test coverage detected