[Numpy-discussion] find_common_type broken?

Citi, Luca lciti@essex.ac...
Sun Jul 12 12:24:55 CDT 2009


> That is what I thought at first, but then what is the difference between
> array_types and scalar_types? Function signature is:
> *find_common_type(array_types, scalar_types)*
As I understand it, the difference is that in the following case:
  np.choose(range(5), [np.arange(1,6), np.zeros(5, dtype=np.uint8), 1j*np.arange(5), 22, 1.5])
one should call:
  find_common_type([np.int64,np.uint8,np.complex128], [int,float])

I had a look at the code and it looks like
dtype1 < dtype2  if  dtype1 can safely be broadcasted to dtype2

As this is not the case, in either direction, for int32 and float32,
then neither dtype(int32) < dtype(float32) nor dtype(int32) > dtype(float32)
and this causes the problem you highlighted.

I think in this case find_common_type should return float64.
The same problem arises with:

>>> np.find_common_type([np.int8,np.uint8], [])
dtype('int8')
>>> np.find_common_type([np.uint8,np.int8], [])
dtype('uint8')

here too, I think find_common_type should return e third type
which is the "smallest" to which both can be safely
broadcasted: int16.

Best,
Luca


More information about the NumPy-Discussion mailing list