[Numpy-discussion] linalg.norm probems

Charles R Harris charlesr.harris at gmail.com
Tue Mar 3 19:31:28 EST 2015


On Tue, Mar 3, 2015 at 5:21 PM, Jaime Fernández del Río <
jaime.frio at gmail.com> wrote:

> On Tue, Mar 3, 2015 at 4:11 PM, Charles R Harris <
> charlesr.harris at gmail.com> wrote:
>
>> Hi All,
>>
>> This is with reference to issue  #5626
>> <https://github.com/numpy/numpy/issues/5626>. Currently linalg.norm
>> converts the input like so `x = asarray(x)`. This can produce integer
>> arrays, which in turn may create problems of overflow, or the failure of
>> the abs functions for minimum values of signed integer types. I propose to
>> convert the input to a minimum precision of float32. However, this will be
>> a change in behavior. I'd guess that that might not be much of a problem,
>> as otherwise it is likely that this problem would have been reported
>> earlier.
>>
>> Thoughts?
>>
>
> Not sure if it makes sense here, but elsewhere (I think it was polyval) we
> let object arrays through unchanged.
>

That would still work. I'm thinking something like

x = asarray(x)
dt = result_type(x, np.float32)
if x.dtype.type is not dt.type:
    x = x.astype(dt)

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20150303/78744372/attachment.html>


More information about the NumPy-Discussion mailing list