pybind11

How can you bind exceptions with custom fields and constructors in pybind11 and still have them function as python exception?

你。 提交于 2021-02-08 11:15:26
问题 This appears to be a known limitation in pybind11. I read through all the docs, whatever bug reports seemed applicable, and everything I could find in the pybind11 gitter. I have a custom exception class in c++ that contains custom constructors and fields. A very basic example of such a class, trimmed for space is here: class BadData : public std::exception { public: // Constructors BadData() : msg(), stack(), _name("BadData") {} BadData(std::string _msg, std::string _stack) : msg(_msg),

How can you bind exceptions with custom fields and constructors in pybind11 and still have them function as python exception?

亡梦爱人 提交于 2021-02-08 11:14:10
问题 This appears to be a known limitation in pybind11. I read through all the docs, whatever bug reports seemed applicable, and everything I could find in the pybind11 gitter. I have a custom exception class in c++ that contains custom constructors and fields. A very basic example of such a class, trimmed for space is here: class BadData : public std::exception { public: // Constructors BadData() : msg(), stack(), _name("BadData") {} BadData(std::string _msg, std::string _stack) : msg(_msg),

Pass python list to C/C++ as 'float*' or 'int*'

亡梦爱人 提交于 2021-02-08 06:57:53
问题 C/C++ void func(float* xyz1, float* xyz2,int n){ //do something for(int i=0; i<n;i++){ printf("%f %f\n",xyz1[i],xyz2[i]); } } Python import numpy as np n = 1000000 xyz1 = np.random.random((n,)).tolist() xyz2 = np.random.random((n,)).tolist() #pass above array to the C/C++ code for further processing. func(xyz1,xyz2,n) # <-- the call to the c/c++ code I have seen examples that call the C++ code using more high-level data structures like C++'s array . However, I simply want to pass it using

Getting undefined reference when trying to build a pybind11 project using gcc

Deadly 提交于 2021-02-08 06:40:54
问题 I am trying to build a C++ static library in Linux (Ubuntu 18.04 in my case) using GCC using a Makefile . I noticed the issue is not with the makefile itself but the way I'm trying to compile and build with GCC. Before I explain a bit more on the GCC side, here is how my current project hierarchy looks like. The project uses Pybind11 header only library which resides in the External_Libraries directory. My class definition and implementation, naming Core.h and Core.cpp reside in Internal

How to convert PyArrow table to Arrow table when interfacing between PyArrow in python and Arrow in C++

旧时模样 提交于 2021-02-08 04:37:27
问题 I have a C++ library which is built against the Apache Arrow C++ libraries, with a binding to python using Pybind. I'd like to be able to write a function in C++ to take a table constructed with PyArrow, like: void test(arrow::Table test); Passing in a PyArrow table like: tab = pa.Table.from_pandas(df) mybinding.test(tab) If I do a naive function as above, I get: TypeError: arrow_test(): incompatible function arguments. The following argument types are supported: 1. (arg0: arrow::Table) ->

Pybind11 - Returning a pointer to a container of unique_ptr

不问归期 提交于 2021-02-07 14:58:49
问题 I've been using the excellent pybind11 library but have hit a brick wall. I need to return to Python a pointer to a non-copyable object (as the object contains unique_ptrs). Generally this works fine with caveat of using return_value_policy::reference. However, returning a pointer to an object that has vector of non-copyable's results in a compilation error. It seems pybind wants to perform a copy in this case even though the return value policy is reference and the function explicitly

Pybind11 - Returning a pointer to a container of unique_ptr

怎甘沉沦 提交于 2021-02-07 14:58:13
问题 I've been using the excellent pybind11 library but have hit a brick wall. I need to return to Python a pointer to a non-copyable object (as the object contains unique_ptrs). Generally this works fine with caveat of using return_value_policy::reference. However, returning a pointer to an object that has vector of non-copyable's results in a compilation error. It seems pybind wants to perform a copy in this case even though the return value policy is reference and the function explicitly

Extending C++ to Python using Pybind11

强颜欢笑 提交于 2021-02-06 08:52:12
问题 I have got some code written in c++ which i am trying to use in python without rewriting the complete code in python again and i am using Pybind11 to build a python module for that. I am trying to achieve this thing in Microsoft Visual Studio 2015 by following this tutorial here https://pybind11.readthedocs.io/en/stable/basics.html I did following things in visual studio. 1) Downloaded Pybind11 from https://codeload.github.com/pybind/pybind11/zip/master 2) Unzipped the file 3) In visual

pybind11 “Python is 64-bit, chosen compiler is 32-bit”

我是研究僧i 提交于 2021-02-02 06:52:10
问题 I'm trying to compile pybind11 on a Windows machine that has VisualStudio 2015 installed. I also have python 3.5.3 64bit installed, and cmake 2.8.12. I get the error: CMake Error at tools/FindPythonLibsNew.cmake:122 (message): Python config failure: Python is 64-bit, chosen compiler is 32-bit Call Stack (most recent call first): tools/pybind11Tools.cmake:16 (find_package) CMakeLists.txt:28 (include) I did not "choose" the compiler to be 32-bit, and looking at the CMakeLists.txt, I did not

pybind11 “Python is 64-bit, chosen compiler is 32-bit”

时光毁灭记忆、已成空白 提交于 2021-02-02 06:47:45
问题 I'm trying to compile pybind11 on a Windows machine that has VisualStudio 2015 installed. I also have python 3.5.3 64bit installed, and cmake 2.8.12. I get the error: CMake Error at tools/FindPythonLibsNew.cmake:122 (message): Python config failure: Python is 64-bit, chosen compiler is 32-bit Call Stack (most recent call first): tools/pybind11Tools.cmake:16 (find_package) CMakeLists.txt:28 (include) I did not "choose" the compiler to be 32-bit, and looking at the CMakeLists.txt, I did not