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
Cheers,
Mark
_______________________________________________
NumPy-Discussion mailing list
[email protected]
http://mail.scipy.org/mailman/listinfo/numpy-discussion