MCPcopy Create free account
hub / github.com/accellera-official/systemc / get_2darray

Function get_2darray

examples/sysc/async_suspend/matplotlibcpp.h:289–310  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

287
288template<typename Numeric>
289PyObject* get_2darray(const std::vector<::std::vector<Numeric>>& v)
290{
291 detail::_interpreter::get(); //interpreter needs to be initialized for the numpy commands to work
292 if (v.size() < 1) throw std::runtime_error("get_2d_array v too small");
293
294 npy_intp vsize[2] = {static_cast<npy_intp>(v.size()),
295 static_cast<npy_intp>(v[0].size())};
296
297 PyArrayObject *varray =
298 (PyArrayObject *)PyArray_SimpleNew(2, vsize, NPY_DOUBLE);
299
300 double *vd_begin = static_cast<double *>(PyArray_DATA(varray));
301
302 for (const ::std::vector<Numeric> &v_row : v) {
303 if (v_row.size() != static_cast<size_t>(vsize[1]))
304 throw std::runtime_error("Missmatched array size");
305 std::copy(v_row.begin(), v_row.end(), vd_begin);
306 vd_begin += vsize[1];
307 }
308
309 return reinterpret_cast<PyObject *>(varray);
310}
311
312#else // fallback if we don't have numpy: copy every element of the given vector
313

Callers 1

plot_surfaceFunction · 0.85

Calls 4

copyFunction · 0.85
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected