Tengo una función en c ++ que devuelve una lista de complejos:
#include std::list< std::complex > func(...);
¿Qué debo hacer en el archivo ‘* .i’?
Gracias a todos.
=================
Los siguientes son detalles:
la función que me gustaría usar en python en xh:
std::list<std::complex > roots1(const double& d, const double& e);
He intentado algunas maneras:
(1) xi:
%include %include
de lo que trato en IPython:
tmp = x.roots1(1.0, 2.0) len(tmp)
y me dieron
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) in () ----> 1 len(tmp) TypeError: object of type 'SwigPyObject' has no len()
y:
dir(tmp)
devoluciones:
[ ... 'acquire', 'append', 'disown', 'next', 'own']
(2) xi:
%include %include namespace std { %template(ComplexDouble) complex; }
que, tengo error de comstackción:
error: command 'swig' failed with exit status 1 make: *** [py] Error 1
(3) en xi:
%include %include namespace std { %template(ComplexDouble) list<complex >; }
o:
%include %include namespace std { %template(ComplexDouble) list; }
y me dieron
x_wrap.cpp:5673:32: error: 'complex' was not declared in this scope template struct traits { ^
================================================
(Mr./Ms./Mrs) m7thon me ayuda a encontrar el problema. En mi contexto python:
Ubuntu: 45~14.04.1 Python: 3.4.3 SWIG: SWIG Version 2.0.11 Compiled with g++ [x86_64-unknown-linux-gnu] Configured options: +pcre
Si define el xi como:
%include %include namespace std { %template(ComplexList) list<complex >; }
Habrá error de comstackción. Pero funciona si xi:
%include %include %template(ComplexList) std::list< std::complex >;
Gracias m7thon.
Esto funciona:
%include %include %template(ComplexList) std::list >; ... (your includes / function declarations)
Creo que tu versión (3) debería funcionar también. Es extraño que no lo haga. Tal vez un error SWIG.
Para ser más conciso puedes usar el espacio de nombres completo:
%include %include using namespace std; %template(ComplexList) list >;
Pero las versiones inicialmente sugeridas de incluir la %template
SWIG %template
en el std
nombres estándar no es una buena idea.