-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathnumpy.cpp
More file actions
52 lines (46 loc) · 1.11 KB
/
Copy pathnumpy.cpp
File metadata and controls
52 lines (46 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright Jim Bosch 2010-2012.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#define BOOST_NUMPY_INTERNAL_MAIN
#include <boost/numpy/internal.hpp>
#include <boost/numpy/dtype.hpp>
namespace boost
{
namespace numpy
{
// NumPy's import_* macros always return if they encounter an error,
// but in Python 2 there's no return value, while Python 3 returns
// null on an error. The machinery below produces the same behavior
// on both Python versions: initialize returns false with an exception
// raised if there is an exception.
static
#if PY_MAJOR_VERSION == 2
void
#else
PyObject *
#endif
wrap_imports()
{
import_array();
import_ufunc();
#if PY_MAJOR_VERSION > 2
Py_RETURN_NONE;
#endif
}
bool initialize(bool register_scalar_converters)
{
#if PY_MAJOR_VERSION == 2
wrap_imports();
if (PyErr_Occurred()) return false;
#else
PyObject * r = wrap_imports();
if (!r) return false;
Py_DECREF(r);
#endif
if (register_scalar_converters)
dtype::register_scalar_converters();
return true;
}
}
}