Verified Commit 836ea585 authored by Justin Carpentier's avatar Justin Carpentier
Browse files

core: import numpy only once

parent b5c16913
......@@ -110,6 +110,7 @@ SET(${PROJECT_NAME}_HEADERS
include/eigenpy/geometry-conversion.hpp
include/eigenpy/memory.hpp
include/eigenpy/numpy-type.hpp
include/eigenpy/numpy.hpp
include/eigenpy/registration.hpp
include/eigenpy/angle-axis.hpp
include/eigenpy/quaternion.hpp
......@@ -141,6 +142,7 @@ SET(${PROJECT_NAME}_SOURCES
${${PROJECT_NAME}_DECOMPOSITIONS_SOURCES}
src/exception.cpp
src/eigenpy.cpp
src/numpy.cpp
src/matrix-float.cpp
src/matrix-complex-float.cpp
src/matrix-complex-double.cpp
......
......@@ -584,7 +584,6 @@ namespace eigenpy
template<typename MatType>
void enableEigenPySpecific()
{
numpy_import_array();
if(check_registration<MatType>()) return;
bp::to_python_converter<MatType,EigenToPy<MatType> >();
......
......@@ -11,12 +11,9 @@
#include <boost/python.hpp>
#include <Eigen/Core>
#include <numpy/numpyconfig.h>
#ifdef NPY_1_8_API_VERSION
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#endif
#include <numpy/noprefix.h>
#define NO_IMPORT_ARRAY
#include "eigenpy/numpy.hpp"
#undef NO_IMPORT_ARRAY
#ifdef NPY_ALIGNED
#if EIGEN_VERSION_AT_LEAST(3,2,90)
......@@ -31,4 +28,3 @@
#include "eigenpy/expose.hpp"
#endif // ifndef __eigenpy_fwd_hpp__
......@@ -7,7 +7,6 @@
#define __eigenpy_map_hpp__
#include "eigenpy/fwd.hpp"
#include <numpy/arrayobject.h>
#include "eigenpy/exception.hpp"
#include "eigenpy/stride.hpp"
......
......@@ -145,45 +145,6 @@ namespace eigenpy
NP_TYPE np_type;
};
namespace details
{
struct import_numpy
{
static bool status()
{
return instance().imported;
}
protected:
static import_numpy & instance()
{
static import_numpy m_instance;
return m_instance;
}
import_numpy()
: imported(false)
{
if(_import_array() < 0)
{
PyErr_Print();
PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import");
}
else
imported = true;
}
bool imported;
};
} // namespace details
inline bool numpy_import_array()
{
return details::import_numpy::status();
}
}
#endif // ifndef __eigenpy_numpy_type_hpp__
/*
* Copyright 2020 INRIA
*/
#ifndef __eigenpy_numpy_hpp__
#define __eigenpy_numpy_hpp__
#ifndef PY_ARRAY_UNIQUE_SYMBOL
#define PY_ARRAY_UNIQUE_SYMBOL EIGENPY_ARRAY_API
#endif
#include <numpy/numpyconfig.h>
#ifdef NPY_1_8_API_VERSION
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#endif
#include <numpy/noprefix.h>
namespace eigenpy
{
void import_numpy();
}
#endif // ifndef __eigenpy_numpy_hpp__
......@@ -28,6 +28,7 @@ namespace eigenpy
void enableEigenPy()
{
using namespace Eigen;
import_numpy();
Exception::registerException();
......
/*
* Copyright 2020 INRIA
*/
#include "eigenpy/numpy.hpp"
namespace eigenpy
{
void import_numpy()
{
if(_import_array() < 0)
{
PyErr_Print();
PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import");
}
// std::cout << "init _import_array " << std::endl;
}
}
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