Unverified Commit eb627859 authored by Justin Carpentier's avatar Justin Carpentier Committed by GitHub
Browse files

Merge pull request #85 from jcarpent/devel

Minor smoothing + sync submodule cmake
parents 92c3de26 128e29e4
Subproject commit ab4c798680d0a3ba4e84d3b7f25cc42d336eca1b
Subproject commit b58bd669f6567662eefb8a410e8e40aeba4f1060
......@@ -24,7 +24,7 @@ namespace eigenpy
template <typename SCALAR> struct NumpyEquivalentType {};
template <> struct NumpyEquivalentType<double> { enum { type_code = NPY_DOUBLE };};
template <> struct NumpyEquivalentType<int> { enum { type_code = NPY_INT };};
template <> struct NumpyEquivalentType<long> { enum { type_code = NPY_LONG };};
template <> struct NumpyEquivalentType<long> { enum { type_code = NPY_LONG };};
template <> struct NumpyEquivalentType<float> { enum { type_code = NPY_FLOAT };};
template <typename SCALAR1, typename SCALAR2>
......@@ -181,8 +181,8 @@ namespace eigenpy
/// \brief Copy mat into the Python array using Eigen::Map
template<typename MatrixDerived>
static void convert(const Eigen::MatrixBase<MatrixDerived> & mat_,
PyArrayObject * pyArray)
static void copy(const Eigen::MatrixBase<MatrixDerived> & mat_,
PyArrayObject * pyArray)
{
const MatrixDerived & mat = const_cast<const MatrixDerived &>(mat_.derived());
......@@ -231,9 +231,9 @@ namespace eigenpy
new (storage) Type(numpyMap);
}
static void convert(Type const & mat, PyArrayObject * pyArray)
static void copy(Type const & mat, PyArrayObject * pyArray)
{
EigenObjectAllocator<MatType>::convert(mat,pyArray);
EigenObjectAllocator<MatType>::copy(mat,pyArray);
}
};
#endif
......@@ -266,7 +266,7 @@ namespace eigenpy
}
// Allocate memory
EigenObjectAllocator<MatType>::convert(mat,pyArray);
EigenObjectAllocator<MatType>::copy(mat,pyArray);
// Create an instance (either np.array or np.matrix)
return NumpyType::getInstance().make(pyArray).ptr();
......@@ -279,18 +279,18 @@ namespace eigenpy
struct EigenFromPy
{
/// \brief Determine if pyObj can be converted into a MatType object
static void* convertible(PyArrayObject* pyObj)
static void* convertible(PyArrayObject* pyArray)
{
if (!PyArray_Check(pyObj))
if(!PyArray_Check(pyArray))
return 0;
if(MatType::IsVectorAtCompileTime)
{
// Special care of scalar matrix of dimension 1x1.
if(PyArray_DIMS(pyObj)[0] == 1 && PyArray_DIMS(pyObj)[1] == 1)
return pyObj;
if(PyArray_DIMS(pyArray)[0] == 1 && PyArray_DIMS(pyArray)[1] == 1)
return pyArray;
if(PyArray_DIMS(pyObj)[0] > 1 && PyArray_DIMS(pyObj)[1] > 1)
if(PyArray_DIMS(pyArray)[0] > 1 && PyArray_DIMS(pyArray)[1] > 1)
{
#ifndef NDEBUG
std::cerr << "The number of dimension of the object does not correspond to a vector" << std::endl;
......@@ -298,8 +298,8 @@ namespace eigenpy
return 0;
}
if(((PyArray_DIMS(pyObj)[0] == 1) && (MatType::ColsAtCompileTime == 1))
|| ((PyArray_DIMS(pyObj)[1] == 1) && (MatType::RowsAtCompileTime == 1)))
if(((PyArray_DIMS(pyArray)[0] == 1) && (MatType::ColsAtCompileTime == 1))
|| ((PyArray_DIMS(pyArray)[1] == 1) && (MatType::RowsAtCompileTime == 1)))
{
#ifndef NDEBUG
if(MatType::ColsAtCompileTime == 1)
......@@ -311,9 +311,9 @@ namespace eigenpy
}
}
if (PyArray_NDIM(pyObj) != 2)
if(PyArray_NDIM(pyArray) != 2)
{
if ( (PyArray_NDIM(pyObj) !=1) || (! MatType::IsVectorAtCompileTime) )
if ( (PyArray_NDIM(pyArray) !=1) || (! MatType::IsVectorAtCompileTime) )
{
#ifndef NDEBUG
std::cerr << "The number of dimension of the object is not correct." << std::endl;
......@@ -322,10 +322,10 @@ namespace eigenpy
}
}
if (PyArray_NDIM(pyObj) == 2)
if(PyArray_NDIM(pyArray) == 2)
{
const int R = (int)PyArray_DIMS(pyObj)[0];
const int C = (int)PyArray_DIMS(pyObj)[1];
const int R = (int)PyArray_DIMS(pyArray)[0];
const int C = (int)PyArray_DIMS(pyArray)[1];
if( (MatType::RowsAtCompileTime!=R)
&& (MatType::RowsAtCompileTime!=Eigen::Dynamic) )
......@@ -336,7 +336,7 @@ namespace eigenpy
}
// Check if the Scalar type of the obj_ptr is compatible with the Scalar type of MatType
if ((PyArray_ObjectType(reinterpret_cast<PyObject *>(pyObj), 0)) == NPY_INT)
if(GET_PY_ARRAY_TYPE(pyArray) == NPY_INT)
{
if(!FromTypeToType<int,typename MatType::Scalar>::value)
{
......@@ -346,7 +346,7 @@ namespace eigenpy
return 0;
}
}
else if ((PyArray_ObjectType(reinterpret_cast<PyObject *>(pyObj), 0)) == NPY_LONG)
else if(GET_PY_ARRAY_TYPE(pyArray) == NPY_LONG)
{
if(!FromTypeToType<long,typename MatType::Scalar>::value)
{
......@@ -356,7 +356,7 @@ namespace eigenpy
return 0;
}
}
else if ((PyArray_ObjectType(reinterpret_cast<PyObject *>(pyObj), 0)) == NPY_FLOAT)
else if(GET_PY_ARRAY_TYPE(pyArray) == NPY_FLOAT)
{
if(!FromTypeToType<float,typename MatType::Scalar>::value)
{
......@@ -366,7 +366,7 @@ namespace eigenpy
return 0;
}
}
else if ((PyArray_ObjectType(reinterpret_cast<PyObject *>(pyObj), 0)) == NPY_DOUBLE)
else if(GET_PY_ARRAY_TYPE(pyArray) == NPY_DOUBLE)
{
if(!FromTypeToType<double,typename MatType::Scalar>::value)
{
......@@ -376,8 +376,7 @@ namespace eigenpy
return 0;
}
}
else if ((PyArray_ObjectType(reinterpret_cast<PyObject *>(pyObj), 0))
!= NumpyEquivalentType<typename MatType::Scalar>::type_code)
else if(GET_PY_ARRAY_TYPE(pyArray) != NumpyEquivalentType<typename MatType::Scalar>::type_code)
{
#ifndef NDEBUG
std::cerr << "The internal type as no Eigen equivalent." << std::endl;
......@@ -387,9 +386,9 @@ namespace eigenpy
}
#ifdef NPY_1_8_API_VERSION
if (!(PyArray_FLAGS(pyObj)))
if(!(PyArray_FLAGS(pyArray)))
#else
if (!(PyArray_FLAGS(obj_ptr) & NPY_ALIGNED))
if(!(PyArray_FLAGS(pyArray) & NPY_ALIGNED))
#endif
{
#ifndef NDEBUG
......@@ -398,7 +397,7 @@ namespace eigenpy
return 0;
}
return pyObj;
return pyArray;
}
/// \brief Allocate memory and copy pyObj in the new storage
......
......@@ -10,14 +10,14 @@
namespace eigenpy
{
template<typename MatType, int IsVectorAtCompileTime = MatType::IsVectorAtCompileTime>
template<typename MatType, bool IsVectorAtCompileTime = MatType::IsVectorAtCompileTime>
struct StrideType
{
typedef Eigen::Stride<Eigen::Dynamic,Eigen::Dynamic> type;
};
template<typename MatType>
struct StrideType<MatType,1>
struct StrideType<MatType,true>
{
typedef Eigen::InnerStride<Eigen::Dynamic> type;
};
......
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