Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Stack Of Tasks
eigenpy
Commits
836ea585
Verified
Commit
836ea585
authored
Feb 21, 2020
by
Justin Carpentier
Browse files
core: import numpy only once
parent
b5c16913
Changes
8
Hide whitespace changes
Inline
Side-by-side
CMakeLists.txt
View file @
836ea585
...
...
@@ -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
...
...
include/eigenpy/details.hpp
View file @
836ea585
...
...
@@ -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
>
>
();
...
...
include/eigenpy/fwd.hpp
View file @
836ea585
...
...
@@ -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__
include/eigenpy/map.hpp
View file @
836ea585
...
...
@@ -7,7 +7,6 @@
#define __eigenpy_map_hpp__
#include
"eigenpy/fwd.hpp"
#include
<numpy/arrayobject.h>
#include
"eigenpy/exception.hpp"
#include
"eigenpy/stride.hpp"
...
...
include/eigenpy/numpy-type.hpp
View file @
836ea585
...
...
@@ -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__
include/eigenpy/numpy.hpp
0 → 100644
View file @
836ea585
/*
* 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__
src/eigenpy.cpp
View file @
836ea585
...
...
@@ -28,6 +28,7 @@ namespace eigenpy
void
enableEigenPy
()
{
using
namespace
Eigen
;
import_numpy
();
Exception
::
registerException
();
...
...
src/numpy.cpp
0 → 100644
View file @
836ea585
/*
* 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;
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment