From fd2dcb6180e00e3706cf63a05a3b83b927a02304 Mon Sep 17 00:00:00 2001 From: Justin Carpentier Date: Sat, 16 Nov 2019 17:01:30 +0100 Subject: [PATCH] core: improve conversion checking --- include/eigenpy/details.hpp | 40 +++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/include/eigenpy/details.hpp b/include/eigenpy/details.hpp index b9c37ac1f..e7becd589 100644 --- a/include/eigenpy/details.hpp +++ b/include/eigenpy/details.hpp @@ -378,17 +378,43 @@ namespace eigenpy if(MatType::IsVectorAtCompileTime) { + const Eigen::DenseIndex size_at_compile_time + = MatType::IsRowMajor + ? MatType::ColsAtCompileTime + : MatType::RowsAtCompileTime; + switch(PyArray_NDIM(pyArray)) { case 0: return 0; case 1: - return pyArray; + { + if(size_at_compile_time != Eigen::Dynamic) + { + // check that the sizes at compile time matche + if(PyArray_DIMS(pyArray)[0] == size_at_compile_time) + return pyArray; + else + return 0; + } + else // This is a dynamic MatType + return pyArray; + } case 2: { // Special care of scalar matrix of dimension 1x1. if(PyArray_DIMS(pyArray)[0] == 1 && PyArray_DIMS(pyArray)[1] == 1) - return pyArray; + { + if(size_at_compile_time != Eigen::Dynamic) + { + if(size_at_compile_time == 1) + return pyArray; + else + return 0; + } + else // This is a dynamic MatType + return pyArray; + } if(PyArray_DIMS(pyArray)[0] > 1 && PyArray_DIMS(pyArray)[1] > 1) { @@ -409,6 +435,16 @@ namespace eigenpy #endif return 0; } + + if(size_at_compile_time != Eigen::Dynamic) + { // This is a fixe size vector + const Eigen::DenseIndex pyArray_size + = PyArray_DIMS(pyArray)[0] > PyArray_DIMS(pyArray)[1] + ? PyArray_DIMS(pyArray)[0] + : PyArray_DIMS(pyArray)[1]; + if(size_at_compile_time != pyArray_size) + return 0; + } break; } default: