Commit b869723e authored by jcarpent's avatar jcarpent
Browse files

[Conversion] Handle zero-size vector

parent be1ef56b
......@@ -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)
......
/*
* 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);
}
......@@ -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])
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment