Hi Damian
2008/7/29 Damian Eads <[EMAIL PROTECTED]>:
> 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 [18]: np.dtype('i') == np.dtype('l')
Out[18]: True
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
X.view(np.dtype('l'))
But, of course, that would break on a platform where the widths of int
and clong differ.
Cheers
Stéfan
_______________________________________________
Numpy-discussion mailing list
[email protected]
http://projects.scipy.org/mailman/listinfo/numpy-discussion