[SciPy-user] [solved] errors using weave with with blitz on Ubuntu/Breezy

Evan Monroig evan at monroig.net
Thu Jan 5 04:11:06 CST 2006

On 12/31/05, Fernando Perez <Fernando.Perez at colorado.edu> wrote:
> Evan Monroig wrote:
> > Hi,
> >
> > I am trying to use weave to speed up my code with inline c++ code, but
> > I can't find any working sample.
> >
> > I found a very simple one [1] to return the trace of a matrix, but
> > I can't find how to incorporate the c++ code. I attached the compile
> > errors. I also tried to remove the "type_converters" parameter in inline
> > and change the array parentheses () into brackets [], then it compiles
> > but gives wrong results...
> >
> > I am running on Ubuntu with
> > python2.4-scipy-core=0.3.2-2ubuntu1
> > python2.4-scipy=0.3.2-3ubuntu2
> > python2.4-numeric=23.8-4
> > python2.4-numeric-ext=23.8-4
> > blitz++=1:0.8-4 (just in case)
> >
> > gcc version is 4.0.2
>    ^^^^^^^^^^^^^^^^^^^^
> This is your problem: only blitz 0.9 compiles with gcc4.  You need to download
>   the newer blitz, and put it by hand in the
> /usr/lib/python2.4/site-packages/weave/blitz-20001213/blitz
> directory.

Thanks again for the help. Now it works. Just in case someone has the
same problem, here is how to solve it

Warning: don't forget I have Ubuntu/Breezy and I use the scipy
packages that come in the universe repository

First download blitz from sourceforge [1] and put it for example in /usr/src/

Then replace the old blitz directory by the new as Fernando Perez
explained. I did with the following commands (don't forget to save the
old version just in case something goes wrong !)

cd /usr/lib/python2.4/site-packages/weave/blitz-20001213
sudo tar cvjf blitz_old.tar.bz2 blitz/
sudo rm -rf /usr/lib/python2.4/site-packages/weave/blitz-20001213/blitz
cd /usr/src
tar xvzf blitz-0.9.tar.gz
cd blitz-0.9
sudo cp -a blitz/ /usr/lib/python2.4/site-packages/weave/blitz-20001213/

Now you can test weave with a sample file [2].


[1] http://sourceforge.net/project/showfiles.php?group_id=63961
[2] the sample file: (the code is not mine, and you can find the
original file here
# -*- coding: utf-8 -*-
import scipy
from weave import converters, inline

def trace(mat):
   """Return the trace of a matrix.
   nrow,ncol = mat.shape
   code = \
double tr=0.0;

for(int i=0;i<nrow;++i)
   tr += mat(i,i);
return_val = tr;
   return inline(code,['mat','nrow','ncol'],
                 type_converters = converters.blitz)

M = scipy.rand(3,3)
t_weave = trace(M)
t_scipy = scipy.trace(M)
if (abs(t_weave - t_scipy) < 1e-8):
    print 'test succeeded'
    print 'test failed'

More information about the SciPy-user mailing list