[Numpy-discussion] Numarray - Numeric incompatibility

Tim Hochberg tim.hochberg at ieee.org
Thu Sep 18 10:54:18 EDT 2003


I'm just starting to move some of my code over to numarray and I was 
dismayed to find that basic operation between Numeric and numarray 
arrays fail.

 >>> import Numeric as np
 >>> import numarray as na
 >>> a = na.arange(5)
 >>> p = np.arange(5)
 >>> a + p
['vector', 'vector']
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "C:\Python23\Lib\site-packages\numarray\numarraycore.py", line 
648, in __add__
    def __add__(self, operand): return ufunc.add(self, operand)
  File "C:\Python23\lib\site-packages\numarray\ufunc.py", line 818, in 
_cache_miss2
    key = (_digest(n1), _digest(n2), _digest(out), safethread.get_ident())
KeyError: '_digest force cache miss'

I suspect (hope!) that this is just a bug and not something inherent in 
numarray. I dug around in unfunc.py a bit and it appears that the bug is 
shallow and can be fixed simply by replacing::

         if not (_sequence(n1) or _sequence(n2)):
            key = (_digest(n1), _digest(n2), _digest(out), 
safethread.get_ident())
            self._cache[ key ] = cached

with::

        try:
            key = (_digest(n1), _digest(n2), _digest(out), 
safethread.get_ident())
        except KeyError:
            pass
        else:
            self._cache[ key ] = cached

in _cache_miss2 and _cache_miss1. If this were done, _sequence could 
probably be deleted as well.

I'm not very familiar with the numarray code yet, so it's quite possible 
I'm missing something, but I'm willing to do more digging to fix this if 
this turns out to not be sufficient.

Regards,

-tim






More information about the NumPy-Discussion mailing list