Hmmm. This seems like a regression. The scalar casting API was fairly intentional.
What is the reason for the change? -- Travis Oliphant (on a mobile) 512-826-7480 On Feb 13, 2012, at 6:25 PM, Matthew Brett <[email protected]> wrote: > Hi, > > I recently noticed a change in the upcasting rules in numpy 1.6.0 / > 1.6.1 and I just wanted to check it was intentional. > > For all versions of numpy I've tested, we have: > >>>> import numpy as np >>>> Adata = np.array([127], dtype=np.int8) >>>> Bdata = np.int16(127) >>>> (Adata + Bdata).dtype > dtype('int8') > > That is - adding an integer scalar of a larger dtype does not result > in upcasting of the output dtype, if the data in the scalar type fits > in the smaller. > > For numpy < 1.6.0 we have this: > >>>> Bdata = np.int16(128) >>>> (Adata + Bdata).dtype > dtype('int8') > > That is - even if the data in the scalar does not fit in the dtype of > the array to which it is being added, there is no upcasting. > > For numpy >= 1.6.0 we have this: > >>>> Bdata = np.int16(128) >>>> (Adata + Bdata).dtype > dtype('int16') > > There is upcasting... > > I can see why the numpy 1.6.0 way might be preferable but it is an API > change I suppose. > > Best, > > Matthew > _______________________________________________ > NumPy-Discussion mailing list > [email protected] > http://mail.scipy.org/mailman/listinfo/numpy-discussion _______________________________________________ NumPy-Discussion mailing list [email protected] http://mail.scipy.org/mailman/listinfo/numpy-discussion
