diff --git a/include/eigenpy/map.hpp b/include/eigenpy/map.hpp index 71e6c4d26ce36f9e1079caf2d1572dc35e39ad0c..7de53f5c3a297f98f4c8e77ea545255ec2ef9eb6 100644 --- a/include/eigenpy/map.hpp +++ b/include/eigenpy/map.hpp @@ -94,6 +94,8 @@ namespace eigenpy int rowMajor; if( PyArray_NDIM(pyArray)==1 ) rowMajor = 0; + else if (PyArray_DIMS(pyArray)[0] == 0) rowMajor = 0; // handle zero-size vector + else if (PyArray_DIMS(pyArray)[1] == 0) rowMajor = 1; // handle zero-size vector else rowMajor = (PyArray_DIMS(pyArray)[0]>PyArray_DIMS(pyArray)[1])?0:1; assert( (PyArray_DIMS(pyArray)[rowMajor]< INT_MAX) diff --git a/unittest/matrix.cpp b/unittest/matrix.cpp index 8eff2946857fa3a3d8e66d035aadadadd4a6e22c..b65d2f8709999ce641b8f36ec139996f42eff908 100644 --- a/unittest/matrix.cpp +++ b/unittest/matrix.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2014, Nicolas Mansard, LAAS-CNRS + * Copyright 2014,2018, Nicolas Mansard, Justin Carpentier, LAAS-CNRS * * This file is part of eigenpy. * eigenpy is free software: you can redistribute it and/or @@ -17,6 +17,18 @@ #include "eigenpy/eigenpy.hpp" #include <iostream> +Eigen::VectorXd emptyVector() +{ + Eigen::VectorXd vec; + vec.resize(0); + return vec; +} + +Eigen::MatrixXd emptyMatrix() +{ + return Eigen::MatrixXd(0,0); +} + Eigen::MatrixXd naturals(int R,int C,bool verbose) { Eigen::MatrixXd mat(R,C); @@ -77,4 +89,7 @@ BOOST_PYTHON_MODULE(matrix) bp::def("reflexV", reflex<Eigen::VectorXd>); bp::def("reflex33", reflex<Eigen::Matrix3d>); bp::def("reflex3", reflex<Eigen::Vector3d>); + + bp::def("emptyVector", emptyVector); + bp::def("emptyMatrix", emptyMatrix); } diff --git a/unittest/python/test_matrix.py b/unittest/python/test_matrix.py index ad5490c0663ae306d2105653e1df189c5886b361..847bb94a8af389de79752b07e915e3a131da5027 100644 --- a/unittest/python/test_matrix.py +++ b/unittest/python/test_matrix.py @@ -5,6 +5,14 @@ import matrix as eigenpy verbose = True +if verbose: print("===> From empty MatrixXd to Py") +M = eigenpy.emptyMatrix() +assert M.shape == (0,0) + +if verbose: print("===> From empty VectorXd to Py") +v = eigenpy.emptyVector() +assert v.shape == (0,1) + if verbose: print("===> From MatrixXd to Py") M = eigenpy.naturals(3,3,verbose) Mcheck = np.reshape(np.matrix(range(9),np.double),[3,3])