Skip to content

Commit ab133d8

Browse files
committed
Simplify import_numpy
1 parent 6fe5cf9 commit ab133d8

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

include/xtensor-python/pycontainer.hpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
#ifndef FORCE_IMPORT_ARRAY
2121
#define NO_IMPORT_ARRAY
22-
static int _import_array() { return 0; };
2322
#endif
2423
#ifndef PY_ARRAY_UNIQUE_SYMBOL
2524
#define PY_ARRAY_UNIQUE_SYMBOL xtensor_python_ARRAY_API
@@ -33,17 +32,7 @@ static int _import_array() { return 0; };
3332
namespace xt
3433
{
3534

36-
/**
37-
* Import the numpy Python module.
38-
*/
39-
inline void import_numpy()
40-
{
41-
if (_import_array() < 0)
42-
{
43-
PyErr_Print();
44-
PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import");
45-
}
46-
}
35+
inline void import_numpy();
4736

4837
/**
4938
* @class pycontainer
@@ -253,6 +242,19 @@ namespace xt
253242
*static_cast<derived_type*>(this) = std::move(tmp);
254243
}
255244

245+
/**
246+
* Import the numpy Python module.
247+
*/
248+
inline void import_numpy()
249+
{
250+
#ifdef FORCE_IMPORT_ARRAY
251+
if (_import_array() < 0)
252+
{
253+
PyErr_Print();
254+
PyErr_SetString(PyExc_ImportError, "numpy.core.multiarray failed to import");
255+
}
256+
#endif
257+
}
256258
}
257259

258260
#endif

0 commit comments

Comments
 (0)