swig

How to implement Array in python Swig.?

守給你的承諾、 提交于 2021-02-11 06:31:19
问题 I am wrote sample C++ application. Now I am going communicate with Python through Swig. What I did Generated interface file for my function classify.i %module example %{ #include "Facdetect.h" %} %include "typemaps.i" %include "cstring.i" %include "cdata.i" %include <std_string.i> %apply unsigned char *{unsigned char *x}; %apply double *INOUT{double *y}; %include "Facdetect.h" Facdetect.h #include <iostream> class facedetect { public: void display(unsigned char *x,double *y); }; sample.cpp

How to implement Array in python Swig.?

∥☆過路亽.° 提交于 2021-02-11 06:30:25
问题 I am wrote sample C++ application. Now I am going communicate with Python through Swig. What I did Generated interface file for my function classify.i %module example %{ #include "Facdetect.h" %} %include "typemaps.i" %include "cstring.i" %include "cdata.i" %include <std_string.i> %apply unsigned char *{unsigned char *x}; %apply double *INOUT{double *y}; %include "Facdetect.h" Facdetect.h #include <iostream> class facedetect { public: void display(unsigned char *x,double *y); }; sample.cpp

C++ & Python: Pass and return a 2D double pointer array from python to c++

℡╲_俬逩灬. 提交于 2021-02-10 14:17:21
问题 I want to pass a 2D array from Python to a C++ function and then return an array of the same type, same dimensions, to Python. I am aware this question has already been asked several times, but I haven't been able to find a relevant answer to my question. For my problem, I must use a double pointer array and have the function returning a double pointer array (not void as many examples show). My C++ function is: #include <stdio.h> #include <stdlib.h> extern "C" double** dot(double **a, int m,

setup.py not installing swig extension module

半世苍凉 提交于 2021-02-09 09:31:57
问题 I'm struggling to figure out how to copy the wrapper generated by swig at the same level than the swig shared library. Consider this tree structure: │ .gitignore │ setup.py │ ├───hello ├───src │ hello.c │ hello.h │ hello.i │ └───test test_hello.py and this setup.py: import os import sys from setuptools import setup, find_packages, Extension from setuptools.command.build_py import build_py as _build_py class build_py(_build_py): def run(self): self.run_command("build_ext") return super().run()

SWIG and Boost::variant

不打扰是莪最后的温柔 提交于 2021-02-08 17:44:09
问题 I'm in the middle of trying to wrap a c++ project into a python api using SWIG and I'm running into an issue with code that has the following format. class A { //constructors and such. }; class B { //constructors and such. }; class C { //constructors and such. }; typedef boost::variant<A,B,C> VariantType; typedef std::vector<boost::variant<A,B,C>> VariantTypeList; Classes A,B & C all come out in the python wrapper without a problem and seem to be usable. However when I try to add the

SWIG and Boost::variant

南楼画角 提交于 2021-02-08 17:42:00
问题 I'm in the middle of trying to wrap a c++ project into a python api using SWIG and I'm running into an issue with code that has the following format. class A { //constructors and such. }; class B { //constructors and such. }; class C { //constructors and such. }; typedef boost::variant<A,B,C> VariantType; typedef std::vector<boost::variant<A,B,C>> VariantTypeList; Classes A,B & C all come out in the python wrapper without a problem and seem to be usable. However when I try to add the

SWIG and Boost::variant

家住魔仙堡 提交于 2021-02-08 17:38:47
问题 I'm in the middle of trying to wrap a c++ project into a python api using SWIG and I'm running into an issue with code that has the following format. class A { //constructors and such. }; class B { //constructors and such. }; class C { //constructors and such. }; typedef boost::variant<A,B,C> VariantType; typedef std::vector<boost::variant<A,B,C>> VariantTypeList; Classes A,B & C all come out in the python wrapper without a problem and seem to be usable. However when I try to add the

Create a copy class method for a Python object containing a Swig object

喜欢而已 提交于 2021-02-08 09:18:30
问题 I have created a Python class with an attribute that is a Swig object (which happens to be a wrapper of a C structure). I want to be able to create copies of that class, e.g., by defining a __copy__ method, that contain independent copies of the Swig object (using the copy modules' copy class just creates a pointer to the original object, and deepcopy fails). Does anyone know if you can just copy chunks of memory in Python, and use this to copy the attribute containing the Swig object? Or,

Create a copy class method for a Python object containing a Swig object

霸气de小男生 提交于 2021-02-08 09:18:12
问题 I have created a Python class with an attribute that is a Swig object (which happens to be a wrapper of a C structure). I want to be able to create copies of that class, e.g., by defining a __copy__ method, that contain independent copies of the Swig object (using the copy modules' copy class just creates a pointer to the original object, and deepcopy fails). Does anyone know if you can just copy chunks of memory in Python, and use this to copy the attribute containing the Swig object? Or,

Python callback from C++

随声附和 提交于 2021-02-08 07:25:21
问题 I have a C++ class class EventHandler { virtual long readFromDaemon(void *buf, size_t count) = 0; }; and a Python program that uses it class Handler(EventHandler): def readFromDaemon(self, buf, count): ... C++ code calls EventHandler::readFromDaemon(). SWIG converts arguments and calls Python's readFromDaemon(): long SwigDirector_EventHandler::readFromDaemon(void *buf, size_t count) { ... swig::SwigVar_PyObject obj0; obj0 = SWIG_NewPointerObj(SWIG_as_voidptr(buf), SWIGTYPE_p_void, 0 ); swig: