Skip to content

Commit aaa031d

Browse files
authored
Merge pull request #36 from jcarpent/devel
Handle zero-size vector
2 parents be1ef56 + b869723 commit aaa031d

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

include/eigenpy/map.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ namespace eigenpy
9494

9595
int rowMajor;
9696
if( PyArray_NDIM(pyArray)==1 ) rowMajor = 0;
97+
else if (PyArray_DIMS(pyArray)[0] == 0) rowMajor = 0; // handle zero-size vector
98+
else if (PyArray_DIMS(pyArray)[1] == 0) rowMajor = 1; // handle zero-size vector
9799
else rowMajor = (PyArray_DIMS(pyArray)[0]>PyArray_DIMS(pyArray)[1])?0:1;
98100

99101
assert( (PyArray_DIMS(pyArray)[rowMajor]< INT_MAX)

unittest/matrix.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014, Nicolas Mansard, LAAS-CNRS
2+
* Copyright 2014,2018, Nicolas Mansard, Justin Carpentier, LAAS-CNRS
33
*
44
* This file is part of eigenpy.
55
* eigenpy is free software: you can redistribute it and/or
@@ -17,6 +17,18 @@
1717
#include "eigenpy/eigenpy.hpp"
1818
#include <iostream>
1919

20+
Eigen::VectorXd emptyVector()
21+
{
22+
Eigen::VectorXd vec;
23+
vec.resize(0);
24+
return vec;
25+
}
26+
27+
Eigen::MatrixXd emptyMatrix()
28+
{
29+
return Eigen::MatrixXd(0,0);
30+
}
31+
2032
Eigen::MatrixXd naturals(int R,int C,bool verbose)
2133
{
2234
Eigen::MatrixXd mat(R,C);
@@ -77,4 +89,7 @@ BOOST_PYTHON_MODULE(matrix)
7789
bp::def("reflexV", reflex<Eigen::VectorXd>);
7890
bp::def("reflex33", reflex<Eigen::Matrix3d>);
7991
bp::def("reflex3", reflex<Eigen::Vector3d>);
92+
93+
bp::def("emptyVector", emptyVector);
94+
bp::def("emptyMatrix", emptyMatrix);
8095
}

unittest/python/test_matrix.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55

66
verbose = True
77

8+
if verbose: print("===> From empty MatrixXd to Py")
9+
M = eigenpy.emptyMatrix()
10+
assert M.shape == (0,0)
11+
12+
if verbose: print("===> From empty VectorXd to Py")
13+
v = eigenpy.emptyVector()
14+
assert v.shape == (0,1)
15+
816
if verbose: print("===> From MatrixXd to Py")
917
M = eigenpy.naturals(3,3,verbose)
1018
Mcheck = np.reshape(np.matrix(range(9),np.double),[3,3])

0 commit comments

Comments
 (0)