[Numpy-discussion] Do we want scalar casting to behave as it does at the moment?
Mon Jan 7 14:55:25 CST 2013
On Mon, Jan 7, 2013 at 8:50 PM, Andrew Collette
> Hi Matthew,
>> Just to be clear, you mean you might have something like this?
>> def my_func('array_name', some_offset):
>> arr = load_somehow('array_name') # dtype hitherto unknown
>> return arr + some_offset
>> ? And the problem is that it fails late? Is it really better that
>> something bad happens for the addition than that it raises an error?
>> You'll also often get an error when trying to add structured dtypes,
>> but maybe you cant return these from a 'load'?
> In this specific case I would like to just use "+" and say "We add
> your offset using the NumPy rules," which is a problem if there are no
> NumPy rules for addition in the specific case where some_offset
> happens to be a scalar and not an array, and also slightly larger than
> arr.dtype can hold. I personally prefer upcasting to some reasonable
> type big enough to hold some_offset, as I described earlier, although
> that's not crucial.
> But I think we're getting a little caught up in the details of this
> example. My basic point is: yes, people should be careful to check
> dtypes, etc. where it's important to their application; but people who
> want to rely on some reasonable NumPy-supplied default behavior should
> be excused from doing so.
For myself, I find detailed examples helpful, because I find it
difficult to think about more general rules without applying them to
In this case I think you'd probably agree it would be reasonable to
raise an error - all other things being equal?
Can you think of another practical case where it would be reasonably
clear that it was the wrong thing to do?
More information about the NumPy-Discussion