[Numpy-discussion] dtype subarray comparison

Charles R Harris charlesr.harris@gmail....
Thu Oct 21 12:03:52 CDT 2010

On Wed, Oct 20, 2010 at 5:59 PM, Mark Wiebe <mwwiebe@gmail.com> wrote:

> It turns out that when comparing dtypes, the subarray is currently ignored.
>  This means you can get things like this:
> >>> import numpy as np
> >>> np.dtype(('f4',(6))) == np.dtype(('f4',(2,3)))
> True
> >>> np.dtype(([('a','i4')],2)) == np.dtype(([('b','u2'),('c','i2')],2))
> True
> which pretty clearly should be False in both cases.  I've implemented a
> patch to fix this, for which a pull request is here:
> http://github.com/numpy/numpy/pull/6
> The main points included in this patch are:
> * If there's a subarray shape, it has to match exactly.
> * Currently, sometimes the subarray shape was an integer, other times a
> tuple.  The output formatting code checks for this and prints a tuple in
> both cases.  I changed the code to turn the integer into a tuple on
> construction instead.  This didn't cause any tests to fail, so I think it's
> a safe change.
> * The current code converts (type, 1) and (type, tuple()) to just type, so
> this means (type, 1) != (type, (1,)) but (type, 2) == (type, (2,))  I put in
> some tests of these edge cases.
> http://github.com/numpy/numpy/blob/master/numpy/core/src/multiarray/descriptor.c#L234
I think the important thing to settle here is just how dtype comparisons are
supposed to work. The current implementation might well be intended and if
so we need to know why it is so. I'd like Travis to weigh in here.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20101021/efb12cb2/attachment.html 

More information about the NumPy-Discussion mailing list