[Numpy-discussion] asarray issue with type codes
Stéfan van der Walt
Tue Jul 29 01:54:52 CDT 2008
2008/7/29 Damian Eads <firstname.lastname@example.org>:
> I ran into a little problem in some type checking code for a C extension
> I'm writing. I construct X as a C-long array and then I cast it to a C-int
> array Y, however the type code does not change. However, when I try
> constructing the array from scratch as a C-int, I get the right type code
> (ie 5).
> I assumed that when X gets casted to a C-int, no copying should occur but
> a new array view should be constructed with the C-int type code. What's
> wrong with this logic?
I would guess that, somewhere along the line, the two dtypes are
compared to see whether anything needs to be done:
In : np.dtype('i') == np.dtype('l')
Since int and c_long is the same on 32-bit platforms, it doesn't do
anything. I agree; that looks like a bug. Unless someone else
justifies this behaviour, please file a ticket so that we can fix it
in time for 1.2. For now, you could achieve what you want by doing
But, of course, that would break on a platform where the widths of int
and clong differ.
More information about the Numpy-discussion