swig

How to stringfy a swig matrix object in python

非 Y 不嫁゛ 提交于 2019-12-04 03:51:14
问题 I am using swig wrapper of openbabel (written in C++, and supply a python wrapper through swig) Below i just use it to read a molecule structure file and get the unitcell property of it. import pybel for molecule in pybel.readfile('pdb','./test.pdb'): unitcell = molecule.unitcell print unitcell |..> |..> <openbabel.OBUnitCell; proxy of <Swig Object of type 'OpenBabel::OBUnitCell *' at 0x17b390c0> > The unitcell has function CellMatrix(), unitcell.GetCellMatrix() <22> <openbabel.matrix3x3;

No iterator for Java when using SWIG with C++'s std::map

拥有回忆 提交于 2019-12-04 03:29:50
I have implemented a class with std::map in C++ and created interface using SWIG to be call from Java. However there is no iterator object that allows me to iterate through the entries in the SWIG wrapped std::map . Does anyone know how to create an iterator? In order to be able to iterate over an Object in Java it needs to implement Iterable . This in turn requires a member function called iterator() which returns a suitable implementation of an Iterator . From your question it's not quite clear if what types you're using in the map and if you want to be able to iterate over the pairs (as you

Swig, returning an array of doubles

别等时光非礼了梦想. 提交于 2019-12-04 03:01:32
I know, there are often many ways to solve certain problems. But here I know which way I want to have it, but I am unable to make it work with Python and SWIG... I have a C-function, which returns me an array of double values: double *my(int x) { double a,b,*buf; buf = malloc (x * sizeof(double)); a=3.14; b=2.7; buf[0]=a; buf[1]=b; return buf; } Here, I definitively want to have the array as a return value. Not, as in many examples a 'void' function, which writes into an input array. Now, I would like to get a SWIG-python wrapper, which might be used as: >>> import example >>> print example.my

SWIG: difference between %import and %include

梦想与她 提交于 2019-12-04 01:49:48
The SWIG docs explain these two directives as follows: %include : "To include another file into a SWIG interface, use the %include directive ... Unlike, #include , %include includes each file once (and will not reload the file on subsequent %include declarations). Therefore, it is not necessary to use include-guards in SWIG interfaces." %import : "SWIG provides another file inclusion directive with the %import directive ... The purpose of %import is to collect certain information from another SWIG interface file or a header file without actually generating any wrapper code. Such information

what does the last argument to SWIG_NewPointerObj mean?

断了今生、忘了曾经 提交于 2019-12-04 00:05:38
I have a compatibility library that uses SWIG to access a C++ library. I would find it useful to be able to create a SWIG-wrapped Python object inside this layer (as opposed to accepting the C++ object as an argument or returning one). I.e. I want the PyObject* that points to the SWIG-wrapped C++ object. I discovered that the SWIG_NewPointerObj function does exactly this. The SWIG-generated xx_wrap.cpp file uses this function, but it's also made available in the header emitted by swig -python -external-runtime swigpyrun.h HOWEVER, I cannot find any reference to what the last argument to this

Pocketsphinx install fail? Raspberry Pi Zero (Raspbian Jessie)

拟墨画扇 提交于 2019-12-03 23:24:33
This will probably get tagged as a duplicate, but I haven't had any luck, so here we go. I'm trying to develop a "Jarvis" like setup with Python2.7. I', looking to use Pocketsphinx as part of that. I tried to do this on my Windows 10 machine, but Pocketsphinx requires Swig, and that utterly failed on the Windows 10 machine (I'm still working on that.) So, I moved over to my Raspberry Pi Zero, since that is where I will be looking to impliment the actual program anyways. I got Swig to install just fine. None of the problems that Windows 10 had. Then I tried to install Pocketsphinx and things

Swig python - c++ how to use type int8_t

僤鯓⒐⒋嵵緔 提交于 2019-12-03 23:19:16
I have a C function that takes as paramenter an 8 bit integer int8_t foo( int8_t x ); I would like to call this function from my python code using a swig interface but int8_t type do not exists in python. In order to have this kind of types exists a python module called numpy. Even using this yet I do not manage to make the 2 comunicating. Do you know if there is any way of defining such a type in the SWIG interfacve in order to be able to use it from python?? int8_t is just an example... i have to do the same for signed/unsigned from 8 up to 64 bits Thanks in advance, S. Flexo In your SWIG

Wrapping std::vector of boost::shared_ptr in SWIG for Python

浪子不回头ぞ 提交于 2019-12-03 20:13:23
EDIT: Solved, my mistake; explained in my answer. I have this: std::vector < boost::shared_ptr < Entity > > entities; and I try to expose it through SWIG like this: %include "boost_shared_ptr.i" %include "std_vector.i" %shared_ptr(Entity) %include <Entity.h> namespace std { %template(EntityVector) vector<boost::shared_ptr<Entity> >; }; %include <TheFileWithEntities.h> However, in Python entities ends up being a tuple: import MyModule print type(MyModule.cvar.entities) # Output: (type 'tuple') I've Googled for this, but could not find any concrete examples on how to wrap this. One page gave a

Swig: How to wrap double& (double passed by reference)?

偶尔善良 提交于 2019-12-03 16:37:43
I am using SWIG to access C++ code from Python. How do I elegantly wrap a function that returns values in variables passed by reference like void set(double&a) { a = 42.; } I could not find out how to do this. In the best case I'd be able to use the function in Python with Python floats: >>> b = 2. >>> set(b) >>> print b 42.0 At the moment it gives me a TypeError: in method 'TestDouble_set', argument 2 of type 'double &' . sambha Do it this way: Your swig interface file: %include <typemaps.i> %apply double& INOUT { double& a }; void set(double& a); Usage in python script: a = 0.0 a = set(a)

Mixing C++ code from different compilers

限于喜欢 提交于 2019-12-03 15:57:39
问题 Suppose I have two projects that I would like to link together: A C++ library compiled with Visual C++ to a DLL file. A C++ executable compiled with C++ Builder that uses the classes in the library. I realize that there is no standard C++ ABI and that any attempts to directly link these two C++ projects together will fail. What is a good, automated way of creating a compatibility layer that allows me to accomplish this? For example, conceivably the C++ library could expose itself via a C