[SciPy-user] weave and compiler install help
Michael ODonnell
odonnems at yahoo.com
Mon Dec 3 14:06:34 EST 2007
Thank you for your response Fernando. I am a new python user so this is likely out of my league. I am not sure why the code below is commented out, but I am actually using the blitz. Here is a very simple test that I cannot get to work:
a = 1
weave.inline('printf("%d\\n",a);',['a'], verbose=2, type_converters=converters.blitz)
I just added a ticket, as you suggested, under scipy.weave component which will hopefully shed some light. I have tried numerous compilers and versions of scipy/python/enthought. For some reason they all seem to give a similar error. Ticket #550
I have attached a script denoting all the tests that I have done to get weave.inline to work (this is a .zip file of a py script). The problem for me seems to be that the compiler is creating the source file but does not create the object file. Therefore, the script written by exec_command.py crashes when trying to read the output from this script. I am not sure if the problem lies with the content of the script file or with the compiler. I ran the weave.test() and receive no errors, but I am not sure if it is testing what it really needs to be testing.
Anyhow, thank you for the time and effort and maybe I can figure this out with some additional effort.
Michael O'Donnell
----- Original Message ----
From: Fernando Perez <fperez.net at gmail.com>
To: SciPy Users List <scipy-user at scipy.org>
Sent: Sunday, December 2, 2007 11:09:32 PM
Subject: Re: [SciPy-user] weave and compiler install help
On Nov 19, 2007 9:06 AM, Michael ODonnell <odonnems at 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
_______________________________________________
SciPy-user mailing list
SciPy-user at scipy.org
http://projects.scipy.org/mailman/listinfo/scipy-user
____________________________________________________________________________________
Get easy, one-click access to your favorites.
Make Yahoo! your homepage.
http://www.yahoo.com/r/hs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20071203/b7e3dccb/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_weave.zip
Type: application/zip
Size: 3694 bytes
Desc: not available
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20071203/b7e3dccb/attachment.zip>
More information about the SciPy-User
mailing list