From 93594a3857a05d52c2c47e35c768c5fb080752da Mon Sep 17 00:00:00 2001 From: Ben North Date: Tue, 5 Jul 2016 20:05:10 +0100 Subject: [PATCH] Fix handling of one-dimensional input arrays In eigen.h, type_caster::load(): For the 'ndim == 1' case, use the 'InnerStride' type because there is only an inner stride for a vector. Choose between (n_elts x 1) or (1 x n_elts) according to whether we're constructing a Vector or a RowVector. --- include/pybind11/eigen.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/pybind11/eigen.h b/include/pybind11/eigen.h index 718107947..ecad2d547 100644 --- a/include/pybind11/eigen.h +++ b/include/pybind11/eigen.h @@ -61,7 +61,7 @@ struct type_caster::value>::t buffer_info info = buffer.request(); if (info.ndim == 1) { - typedef Eigen::Stride Strides; + typedef Eigen::InnerStride<> Strides; if (!isVector && !(Type::RowsAtCompileTime == Eigen::Dynamic && Type::ColsAtCompileTime == Eigen::Dynamic)) @@ -71,10 +71,13 @@ struct type_caster::value>::t info.shape[0] != (size_t) Type::SizeAtCompileTime) return false; - auto strides = Strides(info.strides[0] / sizeof(Scalar), 0); + auto strides = Strides(info.strides[0] / sizeof(Scalar)); + + Strides::Index n_elts = info.shape[0]; + Strides::Index unity = 1; value = Eigen::Map( - (Scalar *) info.ptr, typename Strides::Index(info.shape[0]), 1, strides); + (Scalar *) info.ptr, rowMajor ? unity : n_elts, rowMajor ? n_elts : unity, strides); } else if (info.ndim == 2) { typedef Eigen::Stride Strides;