Commit 92f9eb14 authored by Justin Carpentier's avatar Justin Carpentier Committed by GitHub
Browse files

Merge pull request #12 from jcarpent/devel

Fix bug in multiple dynamic link of the lib
parents 1065425e 3fb62039
......@@ -108,7 +108,6 @@ ENDFOREACH(header)
SET(${PROJECT_NAME}_SOURCES
src/exception.cpp
src/eigenpy.cpp
src/details.cpp
src/angle-axis.cpp
src/quaternion.cpp
)
......
/*
* Copyright (c) 2015 LAAS-CNRS
*
* This file is part of eigenpy.
* eigenpy is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
* eigenpy is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. You should
* have received a copy of the GNU Lesser General Public License along
* with eigenpy. If not, see <http://www.gnu.org/licenses/>.
*/
#include "eigenpy/details.hpp"
namespace eigenpy
{
PyMatrixType pyMatrixType = PyMatrixType();
} // namespace eigenpy
......@@ -35,31 +35,39 @@ namespace eigenpy
template <> struct NumpyEquivalentType<int> { enum { type_code = NPY_INT };};
template <> struct NumpyEquivalentType<float> { enum { type_code = NPY_FLOAT };};
namespace bp = boost::python;
struct PyMatrixType
{
boost::python::object pyMatrixType;
boost::python::object pyModule;
PyMatrixType()
static PyMatrixType & getInstance()
{
pyModule = boost::python::import("numpy");
pyMatrixType = pyModule.attr("matrix");
static PyMatrixType instance;
return instance;
}
operator boost::python::object () { return pyMatrixType; }
boost::python::object make(PyArrayObject* pyArray, bool copy = false)
operator bp::object () { return pyMatrixType; }
bp::object make(PyArrayObject* pyArray, bool copy = false)
{ return make((PyObject*)pyArray,copy); }
boost::python::object make(PyObject* pyObj, bool copy = false)
bp::object make(PyObject* pyObj, bool copy = false)
{
boost::python::object m
= pyMatrixType( boost::python::object(boost::python::handle<>(pyObj)),
boost::python::object(), copy );
= pyMatrixType(bp::object(bp::handle<>(pyObj)), bp::object(), copy);
Py_INCREF(m.ptr());
return m;
}
};
extern PyMatrixType pyMatrixType;
protected:
PyMatrixType()
{
pyModule = boost::python::import("numpy");
pyMatrixType = pyModule.attr("matrix");
}
bp::object pyMatrixType;
bp::object pyModule;
};
/* --- TO PYTHON -------------------------------------------------------------- */
template< typename MatType,typename EquivalentEigenType >
......@@ -78,7 +86,7 @@ namespace eigenpy
MapNumpy<EquivalentEigenType>::map(pyArray) = mat;
return pyMatrixType.make(pyArray).ptr();
return PyMatrixType::getInstance().make(pyArray).ptr();
}
};
......
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