numpy/numpy — pull request #4144 by larsmans (2013-12-26 13:16:49+00:00)
Title: BUG: linalg: norm fails on longdouble, signed int

This fixes the following bug with longdouble:

```
>>> x = np.arange(10, dtype=np.longdouble)
>>> np.linalg.norm(x, ord=3)
Traceback (most recent call last):
File "", line 1, in
np.linalg.norm(x, ord=3)
File "/tmp/v/lib/python2.7/site-packages/numpy/linalg/linalg.py", line 2090, in norm
return add.reduce(absx**ord, axis=axis)**(1.0/ord)
UnboundLocalError: local variable 'absx' referenced before assignment
```

As well as the handling of minimal values for signed integers:

```
>>> x = np.array([-2**31], dtype=np.int32)
>>> np.linalg.norm(x, ord=3)
/tmp/v/lib/python2.7/site-packages/numpy/linalg/linalg.py:2090: RuntimeWarning: invalid value encountered in double_scalars
return add.reduce(absx**ord, axis=axis)**(1.0/ord)
nan
```

I also tried to use some inplace operations to cut down the memory use a bit.

There might still be a bug with complex numbers due to the use of `asfarray`, which discards the imaginary part. I'm not going to fix that in this PR.