Skip to content

Commit 45ec18e

Browse files
committed
ENH: optimize complex vector norm
Also used ravel(order='K') to prevent copies.
1 parent de9b44f commit 45ec18e

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

numpy/linalg/linalg.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -2048,8 +2048,12 @@ def norm(x, ord=None, axis=None):
20482048

20492049
# Check the default case first and handle it immediately.
20502050
if ord is None and axis is None:
2051-
xr = x.ravel()
2052-
return sqrt(dot(xr, xr.conj()).real)
2051+
x = x.ravel(order='K')
2052+
if isComplexType(x.dtype.type):
2053+
sqnorm = dot(x.real, x.real) + dot(x.imag, x.imag)
2054+
else:
2055+
sqnorm = dot(x, x)
2056+
return sqrt(sqnorm)
20532057

20542058
# Normalize the `axis` argument to a tuple.
20552059
nd = x.ndim

0 commit comments

Comments
 (0)