On Nov 19, 2007 9:06 AM, Michael ODonnell <odonnems@yahoo.com> wrote:
I am trying to compile some inline c++ code inside python using weave. I always get a similar problem where the compiled file cannot be found (see below). I am not sure if the problem is with the compiler or something else. I am a new user of scipy and a novice with python so I would appreciate any direction someone can give me because I have not been able to figure out a work around.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ When I try to test the following script or any other script I get the following message: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ def prod(m, v): #C++ version nrows, ncolumns = m.shape
res = numpy.zeros((nrows, ncolumns), float) code = r""" for (int i=0; i<nrows; i++) { for (int j=0; j<ncolumns; j++) { res(i) += m(i,j)*v(j); } } """
#err = weave.inline(code,['nrows', 'ncolumns', 'res', 'm', 'v'], type_converters=converters.blitz, compiler='mingw32', verbose=2) err = weave.inline(code,['nrows', 'ncolumns', 'res', 'm', 'v'], verbose=2)
There may be windows-specific problems (I'm on linux), but your code as above simply can't work because you're assuming blitz behavior (parens on m(i,j) calls) with the blitz call commented out. On Linux, this version: ########################################################## import numpy from scipy import weave from scipy.weave import converters def prod(m, v): #C++ version nrows, ncolumns = m.shape assert v.ndim==1 and ncolumns==v.shape[0],"Shape mismatch in prod" res = numpy.zeros(nrows, float) code = r""" for (int i=0; i<nrows; i++) { for (int j=0; j<ncolumns; j++) { res(i) += m(i,j)*v(j); } } """ err = weave.inline(code,['nrows', 'ncolumns', 'res', 'm', 'v'], verbose=2, type_converters=converters.blitz) return res m=numpy.random.rand(3,4) v = numpy.random.rand(4) mv = prod(m,v) mvd = numpy.dot(m,v) print 'Err:',numpy.linalg.norm(mv-mvd) ####### EOF ############################################### produces errors within floating-point tolerances, as expected: In [41]: run weaveex.py Err: 1.11022302463e-16 In [42]: run weaveex.py Err: 5.55111512313e-17 In [43]: run weaveex.py Err: 2.77555756156e-17 As I said in my other message, it's still worth filing a ticket on this with the exact input/output pair that produced the error. If it's a core weave bug we'll find it in any platform, and even if it's platform specific it will ensure that it doesn't get lost in the mists of mailing lists. Cheers, f