[Python-modules-team] Bug#511512: python-scipy: weave compilation fails

John Kozak jk at thameslighter.net
Sun Jan 11 19:04:04 UTC 2009


Package: python-scipy
Version: 0.6.0-12
Severity: normal

Attached code fails thus when run via nose:

nosetests -v /tmp/demo.py
Doctest: demo.RGBtoHSV ... In file included from /usr/lib/python2.5/site-packages/scipy/weave/blitz/blitz/applics.h:400,
                 from /usr/lib/python2.5/site-packages/scipy/weave/blitz/blitz/vecexpr.h:32,
                 from /usr/lib/python2.5/site-packages/scipy/weave/blitz/blitz/vecpick.cc:16,
                 from /usr/lib/python2.5/site-packages/scipy/weave/blitz/blitz/vecpick.h:293,
                 from /usr/lib/python2.5/site-packages/scipy/weave/blitz/blitz/vector.h:449,
                 from /usr/lib/python2.5/site-packages/scipy/weave/blitz/blitz/tinyvec.h:430,
                 from /usr/lib/python2.5/site-packages/scipy/weave/blitz/blitz/array-impl.h:44,
                 from /usr/lib/python2.5/site-packages/scipy/weave/blitz/blitz/array.h:32,
                 from /home/jk/.python25_compiled/sc_a48d3243be545a15f833dbd3625fee873.cpp:11:
/usr/lib/python2.5/site-packages/scipy/weave/blitz/blitz/mathfunc.h: In static member function ‘static long int blitz::_bz_abs<long int>::apply(long int)’:
/usr/lib/python2.5/site-packages/scipy/weave/blitz/blitz/mathfunc.h:45: error: ‘labs’ is not a member of ‘std’
In file included from /usr/lib/python2.5/site-packages/scipy/weave/blitz/blitz/array/funcs.h:29,
                 from /usr/lib/python2.5/site-packages/scipy/weave/blitz/blitz/array/newet.h:29,
                 from /usr/lib/python2.5/site-packages/scipy/weave/blitz/blitz/array/et.h:27,
                 from /usr/lib/python2.5/site-packages/scipy/weave/blitz/blitz/array-impl.h:2515,
                 from /usr/lib/python2.5/site-packages/scipy/weave/blitz/blitz/array.h:32,
                 from /home/jk/.python25_compiled/sc_a48d3243be545a15f833dbd3625fee873.cpp:11:
/usr/lib/python2.5/site-packages/scipy/weave/blitz/blitz/funcs.h: In static member function ‘static int blitz::Fn_abs<int>::apply(int)’:
/usr/lib/python2.5/site-packages/scipy/weave/blitz/blitz/funcs.h:509: error: call of overloaded ‘abs(int&)’ is ambiguous
/usr/include/c++/4.3/cmath:99: note: candidates are: double std::abs(double)
/usr/include/c++/4.3/cmath:103: note:                 float std::abs(float)
/usr/include/c++/4.3/cmath:107: note:                 long double std::abs(long double)
...

-- code

import sys

from numpy import *
from scipy import weave
from scipy.weave import converters


def _weaveC_hash_line():
    co = sys._getframe(1).f_code
    return '#line %d "%s"\n'%(co.co_firstlineno,co.co_filename)

def _dtypeToScale(dt):    
    if isinstance(dt,dtype):
        return _dtypeToScale(dt.type)
    else:
        return {ubyte  :255,
                ushort :65535,
                single :1.0,
                float32:1.0,
                float  :1.0}[dt]

def RGBtoHSV(array):
    """Convert a numpy array (which must be of shape HxWx3 containing
    RGB values to an array of the same shape containing HSV values.

    Note that H is in the range [0,max) (with -1 as an "exception").

    Examples:

    # black
    >>> ["%.3f"%f for f in RGBtoHSV(array([[[0,0,0]]],dtype=single)).flat]
    ['-1.000', '0.000', '0.000']

    # white
    >>> ["%.3f"%f for f in RGBtoHSV(array([[[1,1,1]]],dtype=single)).flat]
    ['-1.000', '0.000', '1.000']

    # red
    >>> ["%.3f"%f for f in RGBtoHSV(array([[[1,0,0]]],dtype=single)).flat]
    ['1.000', '1.000', '0.500']
    
    """
    nx,ny,nc = array.shape
    if nc!=3:
        raise ValueError("not an RGB array")
    out   = empty_like(array)
    scale = _dtypeToScale(array.dtype)
    code  = _weaveC_hash_line()+'''
#define MAX(a,b) ((a)<(b) ? (b) : (a))
#define MIN(a,b) ((a)>(b) ? (b) : (a))
    // this code assumes gcc (typeof)
    float delta,max,min;
    float hue,saturation,luminosity;

    for (int x=0;x<nx;x++)
       for (int y=0;y<ny;y++)
       {
          float r = array(x,y,0)/scale;
          float g = array(x,y,1)/scale;
          float b = array(x,y,2)/scale;
          max        = MAX(r,MAX(g,b));
          min        = MIN(r,MIN(g,b));
          hue        = -1.0;
          saturation = 0.0;
          luminosity = 0.50000001*(min+max);
          delta      = max-min;
          if (delta!=0.0)
          {
             saturation = delta/((luminosity <= 0.5) ? (min+max) : (2.0-max-min));
             if (r==max)
                hue = (g==min ? 5.0+(max-b)/delta : 1.0-(max-g)/delta);
             else if (g==max)
                hue = (b==min ? 1.0+(max-r)/delta : 3.0-(max-b)/delta);
             else
                hue = (r==min ? 3.0+(max-g)/delta : 5.0-(max-r)/delta);
             hue /= 6.0;
          }
          out(x,y,0) = (typeof(out(x,y,0))) (hue*scale);
          out(x,y,1) = (typeof(out(x,y,1))) (saturation*scale);
          out(x,y,2) = (typeof(out(x,y,2))) (luminosity*scale);
       }
#undef MAX
#undef MIN
    '''
    weave.inline(code,
                 ['array','out','nx','ny','scale'],
                 verbose        =0,
                 type_converters=weave.converters.blitz,
                 compiler       ='gcc')
    return out


-- end code

-- System Information:
Debian Release: 5.0
  APT prefers unstable
  APT policy: (500, 'unstable'), (1, 'experimental')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.26-1-openvz-amd64 (SMP w/4 CPU cores)
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages python-scipy depends on:
ii  libatlas3gf-base [liblapack. 3.6.0-22    Automatically Tuned Linear Algebra
ii  libblas3gf [libblas.so.3gf]  1.2-2       Basic Linear Algebra Subroutines 3
ii  libc6                        2.7-18      GNU C Library: Shared libraries
ii  libfftw3-3                   3.1.2-3.1   library for computing Fast Fourier
ii  libgcc1                      1:4.3.2-1.1 GCC support library
ii  libgfortran3                 4.3.2-1.1   Runtime library for GNU Fortran ap
ii  liblapack3gf [liblapack.so.3 3.1.1-6     library of linear algebra routines
ii  libstdc++6                   4.3.2-1.1   The GNU Standard C++ Library v3
ii  libsuitesparse-3.1.0         1:3.1.0-3.1 collection of libraries for comput
ii  python                       2.5.2-3     An interactive high-level object-o
ii  python-central               0.6.8       register and build utility for Pyt
ii  python-imaging               1.1.6-3     Python Imaging Library
ii  python-numpy                 1:1.1.1-2   Numerical Python adds a fast array

Versions of packages python-scipy recommends:
ii  g++ [c++-compiler]            4:4.3.2-2  The GNU C++ compiler
ii  g++-3.3 [c++-compiler]        1:3.3.6-15 The GNU C++ compiler
ii  g++-4.1 [c++-compiler]        4.1.2-24   The GNU C++ compiler
ii  g++-4.2 [c++-compiler]        4.2.4-5    The GNU C++ compiler
ii  g++-4.3 [c++-compiler]        4.3.2-1.1  The GNU C++ compiler

Versions of packages python-scipy suggests:
pn  python-profiler               <none>     (no description available)

-- debconf-show failed





More information about the Python-modules-team mailing list