MCPcopy Create free account
hub / github.com/HViktorTsoi/FAST_LIO_LOCALIZATION / get_2darray

Function get_2darray

include/matplotlibcpp.h:342–362  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

340
341template<typename Numeric>
342PyObject* get_2darray(const std::vector<::std::vector<Numeric>>& v)
343{
344 if (v.size() < 1) throw std::runtime_error("get_2d_array v too small");
345
346 npy_intp vsize[2] = {static_cast<npy_intp>(v.size()),
347 static_cast<npy_intp>(v[0].size())};
348
349 PyArrayObject *varray =
350 (PyArrayObject *)PyArray_SimpleNew(2, vsize, NPY_DOUBLE);
351
352 double *vd_begin = static_cast<double *>(PyArray_DATA(varray));
353
354 for (const ::std::vector<Numeric> &v_row : v) {
355 if (v_row.size() != static_cast<size_t>(vsize[1]))
356 throw std::runtime_error("Missmatched array size");
357 std::copy(v_row.begin(), v_row.end(), vd_begin);
358 vd_begin += vsize[1];
359 }
360
361 return reinterpret_cast<PyObject *>(varray);
362}
363
364#else // fallback if we don't have numpy: copy every element of the given vector
365

Callers 1

plot_surfaceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected