[Numpy-discussion] dtype subarray comparison
Charles R Harris
Thu Oct 21 12:03:52 CDT 2010
On Wed, Oct 20, 2010 at 5:59 PM, Mark Wiebe <email@example.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)))
> >>> np.dtype(([('a','i4')],2)) == np.dtype(([('b','u2'),('c','i2')],2))
> which pretty clearly should be False in both cases. I've implemented a
> patch to fix this, for which a pull request is here:
> 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.
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...
More information about the NumPy-Discussion