mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-22 13:15:12 +00:00
A few breaking changes for consistency just before the 1.0 release
1. Renamed PYTHON_* to PYBIND_* everywhere 2. Renamed pybind::array_dtype<> to pybind::array_t<>
This commit is contained in:
parent
19208fe9a4
commit
b50872acf2
@ -22,7 +22,7 @@ void init_ex10(py::module &);
|
|||||||
void init_ex11(py::module &);
|
void init_ex11(py::module &);
|
||||||
void init_ex12(py::module &);
|
void init_ex12(py::module &);
|
||||||
|
|
||||||
PYTHON_PLUGIN(example) {
|
PYBIND_PLUGIN(example) {
|
||||||
py::module m("example", "pybind example plugin");
|
py::module m("example", "pybind example plugin");
|
||||||
|
|
||||||
init_ex1(m);
|
init_ex1(m);
|
||||||
|
@ -26,7 +26,7 @@ void init_ex10(py::module &m) {
|
|||||||
|
|
||||||
// Vectorize a lambda function with a capture object (e.g. to exclude some arguments from the vectorization)
|
// Vectorize a lambda function with a capture object (e.g. to exclude some arguments from the vectorization)
|
||||||
m.def("vectorized_func2",
|
m.def("vectorized_func2",
|
||||||
[](py::array_dtype<int> x, py::array_dtype<float> y, float z) {
|
[](py::array_t<int> x, py::array_t<float> y, float z) {
|
||||||
return py::vectorize([z](int x, float y) { return my_func(x, y, z); })(x, y);
|
return py::vectorize([z](int x, float y) { return my_func(x, y, z); })(x, y);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -16,11 +16,11 @@
|
|||||||
#define NAMESPACE_END(name) }
|
#define NAMESPACE_END(name) }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(PYTHON_EXPORT)
|
#if !defined(PYBIND_EXPORT)
|
||||||
#if defined(WIN32) || defined(_WIN32)
|
#if defined(WIN32) || defined(_WIN32)
|
||||||
#define PYTHON_EXPORT __declspec(dllexport)
|
#define PYBIND_EXPORT __declspec(dllexport)
|
||||||
#else
|
#else
|
||||||
#define PYTHON_EXPORT __attribute__ ((visibility("default")))
|
#define PYBIND_EXPORT __attribute__ ((visibility("default")))
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -61,11 +61,11 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if PY_MAJOR_VERSION >= 3
|
#if PY_MAJOR_VERSION >= 3
|
||||||
#define PYTHON_PLUGIN(name) \
|
#define PYBIND_PLUGIN(name) \
|
||||||
extern "C" PYTHON_EXPORT PyObject *PyInit_##name()
|
extern "C" PYBIND_EXPORT PyObject *PyInit_##name()
|
||||||
#else
|
#else
|
||||||
#define PYTHON_PLUGIN(name) \
|
#define PYBIND_PLUGIN(name) \
|
||||||
extern "C" PYTHON_EXPORT PyObject *init##name()
|
extern "C" PYBIND_EXPORT PyObject *init##name()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
NAMESPACE_BEGIN(pybind)
|
NAMESPACE_BEGIN(pybind)
|
||||||
|
@ -124,10 +124,10 @@ protected:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T> class array_dtype : public array {
|
template <typename T> class array_t : public array {
|
||||||
public:
|
public:
|
||||||
PYBIND_OBJECT_CVT(array_dtype, array, is_non_null, m_ptr = ensure(m_ptr));
|
PYBIND_OBJECT_CVT(array_t, array, is_non_null, m_ptr = ensure(m_ptr));
|
||||||
array_dtype() : array() { }
|
array_t() : array() { }
|
||||||
static bool is_non_null(PyObject *ptr) { return ptr != nullptr; }
|
static bool is_non_null(PyObject *ptr) { return ptr != nullptr; }
|
||||||
PyObject *ensure(PyObject *ptr) {
|
PyObject *ensure(PyObject *ptr) {
|
||||||
if (ptr == nullptr)
|
if (ptr == nullptr)
|
||||||
@ -151,14 +151,14 @@ DECL_FMT(std::complex<double>, NPY_CDOUBLE);
|
|||||||
|
|
||||||
NAMESPACE_BEGIN(detail)
|
NAMESPACE_BEGIN(detail)
|
||||||
PYBIND_TYPE_CASTER_PYTYPE(array)
|
PYBIND_TYPE_CASTER_PYTYPE(array)
|
||||||
PYBIND_TYPE_CASTER_PYTYPE(array_dtype<int8_t>) PYBIND_TYPE_CASTER_PYTYPE(array_dtype<uint8_t>)
|
PYBIND_TYPE_CASTER_PYTYPE(array_t<int8_t>) PYBIND_TYPE_CASTER_PYTYPE(array_t<uint8_t>)
|
||||||
PYBIND_TYPE_CASTER_PYTYPE(array_dtype<int16_t>) PYBIND_TYPE_CASTER_PYTYPE(array_dtype<uint16_t>)
|
PYBIND_TYPE_CASTER_PYTYPE(array_t<int16_t>) PYBIND_TYPE_CASTER_PYTYPE(array_t<uint16_t>)
|
||||||
PYBIND_TYPE_CASTER_PYTYPE(array_dtype<int32_t>) PYBIND_TYPE_CASTER_PYTYPE(array_dtype<uint32_t>)
|
PYBIND_TYPE_CASTER_PYTYPE(array_t<int32_t>) PYBIND_TYPE_CASTER_PYTYPE(array_t<uint32_t>)
|
||||||
PYBIND_TYPE_CASTER_PYTYPE(array_dtype<int64_t>) PYBIND_TYPE_CASTER_PYTYPE(array_dtype<uint64_t>)
|
PYBIND_TYPE_CASTER_PYTYPE(array_t<int64_t>) PYBIND_TYPE_CASTER_PYTYPE(array_t<uint64_t>)
|
||||||
PYBIND_TYPE_CASTER_PYTYPE(array_dtype<float>) PYBIND_TYPE_CASTER_PYTYPE(array_dtype<double>)
|
PYBIND_TYPE_CASTER_PYTYPE(array_t<float>) PYBIND_TYPE_CASTER_PYTYPE(array_t<double>)
|
||||||
PYBIND_TYPE_CASTER_PYTYPE(array_dtype<std::complex<float>>)
|
PYBIND_TYPE_CASTER_PYTYPE(array_t<std::complex<float>>)
|
||||||
PYBIND_TYPE_CASTER_PYTYPE(array_dtype<std::complex<double>>)
|
PYBIND_TYPE_CASTER_PYTYPE(array_t<std::complex<double>>)
|
||||||
PYBIND_TYPE_CASTER_PYTYPE(array_dtype<bool>)
|
PYBIND_TYPE_CASTER_PYTYPE(array_t<bool>)
|
||||||
|
|
||||||
template <typename Func, typename Return, typename... Args>
|
template <typename Func, typename Return, typename... Args>
|
||||||
struct vectorize_helper {
|
struct vectorize_helper {
|
||||||
@ -167,11 +167,11 @@ struct vectorize_helper {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
vectorize_helper(T&&f) : f(std::forward<T>(f)) { }
|
vectorize_helper(T&&f) : f(std::forward<T>(f)) { }
|
||||||
|
|
||||||
object operator()(array_dtype<Args>... args) {
|
object operator()(array_t<Args>... args) {
|
||||||
return run(args..., typename make_index_sequence<sizeof...(Args)>::type());
|
return run(args..., typename make_index_sequence<sizeof...(Args)>::type());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <size_t ... Index> object run(array_dtype<Args>&... args, index_sequence<Index...>) {
|
template <size_t ... Index> object run(array_t<Args>&... args, index_sequence<Index...>) {
|
||||||
/* Request buffers from all parameters */
|
/* Request buffers from all parameters */
|
||||||
const size_t N = sizeof...(Args);
|
const size_t N = sizeof...(Args);
|
||||||
std::array<buffer_info, N> buffers {{ args.request()... }};
|
std::array<buffer_info, N> buffers {{ args.request()... }};
|
||||||
|
Loading…
Reference in New Issue
Block a user