mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-30 00:47:12 +00:00
Remove erroneous py:: prefix in numpy.h
This commit is contained in:
parent
873d267471
commit
036e8cd32f
@ -118,7 +118,7 @@ public:
|
|||||||
buf_info.ptr = std::calloc(info.size, info.itemsize);
|
buf_info.ptr = std::calloc(info.size, info.itemsize);
|
||||||
if (!buf_info.ptr)
|
if (!buf_info.ptr)
|
||||||
pybind11_fail("NumPy: failed to allocate memory for buffer");
|
pybind11_fail("NumPy: failed to allocate memory for buffer");
|
||||||
auto view = py::memoryview(buf_info);
|
auto view = memoryview(buf_info);
|
||||||
|
|
||||||
API& api = lookup_api();
|
API& api = lookup_api();
|
||||||
auto res = api.PyArray_GetArrayParamsFromObject_(view.ptr(), nullptr, 1, &descr,
|
auto res = api.PyArray_GetArrayParamsFromObject_(view.ptr(), nullptr, 1, &descr,
|
||||||
@ -178,8 +178,8 @@ private:
|
|||||||
array::API::NPY_INT_, array::API::NPY_UINT_, array::API::NPY_LONGLONG_, array::API::NPY_ULONGLONG_ };
|
array::API::NPY_INT_, array::API::NPY_UINT_, array::API::NPY_LONGLONG_, array::API::NPY_ULONGLONG_ };
|
||||||
public:
|
public:
|
||||||
static int typenum() { return values[detail::log2(sizeof(T)) * 2 + (std::is_unsigned<T>::value ? 1 : 0)]; }
|
static int typenum() { return values[detail::log2(sizeof(T)) * 2 + (std::is_unsigned<T>::value ? 1 : 0)]; }
|
||||||
static py::object descr() {
|
static object descr() {
|
||||||
if (auto ptr = array::lookup_api().PyArray_DescrFromType_(typenum())) return py::object(ptr, true);
|
if (auto ptr = array::lookup_api().PyArray_DescrFromType_(typenum())) return object(ptr, true);
|
||||||
else pybind11_fail("Unsupported buffer format!");
|
else pybind11_fail("Unsupported buffer format!");
|
||||||
}
|
}
|
||||||
template <typename T2 = T, typename std::enable_if<std::is_signed<T2>::value, int>::type = 0>
|
template <typename T2 = T, typename std::enable_if<std::is_signed<T2>::value, int>::type = 0>
|
||||||
@ -192,8 +192,8 @@ template <typename T> constexpr const int npy_format_descriptor<
|
|||||||
|
|
||||||
#define DECL_FMT(Type, NumPyName, Name) template<> struct npy_format_descriptor<Type> { \
|
#define DECL_FMT(Type, NumPyName, Name) template<> struct npy_format_descriptor<Type> { \
|
||||||
static int typenum() { return array::API::NumPyName; } \
|
static int typenum() { return array::API::NumPyName; } \
|
||||||
static py::object descr() { \
|
static object descr() { \
|
||||||
if (auto ptr = array::lookup_api().PyArray_DescrFromType_(typenum())) return py::object(ptr, true); \
|
if (auto ptr = array::lookup_api().PyArray_DescrFromType_(typenum())) return object(ptr, true); \
|
||||||
else pybind11_fail("Unsupported buffer format!"); \
|
else pybind11_fail("Unsupported buffer format!"); \
|
||||||
} \
|
} \
|
||||||
static PYBIND11_DESCR name() { return _(Name); } }
|
static PYBIND11_DESCR name() { return _(Name); } }
|
||||||
@ -207,7 +207,7 @@ DECL_FMT(std::complex<double>, NPY_CDOUBLE_, "complex128");
|
|||||||
struct field_descriptor {
|
struct field_descriptor {
|
||||||
const char *name;
|
const char *name;
|
||||||
int offset;
|
int offset;
|
||||||
py::object descr;
|
object descr;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T> struct npy_format_descriptor
|
template <typename T> struct npy_format_descriptor
|
||||||
@ -220,10 +220,10 @@ template <typename T> struct npy_format_descriptor
|
|||||||
{
|
{
|
||||||
static PYBIND11_DESCR name() { return _("user-defined"); }
|
static PYBIND11_DESCR name() { return _("user-defined"); }
|
||||||
|
|
||||||
static py::object descr() {
|
static object descr() {
|
||||||
if (!descr_())
|
if (!descr_())
|
||||||
pybind11_fail("NumPy: unsupported buffer format!");
|
pybind11_fail("NumPy: unsupported buffer format!");
|
||||||
return py::object(descr_(), true);
|
return object(descr_(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* format_str() {
|
static const char* format_str() {
|
||||||
@ -232,13 +232,13 @@ template <typename T> struct npy_format_descriptor
|
|||||||
|
|
||||||
static void register_dtype(std::initializer_list<field_descriptor> fields) {
|
static void register_dtype(std::initializer_list<field_descriptor> fields) {
|
||||||
array::API& api = array::lookup_api();
|
array::API& api = array::lookup_api();
|
||||||
auto args = py::dict();
|
auto args = dict();
|
||||||
py::list names { }, offsets { }, formats { };
|
list names { }, offsets { }, formats { };
|
||||||
for (auto field : fields) {
|
for (auto field : fields) {
|
||||||
if (!field.descr)
|
if (!field.descr)
|
||||||
pybind11_fail("NumPy: unsupported field dtype");
|
pybind11_fail("NumPy: unsupported field dtype");
|
||||||
names.append(py::str(field.name));
|
names.append(str(field.name));
|
||||||
offsets.append(py::int_(field.offset));
|
offsets.append(int_(field.offset));
|
||||||
formats.append(field.descr);
|
formats.append(field.descr);
|
||||||
}
|
}
|
||||||
args["names"] = names;
|
args["names"] = names;
|
||||||
@ -248,7 +248,7 @@ template <typename T> struct npy_format_descriptor
|
|||||||
pybind11_fail("NumPy: failed to create structured dtype");
|
pybind11_fail("NumPy: failed to create structured dtype");
|
||||||
auto np = module::import("numpy");
|
auto np = module::import("numpy");
|
||||||
auto empty = (object) np.attr("empty");
|
auto empty = (object) np.attr("empty");
|
||||||
if (auto arr = (object) empty(py::int_(0), object(descr(), true)))
|
if (auto arr = (object) empty(int_(0), object(descr(), true)))
|
||||||
if (auto view = PyMemoryView_FromObject(arr.ptr()))
|
if (auto view = PyMemoryView_FromObject(arr.ptr()))
|
||||||
if (auto info = PyMemoryView_GET_BUFFER(view)) {
|
if (auto info = PyMemoryView_GET_BUFFER(view)) {
|
||||||
std::strncpy(format_str_(), info->format, 4096);
|
std::strncpy(format_str_(), info->format, 4096);
|
||||||
|
Loading…
Reference in New Issue
Block a user