Skip to content

Commit 03ba62e

Browse files
committed
make get_array compatible with Eigen version <= 3.3.7
1 parent 9c58c6c commit 03ba62e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

matplotlibcpp.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,14 +362,16 @@ template <> struct select_npy_type<uint64_t> {
362362

363363
// TODO change to Vector template so useable for Eigen vectors,
364364
// should be enough since it also provides the end and begin methods
365-
template <typename Numeric> PyObject *get_array(const std::vector<Numeric> &v) {
365+
template <typename Vector> PyObject *get_array(const Vector &v) {
366366
detail::_interpreter::get(); // interpreter needs to be initialized for the
367367
// numpy commands to work
368368
NPY_TYPES type = select_npy_type<Numeric>::type;
369369
if (type == NPY_NOTYPE) {
370370
std::vector<double> vd(v.size());
371371
npy_intp vsize = v.size();
372-
std::copy(v.begin(), v.end(), vd.begin());
372+
// Eigen Vectors do not support begin/end() in the currently stable version
373+
// this can be changed once Eigen 3.4. is released
374+
std::copy(v.data(), v.data() + v.size(), vd.begin());
373375
PyObject *varray =
374376
PyArray_SimpleNewFromData(1, &vsize, NPY_DOUBLE, (void *)(vd.data()));
375377
return varray;
@@ -389,7 +391,9 @@ template <typename Vector> PyObject *get_array(const Vector &v) {
389391
if (type == NPY_NOTYPE) {
390392
std::vector<double> vd(v.size());
391393
npy_intp vsize = v.size();
392-
std::copy(v.begin(), v.end(), vd.begin());
394+
// Eigen Vectors do not support begin/end() in the currently stable version
395+
// this can be changed once Eigen 3.4. is released
396+
std::copy(v.data(), v.data() + v.size(), vd.begin());
393397
PyObject *varray =
394398
PyArray_SimpleNewFromData(1, &vsize, NPY_DOUBLE, (void *)(vd.data()));
395399
return varray;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy