When linalg.cond is given a complex input, the output dtype is either the downgraded value type or the complex type, depending on which order value p is given. In contrast, linalg.norm always returns the downgraded value type, for all possible order values.
To improve linalg.cond's consistency with itself and with linalg.norm, it would probably be best if linalg.cond always returns the downgraded value type.
When cond returns a complex value, its imaginary part is always 0 (as far as I understand), so downgrading the type shouldn't affect value correctness.
Reproducing code example:
Behavior of cond:
>>> import numpy as np
>>> a = np.random.randn(10, 10) + 1j * np.random.randn(10, 10)
>>> np.linalg.cond(a, p=None)
72.2881023589724
>>> np.linalg.cond(a, p=2)
72.2881023589724
>>> np.linalg.cond(a, p=-2)
0.013833535082082288
>>> np.linalg.cond(a, p=1)
(253.11513101087314+0j)
>>> np.linalg.cond(a, p=-1)
(15.869620616376949+0j)
>>> np.linalg.cond(a, p=float('inf'))
(200.2689864179095+0j)
>>> np.linalg.cond(a, p=-float('inf'))
(24.578874030599213+0j)
>>> np.linalg.cond(a, p='fro')
(126.26418916571008+0j)
>>> np.linalg.cond(a, p='nuc')
(452.1421038722304+0j)
Behavior of norm:
>>> import numpy as np
>>> a = np.random.randn(10, 10) + 1j * np.random.randn(10, 10)
>>> np.linalg.norm(a, ord=None)
14.445562956889793
>>> np.linalg.norm(a, ord=2)
8.343686487155832
>>> np.linalg.norm(a, ord=-2)
0.11542267973396612
>>> np.linalg.norm(a, ord=1)
16.439210053387864
>>> np.linalg.norm(a, ord=-1)
9.113381379488501
>>> np.linalg.norm(a, ord=float('inf'))
15.027415916886657
>>> np.linalg.norm(a, ord=-float('inf'))
8.36772188424056
>>> np.linalg.norm(a, ord='fro')
14.445562956889793
>>> np.linalg.norm(a, ord='nuc')
39.26235633671831
NumPy/Python version information:
>>> print(np.__version__, sys.version)
1.19.1 3.7.7 (default, Mar 26 2020, 15:48:22)
[GCC 7.3.0]
When
linalg.condis given a complex input, the output dtype is either the downgraded value type or the complex type, depending on which order valuepis given. In contrast,linalg.normalways returns the downgraded value type, for all possible order values.To improve
linalg.cond's consistency with itself and withlinalg.norm, it would probably be best iflinalg.condalways returns the downgraded value type.When
condreturns a complex value, its imaginary part is always 0 (as far as I understand), so downgrading the type shouldn't affect value correctness.Reproducing code example:
Behavior of
cond:Behavior of
norm:NumPy/Python version information: