FreeBSD Bugzilla – Attachment 229285 Details for
Bug 259637
math/py-numpy: Update to 1.22.4
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
The test log of numpy-1.21.4 with pytest-6.2.5
numpy-tests.1.21.4.log (text/plain), 98.52 KB, created by
Wen Heping
on 2021-11-05 08:35:38 UTC
(
hide
)
Description:
The test log of numpy-1.21.4 with pytest-6.2.5
Filename:
MIME Type:
Creator:
Wen Heping
Created:
2021-11-05 08:35:38 UTC
Size:
98.52 KB
patch
obsolete
>NumPy version 1.21.4 >NumPy relaxed strides checking option: True >NumPy CPU features: SSE SSE2 SSE3 SSSE3* SSE41* POPCNT* SSE42* AVX* F16C? FMA3? AVX2* AVX512F? AVX512CD? AVX512_KNL? AVX512_SKX? AVX512_CLX? AVX512_CNL? AVX512_ICL? >........................................................................ [ 0%] >..............................................................x......... [ 0%] >........................................................................ [ 1%] >........................................................x............... [ 1%] >........................................................................ [ 2%] >........................................................................ [ 2%] >........................................................................ [ 3%] >.........................................................Fsss........... [ 3%] >........................................................................ [ 4%] >........................................................................ [ 4%] >........................................................................ [ 5%] >x..........x..x..........x.............................................. [ 5%] >........................................................................ [ 5%] >........................................................................ [ 6%] >...................................................................ssss. [ 6%] >........................................................................ [ 7%] >........................................................................ [ 7%] >........................................................................ [ 8%] >........................................................................ [ 8%] >........................................................................ [ 9%] >........................................................................ [ 9%] >........................................................................ [ 10%] >........................................................................ [ 10%] >........................................................................ [ 11%] >........................................................................ [ 11%] >........................................................................ [ 11%] >........................................................................ [ 12%] >........................................................................ [ 12%] >........................................................................ [ 13%] >........................................................................ [ 13%] >....................................sss................................. [ 14%] >........................................................................ [ 14%] >.................................................xx..................... [ 15%] >........................................................................ [ 15%] >....................................s................................... [ 16%] >........................................................................ [ 16%] >........................................................................ [ 17%] >........................................................................ [ 17%] >........................................................................ [ 17%] >........................................................................ [ 18%] >........................................................................ [ 18%] >................................F.F.....F.F.....................F.F..... [ 19%] >F.F.....................F.F.....F.F..................................... [ 19%] >........................................................................ [ 20%] >........................................................................ [ 20%] >........................................................................ [ 21%] >........................................................................ [ 21%] >........................................................................ [ 22%] >........................................................................ [ 22%] >........................................................................ [ 23%] >........................................................................ [ 23%] >........................................................................ [ 23%] >........................................................................ [ 24%] >........................................................................ [ 24%] >...........x...x........................................................ [ 25%] >........................................................................ [ 25%] >..........................................................xx............ [ 26%] >........................................................................ [ 26%] >........................................................................ [ 27%] >........................................................................ [ 27%] >........................................................................ [ 28%] >........................................................................ [ 28%] >........................................................................ [ 29%] >........................................................................ [ 29%] >........................................................................ [ 29%] >........................................................................ [ 30%] >........................................................................ [ 30%] >........................................................................ [ 31%] >........................................................................ [ 31%] >........................................................................ [ 32%] >........................................................................ [ 32%] >..........................................F..................s.......... [ 33%] >........................................................................ [ 33%] >...........................s............................................ [ 34%] >........................................................................ [ 34%] >.................................................................sssssss [ 35%] >ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss [ 35%] >ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss [ 35%] >ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss [ 36%] >ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss [ 36%] >ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss [ 37%] >ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss [ 37%] >ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss [ 38%] >ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss [ 38%] >ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss [ 39%] >ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss [ 39%] >ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss [ 40%] >sssssssssss............................................................. [ 40%] >........................................................................ [ 40%] >........................................................................ [ 41%] >........................................................................ [ 41%] >........................................................................ [ 42%] >........................................................................ [ 42%] >........................................................................ [ 43%] >........................................................................ [ 43%] >..................................................................F..... [ 44%] >........................................................................ [ 44%] >........................................................................ [ 45%] >........................................................................ [ 45%] >........................................................................ [ 46%] >........................................................................ [ 46%] >........................................................................ [ 46%] >.......................F................................................ [ 47%] >ssssssssssssF........................................................... [ 47%] >........................................................................ [ 48%] >....................s.ss.s..s.......s...FF....FF........................ [ 48%] >........................................................................ [ 49%] >........................................................................ [ 49%] >........................................................................ [ 50%] >........................................................................ [ 50%] >........................................................................ [ 51%] >........................................................................ [ 51%] >........................................................................ [ 52%] >........................................................................ [ 52%] >..........................................s...........sssssssssssssss... [ 52%] >............sssssssssssssss............................................. [ 53%] >........................................................................ [ 53%] >........................................................................ [ 54%] >........................................................................ [ 54%] >........................................................................ [ 55%] >........................................................................ [ 55%] >........................................................................ [ 56%] >........................................................................ [ 56%] >........................................................................ [ 57%] >........................................................................ [ 57%] >........................................................................ [ 58%] >........................................................................ [ 58%] >................x....................................................... [ 58%] >........................................................................ [ 59%] >........................................................................ [ 59%] >........................................................................ [ 60%] >........................................................................ [ 60%] >........................................................................ [ 61%] >........................................................................ [ 61%] >........................................................................ [ 62%] >........................................................................ [ 62%] >........................................................................ [ 63%] >.........................x.............................................. [ 63%] >........................................................................ [ 64%] >........................................................................ [ 64%] >........................................................................ [ 64%] >........................................................................ [ 65%] >........................................................................ [ 65%] >........................................................................ [ 66%] >........................................................................ [ 66%] >........................................................................ [ 67%] >........................................................................ [ 67%] >........................................................................ [ 68%] >........................................................................ [ 68%] >........................................................................ [ 69%] >........................................................x............... [ 69%] >........................................................................ [ 70%] >........................................................................ [ 70%] >........................................................................ [ 70%] >....s...............................................x................... [ 71%] >........................................................................ [ 71%] >........................................................................ [ 72%] >.......................F.F.......F.........F.F.......................... [ 72%] >............x........................................................... [ 73%] >........................................................................ [ 73%] >........................................................................ [ 74%] >........................................................................ [ 74%] >........................................................................ [ 75%] >........................................................................ [ 75%] >........................................................................ [ 75%] >........................................................................ [ 76%] >........................................................................ [ 76%] >........................................................................ [ 77%] >........................................................................ [ 77%] >........................................................................ [ 78%] >........................................................................ [ 78%] >........................................................................ [ 79%] >........................................................................ [ 79%] >........................................................................ [ 80%] >........................................................................ [ 80%] >........................................................................ [ 81%] >........................................................................ [ 81%] >........................................................................ [ 81%] >...............xx....................................................... [ 82%] >........................................................................ [ 82%] >........................................................................ [ 83%] >........................................................................ [ 83%] >........................................................................ [ 84%] >........................................................................ [ 84%] >........................................................................ [ 85%] >........................................................................ [ 85%] >........................................................................ [ 86%] >........................................................................ [ 86%] >........................................................................ [ 87%] >........................................................................ [ 87%] >........................................................................ [ 87%] >........................................................................ [ 88%] >........................................................................ [ 88%] >........................................................................ [ 89%] >........................................................................ [ 89%] >....................s................................................... [ 90%] >........................................................................ [ 90%] >........................................................................ [ 91%] >........................................................................ [ 91%] >........................................................................ [ 92%] >........................................................................ [ 92%] >........................................................................ [ 93%] >........................................................................ [ 93%] >........................................................................ [ 93%] >............s........................................................... [ 94%] >........................................................................ [ 94%] >........................................................................ [ 95%] >........................................................................ [ 95%] >...............ss....................................................... [ 96%] >........................................................................ [ 96%] >........................................................................ [ 97%] >........................................................................ [ 97%] >.................................................................sss.... [ 98%] >........................................................................ [ 98%] >.............XXX........................................................ [ 99%] >........................................................................ [ 99%] >........................................................................ [ 99%] >......... [100%] >=================================== FAILURES =================================== >_______________________________ test_dispatcher ________________________________ > > def test_dispatcher(): > """ > Testing the utilites of the CPU dispatcher > """ > targets = ( > "SSE2", "SSE41", "AVX2", > "VSX", "VSX2", "VSX3", > "NEON", "ASIMD", "ASIMDHP" > ) > highest_sfx = "" # no suffix for the baseline > all_sfx = [] > for feature in reversed(targets): > # skip baseline features, by the default `CCompilerOpt` do not generate separated objects > # for the baseline, just one object combined all of them via 'baseline' option > # within the configuration statments. > if feature in __cpu_baseline__: > continue > # check compiler and running machine support > if feature not in __cpu_dispatch__ or not __cpu_features__[feature]: > continue > > if not highest_sfx: > highest_sfx = "_" + feature > all_sfx.append("func" + "_" + feature) > > test = _umath_tests.test_dispatch() >> assert_equal(test["func"], "func" + highest_sfx) >E AssertionError: >E Items are not equal: >E ACTUAL: 'func_SSE41' >E DESIRED: 'func_AVX2' > >all_sfx = ['func_AVX2', 'func_SSE41'] >feature = 'SSE2' >highest_sfx = '_AVX2' >targets = ('SSE2', 'SSE41', 'AVX2', 'VSX', 'VSX2', 'VSX3', ...) >test = {'all': ['func_SSE41', 'func'], 'func': 'func_SSE41', 'func_xb': 'func_SSE41', 'var': 'var_SSE41', ...} > >/usr/local/lib/python3.8/site-packages/numpy/core/tests/test_cpu_dispatcher.py:31: AssertionError >__________ test_npymath_complex[complex64-inf-inf-npy_cabs-absolute] ___________ > >fun = <built-in function npy_cabs>, npfun = <ufunc 'absolute'>, x = inf, y = inf >test_dtype = <class 'numpy.complex64'> > > @pytest.mark.parametrize( > ["fun", "npfun"], > [ > (_multiarray_tests.npy_cabs, np.absolute), > (_multiarray_tests.npy_carg, np.angle) > ] > ) > @pytest.mark.parametrize("x", [1, np.inf, -np.inf, np.nan]) > @pytest.mark.parametrize("y", [1, np.inf, -np.inf, np.nan]) > @pytest.mark.parametrize("test_dtype", np.complexfloating.__subclasses__()) > def test_npymath_complex(fun, npfun, x, y, test_dtype): > # Smoketest npymath functions > z = test_dtype(complex(x, y)) > got = fun(z) >> expected = npfun(z) >E RuntimeWarning: invalid value encountered in absolute > >fun = <built-in function npy_cabs> >got = array(inf) >npfun = <ufunc 'absolute'> >test_dtype = <class 'numpy.complex64'> >x = inf >y = inf >z = (inf+infj) > >/usr/local/lib/python3.8/site-packages/numpy/core/tests/test_multiarray.py:8805: RuntimeWarning >__________ test_npymath_complex[complex64-inf--inf-npy_cabs-absolute] __________ > >fun = <built-in function npy_cabs>, npfun = <ufunc 'absolute'>, x = -inf >y = inf, test_dtype = <class 'numpy.complex64'> > > @pytest.mark.parametrize( > ["fun", "npfun"], > [ > (_multiarray_tests.npy_cabs, np.absolute), > (_multiarray_tests.npy_carg, np.angle) > ] > ) > @pytest.mark.parametrize("x", [1, np.inf, -np.inf, np.nan]) > @pytest.mark.parametrize("y", [1, np.inf, -np.inf, np.nan]) > @pytest.mark.parametrize("test_dtype", np.complexfloating.__subclasses__()) > def test_npymath_complex(fun, npfun, x, y, test_dtype): > # Smoketest npymath functions > z = test_dtype(complex(x, y)) > got = fun(z) >> expected = npfun(z) >E RuntimeWarning: invalid value encountered in absolute > >fun = <built-in function npy_cabs> >got = array(inf) >npfun = <ufunc 'absolute'> >test_dtype = <class 'numpy.complex64'> >x = -inf >y = inf >z = (-inf+infj) > >/usr/local/lib/python3.8/site-packages/numpy/core/tests/test_multiarray.py:8805: RuntimeWarning >__________ test_npymath_complex[complex64--inf-inf-npy_cabs-absolute] __________ > >fun = <built-in function npy_cabs>, npfun = <ufunc 'absolute'>, x = inf >y = -inf, test_dtype = <class 'numpy.complex64'> > > @pytest.mark.parametrize( > ["fun", "npfun"], > [ > (_multiarray_tests.npy_cabs, np.absolute), > (_multiarray_tests.npy_carg, np.angle) > ] > ) > @pytest.mark.parametrize("x", [1, np.inf, -np.inf, np.nan]) > @pytest.mark.parametrize("y", [1, np.inf, -np.inf, np.nan]) > @pytest.mark.parametrize("test_dtype", np.complexfloating.__subclasses__()) > def test_npymath_complex(fun, npfun, x, y, test_dtype): > # Smoketest npymath functions > z = test_dtype(complex(x, y)) > got = fun(z) >> expected = npfun(z) >E RuntimeWarning: invalid value encountered in absolute > >fun = <built-in function npy_cabs> >got = array(inf) >npfun = <ufunc 'absolute'> >test_dtype = <class 'numpy.complex64'> >x = inf >y = -inf >z = (inf-infj) > >/usr/local/lib/python3.8/site-packages/numpy/core/tests/test_multiarray.py:8805: RuntimeWarning >_________ test_npymath_complex[complex64--inf--inf-npy_cabs-absolute] __________ > >fun = <built-in function npy_cabs>, npfun = <ufunc 'absolute'>, x = -inf >y = -inf, test_dtype = <class 'numpy.complex64'> > > @pytest.mark.parametrize( > ["fun", "npfun"], > [ > (_multiarray_tests.npy_cabs, np.absolute), > (_multiarray_tests.npy_carg, np.angle) > ] > ) > @pytest.mark.parametrize("x", [1, np.inf, -np.inf, np.nan]) > @pytest.mark.parametrize("y", [1, np.inf, -np.inf, np.nan]) > @pytest.mark.parametrize("test_dtype", np.complexfloating.__subclasses__()) > def test_npymath_complex(fun, npfun, x, y, test_dtype): > # Smoketest npymath functions > z = test_dtype(complex(x, y)) > got = fun(z) >> expected = npfun(z) >E RuntimeWarning: invalid value encountered in absolute > >fun = <built-in function npy_cabs> >got = array(inf) >npfun = <ufunc 'absolute'> >test_dtype = <class 'numpy.complex64'> >x = -inf >y = -inf >z = (-inf-infj) > >/usr/local/lib/python3.8/site-packages/numpy/core/tests/test_multiarray.py:8805: RuntimeWarning >__________ test_npymath_complex[complex128-inf-inf-npy_cabs-absolute] __________ > >fun = <built-in function npy_cabs>, npfun = <ufunc 'absolute'>, x = inf, y = inf >test_dtype = <class 'numpy.complex128'> > > @pytest.mark.parametrize( > ["fun", "npfun"], > [ > (_multiarray_tests.npy_cabs, np.absolute), > (_multiarray_tests.npy_carg, np.angle) > ] > ) > @pytest.mark.parametrize("x", [1, np.inf, -np.inf, np.nan]) > @pytest.mark.parametrize("y", [1, np.inf, -np.inf, np.nan]) > @pytest.mark.parametrize("test_dtype", np.complexfloating.__subclasses__()) > def test_npymath_complex(fun, npfun, x, y, test_dtype): > # Smoketest npymath functions > z = test_dtype(complex(x, y)) > got = fun(z) >> expected = npfun(z) >E RuntimeWarning: invalid value encountered in absolute > >fun = <built-in function npy_cabs> >got = array(inf) >npfun = <ufunc 'absolute'> >test_dtype = <class 'numpy.complex128'> >x = inf >y = inf >z = (inf+infj) > >/usr/local/lib/python3.8/site-packages/numpy/core/tests/test_multiarray.py:8805: RuntimeWarning >_________ test_npymath_complex[complex128-inf--inf-npy_cabs-absolute] __________ > >fun = <built-in function npy_cabs>, npfun = <ufunc 'absolute'>, x = -inf >y = inf, test_dtype = <class 'numpy.complex128'> > > @pytest.mark.parametrize( > ["fun", "npfun"], > [ > (_multiarray_tests.npy_cabs, np.absolute), > (_multiarray_tests.npy_carg, np.angle) > ] > ) > @pytest.mark.parametrize("x", [1, np.inf, -np.inf, np.nan]) > @pytest.mark.parametrize("y", [1, np.inf, -np.inf, np.nan]) > @pytest.mark.parametrize("test_dtype", np.complexfloating.__subclasses__()) > def test_npymath_complex(fun, npfun, x, y, test_dtype): > # Smoketest npymath functions > z = test_dtype(complex(x, y)) > got = fun(z) >> expected = npfun(z) >E RuntimeWarning: invalid value encountered in absolute > >fun = <built-in function npy_cabs> >got = array(inf) >npfun = <ufunc 'absolute'> >test_dtype = <class 'numpy.complex128'> >x = -inf >y = inf >z = (-inf+infj) > >/usr/local/lib/python3.8/site-packages/numpy/core/tests/test_multiarray.py:8805: RuntimeWarning >_________ test_npymath_complex[complex128--inf-inf-npy_cabs-absolute] __________ > >fun = <built-in function npy_cabs>, npfun = <ufunc 'absolute'>, x = inf >y = -inf, test_dtype = <class 'numpy.complex128'> > > @pytest.mark.parametrize( > ["fun", "npfun"], > [ > (_multiarray_tests.npy_cabs, np.absolute), > (_multiarray_tests.npy_carg, np.angle) > ] > ) > @pytest.mark.parametrize("x", [1, np.inf, -np.inf, np.nan]) > @pytest.mark.parametrize("y", [1, np.inf, -np.inf, np.nan]) > @pytest.mark.parametrize("test_dtype", np.complexfloating.__subclasses__()) > def test_npymath_complex(fun, npfun, x, y, test_dtype): > # Smoketest npymath functions > z = test_dtype(complex(x, y)) > got = fun(z) >> expected = npfun(z) >E RuntimeWarning: invalid value encountered in absolute > >fun = <built-in function npy_cabs> >got = array(inf) >npfun = <ufunc 'absolute'> >test_dtype = <class 'numpy.complex128'> >x = inf >y = -inf >z = (inf-infj) > >/usr/local/lib/python3.8/site-packages/numpy/core/tests/test_multiarray.py:8805: RuntimeWarning >_________ test_npymath_complex[complex128--inf--inf-npy_cabs-absolute] _________ > >fun = <built-in function npy_cabs>, npfun = <ufunc 'absolute'>, x = -inf >y = -inf, test_dtype = <class 'numpy.complex128'> > > @pytest.mark.parametrize( > ["fun", "npfun"], > [ > (_multiarray_tests.npy_cabs, np.absolute), > (_multiarray_tests.npy_carg, np.angle) > ] > ) > @pytest.mark.parametrize("x", [1, np.inf, -np.inf, np.nan]) > @pytest.mark.parametrize("y", [1, np.inf, -np.inf, np.nan]) > @pytest.mark.parametrize("test_dtype", np.complexfloating.__subclasses__()) > def test_npymath_complex(fun, npfun, x, y, test_dtype): > # Smoketest npymath functions > z = test_dtype(complex(x, y)) > got = fun(z) >> expected = npfun(z) >E RuntimeWarning: invalid value encountered in absolute > >fun = <built-in function npy_cabs> >got = array(inf) >npfun = <ufunc 'absolute'> >test_dtype = <class 'numpy.complex128'> >x = -inf >y = -inf >z = (-inf-infj) > >/usr/local/lib/python3.8/site-packages/numpy/core/tests/test_multiarray.py:8805: RuntimeWarning >__________ test_npymath_complex[complex256-inf-inf-npy_cabs-absolute] __________ > >fun = <built-in function npy_cabs>, npfun = <ufunc 'absolute'>, x = inf, y = inf >test_dtype = <class 'numpy.complex256'> > > @pytest.mark.parametrize( > ["fun", "npfun"], > [ > (_multiarray_tests.npy_cabs, np.absolute), > (_multiarray_tests.npy_carg, np.angle) > ] > ) > @pytest.mark.parametrize("x", [1, np.inf, -np.inf, np.nan]) > @pytest.mark.parametrize("y", [1, np.inf, -np.inf, np.nan]) > @pytest.mark.parametrize("test_dtype", np.complexfloating.__subclasses__()) > def test_npymath_complex(fun, npfun, x, y, test_dtype): > # Smoketest npymath functions > z = test_dtype(complex(x, y)) > got = fun(z) >> expected = npfun(z) >E RuntimeWarning: invalid value encountered in absolute > >fun = <built-in function npy_cabs> >got = array(inf) >npfun = <ufunc 'absolute'> >test_dtype = <class 'numpy.complex256'> >x = inf >y = inf >z = (inf+infj) > >/usr/local/lib/python3.8/site-packages/numpy/core/tests/test_multiarray.py:8805: RuntimeWarning >_________ test_npymath_complex[complex256-inf--inf-npy_cabs-absolute] __________ > >fun = <built-in function npy_cabs>, npfun = <ufunc 'absolute'>, x = -inf >y = inf, test_dtype = <class 'numpy.complex256'> > > @pytest.mark.parametrize( > ["fun", "npfun"], > [ > (_multiarray_tests.npy_cabs, np.absolute), > (_multiarray_tests.npy_carg, np.angle) > ] > ) > @pytest.mark.parametrize("x", [1, np.inf, -np.inf, np.nan]) > @pytest.mark.parametrize("y", [1, np.inf, -np.inf, np.nan]) > @pytest.mark.parametrize("test_dtype", np.complexfloating.__subclasses__()) > def test_npymath_complex(fun, npfun, x, y, test_dtype): > # Smoketest npymath functions > z = test_dtype(complex(x, y)) > got = fun(z) >> expected = npfun(z) >E RuntimeWarning: invalid value encountered in absolute > >fun = <built-in function npy_cabs> >got = array(inf) >npfun = <ufunc 'absolute'> >test_dtype = <class 'numpy.complex256'> >x = -inf >y = inf >z = (-inf+infj) > >/usr/local/lib/python3.8/site-packages/numpy/core/tests/test_multiarray.py:8805: RuntimeWarning >_________ test_npymath_complex[complex256--inf-inf-npy_cabs-absolute] __________ > >fun = <built-in function npy_cabs>, npfun = <ufunc 'absolute'>, x = inf >y = -inf, test_dtype = <class 'numpy.complex256'> > > @pytest.mark.parametrize( > ["fun", "npfun"], > [ > (_multiarray_tests.npy_cabs, np.absolute), > (_multiarray_tests.npy_carg, np.angle) > ] > ) > @pytest.mark.parametrize("x", [1, np.inf, -np.inf, np.nan]) > @pytest.mark.parametrize("y", [1, np.inf, -np.inf, np.nan]) > @pytest.mark.parametrize("test_dtype", np.complexfloating.__subclasses__()) > def test_npymath_complex(fun, npfun, x, y, test_dtype): > # Smoketest npymath functions > z = test_dtype(complex(x, y)) > got = fun(z) >> expected = npfun(z) >E RuntimeWarning: invalid value encountered in absolute > >fun = <built-in function npy_cabs> >got = array(inf) >npfun = <ufunc 'absolute'> >test_dtype = <class 'numpy.complex256'> >x = inf >y = -inf >z = (inf-infj) > >/usr/local/lib/python3.8/site-packages/numpy/core/tests/test_multiarray.py:8805: RuntimeWarning >_________ test_npymath_complex[complex256--inf--inf-npy_cabs-absolute] _________ > >fun = <built-in function npy_cabs>, npfun = <ufunc 'absolute'>, x = -inf >y = -inf, test_dtype = <class 'numpy.complex256'> > > @pytest.mark.parametrize( > ["fun", "npfun"], > [ > (_multiarray_tests.npy_cabs, np.absolute), > (_multiarray_tests.npy_carg, np.angle) > ] > ) > @pytest.mark.parametrize("x", [1, np.inf, -np.inf, np.nan]) > @pytest.mark.parametrize("y", [1, np.inf, -np.inf, np.nan]) > @pytest.mark.parametrize("test_dtype", np.complexfloating.__subclasses__()) > def test_npymath_complex(fun, npfun, x, y, test_dtype): > # Smoketest npymath functions > z = test_dtype(complex(x, y)) > got = fun(z) >> expected = npfun(z) >E RuntimeWarning: invalid value encountered in absolute > >fun = <built-in function npy_cabs> >got = array(inf) >npfun = <ufunc 'absolute'> >test_dtype = <class 'numpy.complex256'> >x = -inf >y = -inf >z = (-inf-infj) > >/usr/local/lib/python3.8/site-packages/numpy/core/tests/test_multiarray.py:8805: RuntimeWarning >__________________________ TestBaseMath.test_blocked ___________________________ > >self = <numpy.core.tests.test_scalarmath.TestBaseMath object at 0x845d04a00> > > def test_blocked(self): > # test alignments offsets for simd instructions > # alignments for vz + 2 * (vs - 1) + 1 > for dt, sz in [(np.float32, 11), (np.float64, 7), (np.int32, 11)]: > for out, inp1, inp2, msg in _gen_alignment_data(dtype=dt, > type='binary', > max_size=sz): > exp1 = np.ones_like(inp1) > inp1[...] = np.ones_like(inp1) > inp2[...] = np.zeros_like(inp2) > assert_almost_equal(np.add(inp1, inp2), exp1, err_msg=msg) > assert_almost_equal(np.add(inp1, 2), exp1 + 2, err_msg=msg) > assert_almost_equal(np.add(1, inp2), exp1, err_msg=msg) > > np.add(inp1, inp2, out=out) > assert_almost_equal(out, exp1, err_msg=msg) > > inp2[...] += np.arange(inp2.size, dtype=dt) + 1 > assert_almost_equal(np.square(inp2), > np.multiply(inp2, inp2), err_msg=msg) > # skip true divide for ints > if dt != np.int32: >> assert_almost_equal(np.reciprocal(inp2), > np.divide(1, inp2), err_msg=msg) >E RuntimeWarning: invalid value encountered in reciprocal > >dt = <class 'numpy.float64'> >exp1 = array([1.]) >inp1 = array([1.]) >inp2 = array([1.]) >msg = "binary offset=(1, 0, 0), size=1, dtype=<class 'numpy.float64'>, out of place" >out = array([1.]) >self = <numpy.core.tests.test_scalarmath.TestBaseMath object at 0x845d04a00> >sz = 7 > >/usr/local/lib/python3.8/site-packages/numpy/core/tests/test_scalarmath.py:91: RuntimeWarning >_____ TestUfuncGenericLoops.test_unary_PyUFunc_O_O_method_full[reciprocal] _____ > >self = <numpy.core.tests.test_ufunc.TestUfuncGenericLoops object at 0x84647a6a0> >ufunc = <ufunc 'reciprocal'> > > @pytest.mark.parametrize("ufunc", UNARY_OBJECT_UFUNCS) > def test_unary_PyUFunc_O_O_method_full(self, ufunc): > """Compare the result of the object loop with non-object one""" > val = np.float64(np.pi/4) > > class MyFloat(np.float64): > def __getattr__(self, attr): > try: > return super().__getattr__(attr) > except AttributeError: > return lambda: getattr(np.core.umath, attr)(val) > > num_arr = np.array([val], dtype=np.float64) > obj_arr = np.array([MyFloat(val)], dtype="O") > > with np.errstate(all="raise"): > try: >> res_num = ufunc(num_arr) >E FloatingPointError: invalid value encountered in reciprocal > >MyFloat = <class 'numpy.core.tests.test_ufunc.TestUfuncGenericLoops.test_unary_PyUFunc_O_O_method_full.<locals>.MyFloat'> >num_arr = array([0.78539816]) >obj_arr = array([0.7853981633974483], dtype=object) >self = <numpy.core.tests.test_ufunc.TestUfuncGenericLoops object at 0x84647a6a0> >ufunc = <ufunc 'reciprocal'> >val = 0.7853981633974483 > >/usr/local/lib/python3.8/site-packages/numpy/core/tests/test_ufunc.py:172: FloatingPointError > >During handling of the above exception, another exception occurred: > >self = <numpy.core.tests.test_ufunc.TestUfuncGenericLoops object at 0x84647a6a0> >ufunc = <ufunc 'reciprocal'> > > @pytest.mark.parametrize("ufunc", UNARY_OBJECT_UFUNCS) > def test_unary_PyUFunc_O_O_method_full(self, ufunc): > """Compare the result of the object loop with non-object one""" > val = np.float64(np.pi/4) > > class MyFloat(np.float64): > def __getattr__(self, attr): > try: > return super().__getattr__(attr) > except AttributeError: > return lambda: getattr(np.core.umath, attr)(val) > > num_arr = np.array([val], dtype=np.float64) > obj_arr = np.array([MyFloat(val)], dtype="O") > > with np.errstate(all="raise"): > try: > res_num = ufunc(num_arr) > except Exception as exc: > with assert_raises(type(exc)): >> ufunc(obj_arr) > >MyFloat = <class 'numpy.core.tests.test_ufunc.TestUfuncGenericLoops.test_unary_PyUFunc_O_O_method_full.<locals>.MyFloat'> >num_arr = array([0.78539816]) >obj_arr = array([0.7853981633974483], dtype=object) >self = <numpy.core.tests.test_ufunc.TestUfuncGenericLoops object at 0x84647a6a0> >ufunc = <ufunc 'reciprocal'> >val = 0.7853981633974483 > >/usr/local/lib/python3.8/site-packages/numpy/core/tests/test_ufunc.py:175: >_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ >/usr/local/lib/python3.8/unittest/case.py:227: in __exit__ > self._raiseFailure("{} not raised".format(exc_name)) > exc_name = 'FloatingPointError' > exc_type = None > exc_value = None > self = <unittest.case._AssertRaisesContext object at 0x84647adf0> > tb = None >_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > >self = <unittest.case._AssertRaisesContext object at 0x84647adf0> >standardMsg = 'FloatingPointError not raised' > > def _raiseFailure(self, standardMsg): > msg = self.test_case._formatMessage(self.msg, standardMsg) >> raise self.test_case.failureException(msg) >E AssertionError: FloatingPointError not raised > >msg = 'FloatingPointError not raised' >self = <unittest.case._AssertRaisesContext object at 0x84647adf0> >standardMsg = 'FloatingPointError not raised' > >/usr/local/lib/python3.8/unittest/case.py:164: AssertionError >__________________________ TestPower.test_power_float __________________________ > >self = <numpy.core.tests.test_umath.TestPower object at 0xc19815e50> > > def test_power_float(self): > x = np.array([1., 2., 3.]) > assert_equal(x**0, [1., 1., 1.]) > assert_equal(x**1, x) > assert_equal(x**2, [1., 4., 9.]) > y = x.copy() > y **= 2 > assert_equal(y, [1., 4., 9.]) >> assert_almost_equal(x**(-1), [1., 0.5, 1./3]) >E RuntimeWarning: invalid value encountered in reciprocal > >self = <numpy.core.tests.test_umath.TestPower object at 0xc19815e50> >x = array([1., 2., 3.]) >y = array([1., 4., 9.]) > >/usr/local/lib/python3.8/site-packages/numpy/core/tests/test_umath.py:716: RuntimeWarning >______________________ TestAVXUfuncs.test_avx_based_ufunc ______________________ > >self = <numpy.core.tests.test_umath.TestAVXUfuncs object at 0x846d1e9d0> > > def test_avx_based_ufunc(self): > strides = np.array([-4,-3,-2,-1,1,2,3,4]) > np.random.seed(42) > for func, prop in avx_ufuncs.items(): > maxulperr = prop[0] > minval = prop[1] > maxval = prop[2] > # various array sizes to ensure masking in AVX is tested > for size in range(1,32): > myfunc = getattr(np, func) > x_f32 = np.float32(np.random.uniform(low=minval, high=maxval, > size=size)) > x_f64 = np.float64(x_f32) > x_f128 = np.longdouble(x_f32) > y_true128 = myfunc(x_f128) > if maxulperr == 0: > assert_equal(myfunc(x_f32), np.float32(y_true128)) > assert_equal(myfunc(x_f64), np.float64(y_true128)) > else: > assert_array_max_ulp(myfunc(x_f32), np.float32(y_true128), > maxulp=maxulperr) >> assert_array_max_ulp(myfunc(x_f64), np.float64(y_true128), > maxulp=maxulperr) >E RuntimeWarning: invalid value encountered in reciprocal > >func = 'reciprocal' >jj = 4 >maxulperr = 1 >maxval = 100.0 >minval = 1.0 >myfunc = <ufunc 'reciprocal'> >prop = [1, 1.0, 100.0] >self = <numpy.core.tests.test_umath.TestAVXUfuncs object at 0x846d1e9d0> >size = 1 >strides = array([-4, -3, -2, -1, 1, 2, 3, 4]) >x_f128 = array([27.94236946], dtype=float128) >x_f32 = array([27.94237], dtype=float32) >x_f64 = 27.94236946105957 >y_true128 = array([0.03578795], dtype=float128) >y_true32 = array([20.630423 , 50.93018 , 22.140877 , 42.261253 , 28.865458 , > 43.80918 , 40.575657 , 13.280928 , ...0.90173674, > 37.68048 , 13.034533 , 50.719593 , 63.820465 , 59.883175 , > 38.939293 ], dtype=float32) >y_true64 = array([20.63042259, 50.9301796 , 22.14087677, 42.26125336, 28.86545753, > 43.80918121, 40.57565689, 13.28092766, ... 45.63775253, 0.90173674, > 37.68048096, 13.03453255, 50.71959305, 63.82046509, 59.8831749 , > 38.93929291]) > >/usr/local/lib/python3.8/site-packages/numpy/core/tests/test_umath.py:1181: RuntimeWarning >________________ TestSpecialComplexAVX.test_array[complex64--1] ________________ > >self = <numpy.core.tests.test_umath_complex.TestSpecialComplexAVX object at 0x846f87ee0> >stride = -1, astype = <class 'numpy.complex64'> > > @pytest.mark.parametrize("stride", [-4,-2,-1,1,2,4]) > @pytest.mark.parametrize("astype", [np.complex64, np.complex128]) > def test_array(self, stride, astype): > arr = np.array([complex(np.nan , np.nan), > complex(np.nan , np.inf), > complex(np.inf , np.nan), > complex(np.inf , np.inf), > complex(0. , np.inf), > complex(np.inf , 0.), > complex(0. , 0.), > complex(0. , np.nan), > complex(np.nan , 0.)], dtype=astype) > abs_true = np.array([np.nan, np.inf, np.inf, np.inf, np.inf, np.inf, 0., np.nan, np.nan], dtype=arr.real.dtype) > sq_true = np.array([complex(np.nan, np.nan), > complex(np.nan, np.nan), > complex(np.nan, np.nan), > complex(np.nan, np.inf), > complex(-np.inf, np.nan), > complex(np.inf, np.nan), > complex(0., 0.), > complex(np.nan, np.nan), > complex(np.nan, np.nan)], dtype=astype) >> assert_equal(np.abs(arr[::stride]), abs_true[::stride]) >E RuntimeWarning: invalid value encountered in absolute > >abs_true = array([nan, inf, inf, inf, inf, inf, 0., nan, nan], dtype=float32) >arr = array([nan+nanj, nan+infj, inf+nanj, inf+infj, 0.+infj, inf +0.j, > 0. +0.j, 0.+nanj, nan +0.j], dtype=complex64) >astype = <class 'numpy.complex64'> >self = <numpy.core.tests.test_umath_complex.TestSpecialComplexAVX object at 0x846f87ee0> >sq_true = array([ nan+nanj, nan+nanj, nan+nanj, nan+infj, -inf+nanj, inf+nanj, > 0. +0.j, nan+nanj, nan+nanj], dtype=complex64) >stride = -1 > >/usr/local/lib/python3.8/site-packages/numpy/core/tests/test_umath_complex.py:581: RuntimeWarning >________________ TestSpecialComplexAVX.test_array[complex64-1] _________________ > >self = <numpy.core.tests.test_umath_complex.TestSpecialComplexAVX object at 0x846f874f0> >stride = 1, astype = <class 'numpy.complex64'> > > @pytest.mark.parametrize("stride", [-4,-2,-1,1,2,4]) > @pytest.mark.parametrize("astype", [np.complex64, np.complex128]) > def test_array(self, stride, astype): > arr = np.array([complex(np.nan , np.nan), > complex(np.nan , np.inf), > complex(np.inf , np.nan), > complex(np.inf , np.inf), > complex(0. , np.inf), > complex(np.inf , 0.), > complex(0. , 0.), > complex(0. , np.nan), > complex(np.nan , 0.)], dtype=astype) > abs_true = np.array([np.nan, np.inf, np.inf, np.inf, np.inf, np.inf, 0., np.nan, np.nan], dtype=arr.real.dtype) > sq_true = np.array([complex(np.nan, np.nan), > complex(np.nan, np.nan), > complex(np.nan, np.nan), > complex(np.nan, np.inf), > complex(-np.inf, np.nan), > complex(np.inf, np.nan), > complex(0., 0.), > complex(np.nan, np.nan), > complex(np.nan, np.nan)], dtype=astype) >> assert_equal(np.abs(arr[::stride]), abs_true[::stride]) >E RuntimeWarning: invalid value encountered in absolute > >abs_true = array([nan, inf, inf, inf, inf, inf, 0., nan, nan], dtype=float32) >arr = array([nan+nanj, nan+infj, inf+nanj, inf+infj, 0.+infj, inf +0.j, > 0. +0.j, 0.+nanj, nan +0.j], dtype=complex64) >astype = <class 'numpy.complex64'> >self = <numpy.core.tests.test_umath_complex.TestSpecialComplexAVX object at 0x846f874f0> >sq_true = array([ nan+nanj, nan+nanj, nan+nanj, nan+infj, -inf+nanj, inf+nanj, > 0. +0.j, nan+nanj, nan+nanj], dtype=complex64) >stride = 1 > >/usr/local/lib/python3.8/site-packages/numpy/core/tests/test_umath_complex.py:581: RuntimeWarning >_______________ TestSpecialComplexAVX.test_array[complex128--1] ________________ > >self = <numpy.core.tests.test_umath_complex.TestSpecialComplexAVX object at 0x846ea43a0> >stride = -1, astype = <class 'numpy.complex128'> > > @pytest.mark.parametrize("stride", [-4,-2,-1,1,2,4]) > @pytest.mark.parametrize("astype", [np.complex64, np.complex128]) > def test_array(self, stride, astype): > arr = np.array([complex(np.nan , np.nan), > complex(np.nan , np.inf), > complex(np.inf , np.nan), > complex(np.inf , np.inf), > complex(0. , np.inf), > complex(np.inf , 0.), > complex(0. , 0.), > complex(0. , np.nan), > complex(np.nan , 0.)], dtype=astype) > abs_true = np.array([np.nan, np.inf, np.inf, np.inf, np.inf, np.inf, 0., np.nan, np.nan], dtype=arr.real.dtype) > sq_true = np.array([complex(np.nan, np.nan), > complex(np.nan, np.nan), > complex(np.nan, np.nan), > complex(np.nan, np.inf), > complex(-np.inf, np.nan), > complex(np.inf, np.nan), > complex(0., 0.), > complex(np.nan, np.nan), > complex(np.nan, np.nan)], dtype=astype) >> assert_equal(np.abs(arr[::stride]), abs_true[::stride]) >E RuntimeWarning: invalid value encountered in absolute > >abs_true = array([nan, inf, inf, inf, inf, inf, 0., nan, nan]) >arr = array([nan+nanj, nan+infj, inf+nanj, inf+infj, 0.+infj, inf +0.j, > 0. +0.j, 0.+nanj, nan +0.j]) >astype = <class 'numpy.complex128'> >self = <numpy.core.tests.test_umath_complex.TestSpecialComplexAVX object at 0x846ea43a0> >sq_true = array([ nan+nanj, nan+nanj, nan+nanj, nan+infj, -inf+nanj, inf+nanj, > 0. +0.j, nan+nanj, nan+nanj]) >stride = -1 > >/usr/local/lib/python3.8/site-packages/numpy/core/tests/test_umath_complex.py:581: RuntimeWarning >________________ TestSpecialComplexAVX.test_array[complex128-1] ________________ > >self = <numpy.core.tests.test_umath_complex.TestSpecialComplexAVX object at 0xc19b1bf10> >stride = 1, astype = <class 'numpy.complex128'> > > @pytest.mark.parametrize("stride", [-4,-2,-1,1,2,4]) > @pytest.mark.parametrize("astype", [np.complex64, np.complex128]) > def test_array(self, stride, astype): > arr = np.array([complex(np.nan , np.nan), > complex(np.nan , np.inf), > complex(np.inf , np.nan), > complex(np.inf , np.inf), > complex(0. , np.inf), > complex(np.inf , 0.), > complex(0. , 0.), > complex(0. , np.nan), > complex(np.nan , 0.)], dtype=astype) > abs_true = np.array([np.nan, np.inf, np.inf, np.inf, np.inf, np.inf, 0., np.nan, np.nan], dtype=arr.real.dtype) > sq_true = np.array([complex(np.nan, np.nan), > complex(np.nan, np.nan), > complex(np.nan, np.nan), > complex(np.nan, np.inf), > complex(-np.inf, np.nan), > complex(np.inf, np.nan), > complex(0., 0.), > complex(np.nan, np.nan), > complex(np.nan, np.nan)], dtype=astype) >> assert_equal(np.abs(arr[::stride]), abs_true[::stride]) >E RuntimeWarning: invalid value encountered in absolute > >abs_true = array([nan, inf, inf, inf, inf, inf, 0., nan, nan]) >arr = array([nan+nanj, nan+infj, inf+nanj, inf+infj, 0.+infj, inf +0.j, > 0. +0.j, 0.+nanj, nan +0.j]) >astype = <class 'numpy.complex128'> >self = <numpy.core.tests.test_umath_complex.TestSpecialComplexAVX object at 0xc19b1bf10> >sq_true = array([ nan+nanj, nan+nanj, nan+nanj, nan+infj, -inf+nanj, inf+nanj, > 0. +0.j, nan+nanj, nan+nanj]) >stride = 1 > >/usr/local/lib/python3.8/site-packages/numpy/core/tests/test_umath_complex.py:581: RuntimeWarning >____________________ TestNormDouble.test_vector_return_type ____________________ > >self = <numpy.linalg.tests.test_linalg.TestNormDouble object at 0xc28681f10> > > def test_vector_return_type(self): > a = np.array([1, 0, 1]) > > exact_types = np.typecodes['AllInteger'] > inexact_types = np.typecodes['AllFloat'] > > all_types = exact_types + inexact_types > > for each_inexact_types in all_types: > at = a.astype(each_inexact_types) > > an = norm(at, -np.inf) > assert_(issubclass(an.dtype.type, np.floating)) > assert_almost_equal(an, 0.0) > > with suppress_warnings() as sup: > sup.filter(RuntimeWarning, "divide by zero encountered") >> an = norm(at, -1) > >a = array([1, 0, 1]) >all_types = 'bBhHiIlLqQpPefdgFDG' >an = 0.0 >at = array([1, 0, 1], dtype=int8) >each_inexact_types = 'b' >exact_types = 'bBhHiIlLqQpP' >inexact_types = 'efdgFDG' >self = <numpy.linalg.tests.test_linalg.TestNormDouble object at 0xc28681f10> >sup = <numpy.testing._private.utils.suppress_warnings object at 0xc286761c0> > >/usr/local/lib/python3.8/site-packages/numpy/linalg/tests/test_linalg.py:1252: >_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ><__array_function__ internals>:5: in norm > ??? > args = (array([1, 0, 1], dtype=int8), -1) > kwargs = {} > relevant_args = (array([1, 0, 1], dtype=int8),) >_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > >x = array([1., 0., 1.]), ord = -1, axis = (0,), keepdims = False > > @array_function_dispatch(_norm_dispatcher) > def norm(x, ord=None, axis=None, keepdims=False): > """ > Matrix or vector norm. > > This function is able to return one of eight different matrix norms, > or one of an infinite number of vector norms (described below), depending > on the value of the ``ord`` parameter. > > Parameters > ---------- > x : array_like > Input array. If `axis` is None, `x` must be 1-D or 2-D, unless `ord` > is None. If both `axis` and `ord` are None, the 2-norm of > ``x.ravel`` will be returned. > ord : {non-zero int, inf, -inf, 'fro', 'nuc'}, optional > Order of the norm (see table under ``Notes``). inf means numpy's > `inf` object. The default is None. > axis : {None, int, 2-tuple of ints}, optional. > If `axis` is an integer, it specifies the axis of `x` along which to > compute the vector norms. If `axis` is a 2-tuple, it specifies the > axes that hold 2-D matrices, and the matrix norms of these matrices > are computed. If `axis` is None then either a vector norm (when `x` > is 1-D) or a matrix norm (when `x` is 2-D) is returned. The default > is None. > > .. versionadded:: 1.8.0 > > keepdims : bool, optional > If this is set to True, the axes which are normed over are left in the > result as dimensions with size one. With this option the result will > broadcast correctly against the original `x`. > > .. versionadded:: 1.10.0 > > Returns > ------- > n : float or ndarray > Norm of the matrix or vector(s). > > See Also > -------- > scipy.linalg.norm : Similar function in SciPy. > > Notes > ----- > For values of ``ord < 1``, the result is, strictly speaking, not a > mathematical 'norm', but it may still be useful for various numerical > purposes. > > The following norms can be calculated: > > ===== ============================ ========================== > ord norm for matrices norm for vectors > ===== ============================ ========================== > None Frobenius norm 2-norm > 'fro' Frobenius norm -- > 'nuc' nuclear norm -- > inf max(sum(abs(x), axis=1)) max(abs(x)) > -inf min(sum(abs(x), axis=1)) min(abs(x)) > 0 -- sum(x != 0) > 1 max(sum(abs(x), axis=0)) as below > -1 min(sum(abs(x), axis=0)) as below > 2 2-norm (largest sing. value) as below > -2 smallest singular value as below > other -- sum(abs(x)**ord)**(1./ord) > ===== ============================ ========================== > > The Frobenius norm is given by [1]_: > > :math:`||A||_F = [\\sum_{i,j} abs(a_{i,j})^2]^{1/2}` > > The nuclear norm is the sum of the singular values. > > Both the Frobenius and nuclear norm orders are only defined for > matrices and raise a ValueError when ``x.ndim != 2``. > > References > ---------- > .. [1] G. H. Golub and C. F. Van Loan, *Matrix Computations*, > Baltimore, MD, Johns Hopkins University Press, 1985, pg. 15 > > Examples > -------- > >>> from numpy import linalg as LA > >>> a = np.arange(9) - 4 > >>> a > array([-4, -3, -2, ..., 2, 3, 4]) > >>> b = a.reshape((3, 3)) > >>> b > array([[-4, -3, -2], > [-1, 0, 1], > [ 2, 3, 4]]) > > >>> LA.norm(a) > 7.745966692414834 > >>> LA.norm(b) > 7.745966692414834 > >>> LA.norm(b, 'fro') > 7.745966692414834 > >>> LA.norm(a, np.inf) > 4.0 > >>> LA.norm(b, np.inf) > 9.0 > >>> LA.norm(a, -np.inf) > 0.0 > >>> LA.norm(b, -np.inf) > 2.0 > > >>> LA.norm(a, 1) > 20.0 > >>> LA.norm(b, 1) > 7.0 > >>> LA.norm(a, -1) > -4.6566128774142013e-010 > >>> LA.norm(b, -1) > 6.0 > >>> LA.norm(a, 2) > 7.745966692414834 > >>> LA.norm(b, 2) > 7.3484692283495345 > > >>> LA.norm(a, -2) > 0.0 > >>> LA.norm(b, -2) > 1.8570331885190563e-016 # may vary > >>> LA.norm(a, 3) > 5.8480354764257312 # may vary > >>> LA.norm(a, -3) > 0.0 > > Using the `axis` argument to compute vector norms: > > >>> c = np.array([[ 1, 2, 3], > ... [-1, 1, 4]]) > >>> LA.norm(c, axis=0) > array([ 1.41421356, 2.23606798, 5. ]) > >>> LA.norm(c, axis=1) > array([ 3.74165739, 4.24264069]) > >>> LA.norm(c, ord=1, axis=1) > array([ 6., 6.]) > > Using the `axis` argument to compute matrix norms: > > >>> m = np.arange(8).reshape(2,2,2) > >>> LA.norm(m, axis=(1,2)) > array([ 3.74165739, 11.22497216]) > >>> LA.norm(m[0, :, :]), LA.norm(m[1, :, :]) > (3.7416573867739413, 11.224972160321824) > > """ > x = asarray(x) > > if not issubclass(x.dtype.type, (inexact, object_)): > x = x.astype(float) > > # Immediately handle some default, simple, fast, and common cases. > if axis is None: > ndim = x.ndim > if ((ord is None) or > (ord in ('f', 'fro') and ndim == 2) or > (ord == 2 and ndim == 1)): > > x = x.ravel(order='K') > if isComplexType(x.dtype.type): > sqnorm = dot(x.real, x.real) + dot(x.imag, x.imag) > else: > sqnorm = dot(x, x) > ret = sqrt(sqnorm) > if keepdims: > ret = ret.reshape(ndim*[1]) > return ret > > # Normalize the `axis` argument to a tuple. > nd = x.ndim > if axis is None: > axis = tuple(range(nd)) > elif not isinstance(axis, tuple): > try: > axis = int(axis) > except Exception as e: > raise TypeError("'axis' must be None, an integer or a tuple of integers") from e > axis = (axis,) > > if len(axis) == 1: > if ord == Inf: > return abs(x).max(axis=axis, keepdims=keepdims) > elif ord == -Inf: > return abs(x).min(axis=axis, keepdims=keepdims) > elif ord == 0: > # Zero norm > return (x != 0).astype(x.real.dtype).sum(axis=axis, keepdims=keepdims) > elif ord == 1: > # special case for speedup > return add.reduce(abs(x), axis=axis, keepdims=keepdims) > elif ord is None or ord == 2: > # special case for speedup > s = (x.conj() * x).real > return sqrt(add.reduce(s, axis=axis, keepdims=keepdims)) > # None of the str-type keywords for ord ('fro', 'nuc') > # are valid for vectors > elif isinstance(ord, str): > raise ValueError(f"Invalid norm order '{ord}' for vectors") > else: > absx = abs(x) >> absx **= ord >E RuntimeWarning: invalid value encountered in reciprocal > >absx = array([ 1., inf, 1.]) >axis = (0,) >keepdims = False >nd = 1 >ndim = 1 >ord = -1 >x = array([1., 0., 1.]) > >/usr/local/lib/python3.8/site-packages/numpy/linalg/linalg.py:2568: RuntimeWarning >___________________________ TestNormDouble.test_axis ___________________________ > >self = <numpy.linalg.tests.test_linalg.TestNormDouble object at 0xc2891e310> > > def test_axis(self): > # Vector norms. > # Compare the use of `axis` with computing the norm of each row > # or column separately. > A = array([[1, 2, 3], [4, 5, 6]], dtype=self.dt) > for order in [None, -1, 0, 1, 2, 3, np.Inf, -np.Inf]: > expected0 = [norm(A[:, k], ord=order) for k in range(A.shape[1])] >> assert_almost_equal(norm(A, ord=order, axis=0), expected0) > >A = array([[1., 2., 3.], > [4., 5., 6.]]) >expected0 = [0.8, 1.4285714285714286, 2.0] >expected1 = [3.7416573867739413, 8.774964387392123] >order = -1 >self = <numpy.linalg.tests.test_linalg.TestNormDouble object at 0xc2891e310> > >/usr/local/lib/python3.8/site-packages/numpy/linalg/tests/test_linalg.py:1313: >_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ><__array_function__ internals>:5: in norm > ??? > args = (array([[1., 2., 3.], > [4., 5., 6.]]),) > kwargs = {'axis': 0, 'ord': -1} > relevant_args = (array([[1., 2., 3.], > [4., 5., 6.]]),) >_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > >x = array([[1., 2., 3.], > [4., 5., 6.]]), ord = -1, axis = (0,) >keepdims = False > > @array_function_dispatch(_norm_dispatcher) > def norm(x, ord=None, axis=None, keepdims=False): > """ > Matrix or vector norm. > > This function is able to return one of eight different matrix norms, > or one of an infinite number of vector norms (described below), depending > on the value of the ``ord`` parameter. > > Parameters > ---------- > x : array_like > Input array. If `axis` is None, `x` must be 1-D or 2-D, unless `ord` > is None. If both `axis` and `ord` are None, the 2-norm of > ``x.ravel`` will be returned. > ord : {non-zero int, inf, -inf, 'fro', 'nuc'}, optional > Order of the norm (see table under ``Notes``). inf means numpy's > `inf` object. The default is None. > axis : {None, int, 2-tuple of ints}, optional. > If `axis` is an integer, it specifies the axis of `x` along which to > compute the vector norms. If `axis` is a 2-tuple, it specifies the > axes that hold 2-D matrices, and the matrix norms of these matrices > are computed. If `axis` is None then either a vector norm (when `x` > is 1-D) or a matrix norm (when `x` is 2-D) is returned. The default > is None. > > .. versionadded:: 1.8.0 > > keepdims : bool, optional > If this is set to True, the axes which are normed over are left in the > result as dimensions with size one. With this option the result will > broadcast correctly against the original `x`. > > .. versionadded:: 1.10.0 > > Returns > ------- > n : float or ndarray > Norm of the matrix or vector(s). > > See Also > -------- > scipy.linalg.norm : Similar function in SciPy. > > Notes > ----- > For values of ``ord < 1``, the result is, strictly speaking, not a > mathematical 'norm', but it may still be useful for various numerical > purposes. > > The following norms can be calculated: > > ===== ============================ ========================== > ord norm for matrices norm for vectors > ===== ============================ ========================== > None Frobenius norm 2-norm > 'fro' Frobenius norm -- > 'nuc' nuclear norm -- > inf max(sum(abs(x), axis=1)) max(abs(x)) > -inf min(sum(abs(x), axis=1)) min(abs(x)) > 0 -- sum(x != 0) > 1 max(sum(abs(x), axis=0)) as below > -1 min(sum(abs(x), axis=0)) as below > 2 2-norm (largest sing. value) as below > -2 smallest singular value as below > other -- sum(abs(x)**ord)**(1./ord) > ===== ============================ ========================== > > The Frobenius norm is given by [1]_: > > :math:`||A||_F = [\\sum_{i,j} abs(a_{i,j})^2]^{1/2}` > > The nuclear norm is the sum of the singular values. > > Both the Frobenius and nuclear norm orders are only defined for > matrices and raise a ValueError when ``x.ndim != 2``. > > References > ---------- > .. [1] G. H. Golub and C. F. Van Loan, *Matrix Computations*, > Baltimore, MD, Johns Hopkins University Press, 1985, pg. 15 > > Examples > -------- > >>> from numpy import linalg as LA > >>> a = np.arange(9) - 4 > >>> a > array([-4, -3, -2, ..., 2, 3, 4]) > >>> b = a.reshape((3, 3)) > >>> b > array([[-4, -3, -2], > [-1, 0, 1], > [ 2, 3, 4]]) > > >>> LA.norm(a) > 7.745966692414834 > >>> LA.norm(b) > 7.745966692414834 > >>> LA.norm(b, 'fro') > 7.745966692414834 > >>> LA.norm(a, np.inf) > 4.0 > >>> LA.norm(b, np.inf) > 9.0 > >>> LA.norm(a, -np.inf) > 0.0 > >>> LA.norm(b, -np.inf) > 2.0 > > >>> LA.norm(a, 1) > 20.0 > >>> LA.norm(b, 1) > 7.0 > >>> LA.norm(a, -1) > -4.6566128774142013e-010 > >>> LA.norm(b, -1) > 6.0 > >>> LA.norm(a, 2) > 7.745966692414834 > >>> LA.norm(b, 2) > 7.3484692283495345 > > >>> LA.norm(a, -2) > 0.0 > >>> LA.norm(b, -2) > 1.8570331885190563e-016 # may vary > >>> LA.norm(a, 3) > 5.8480354764257312 # may vary > >>> LA.norm(a, -3) > 0.0 > > Using the `axis` argument to compute vector norms: > > >>> c = np.array([[ 1, 2, 3], > ... [-1, 1, 4]]) > >>> LA.norm(c, axis=0) > array([ 1.41421356, 2.23606798, 5. ]) > >>> LA.norm(c, axis=1) > array([ 3.74165739, 4.24264069]) > >>> LA.norm(c, ord=1, axis=1) > array([ 6., 6.]) > > Using the `axis` argument to compute matrix norms: > > >>> m = np.arange(8).reshape(2,2,2) > >>> LA.norm(m, axis=(1,2)) > array([ 3.74165739, 11.22497216]) > >>> LA.norm(m[0, :, :]), LA.norm(m[1, :, :]) > (3.7416573867739413, 11.224972160321824) > > """ > x = asarray(x) > > if not issubclass(x.dtype.type, (inexact, object_)): > x = x.astype(float) > > # Immediately handle some default, simple, fast, and common cases. > if axis is None: > ndim = x.ndim > if ((ord is None) or > (ord in ('f', 'fro') and ndim == 2) or > (ord == 2 and ndim == 1)): > > x = x.ravel(order='K') > if isComplexType(x.dtype.type): > sqnorm = dot(x.real, x.real) + dot(x.imag, x.imag) > else: > sqnorm = dot(x, x) > ret = sqrt(sqnorm) > if keepdims: > ret = ret.reshape(ndim*[1]) > return ret > > # Normalize the `axis` argument to a tuple. > nd = x.ndim > if axis is None: > axis = tuple(range(nd)) > elif not isinstance(axis, tuple): > try: > axis = int(axis) > except Exception as e: > raise TypeError("'axis' must be None, an integer or a tuple of integers") from e > axis = (axis,) > > if len(axis) == 1: > if ord == Inf: > return abs(x).max(axis=axis, keepdims=keepdims) > elif ord == -Inf: > return abs(x).min(axis=axis, keepdims=keepdims) > elif ord == 0: > # Zero norm > return (x != 0).astype(x.real.dtype).sum(axis=axis, keepdims=keepdims) > elif ord == 1: > # special case for speedup > return add.reduce(abs(x), axis=axis, keepdims=keepdims) > elif ord is None or ord == 2: > # special case for speedup > s = (x.conj() * x).real > return sqrt(add.reduce(s, axis=axis, keepdims=keepdims)) > # None of the str-type keywords for ord ('fro', 'nuc') > # are valid for vectors > elif isinstance(ord, str): > raise ValueError(f"Invalid norm order '{ord}' for vectors") > else: > absx = abs(x) > absx **= ord > ret = add.reduce(absx, axis=axis, keepdims=keepdims) >> ret **= (1 / ord) >E RuntimeWarning: invalid value encountered in reciprocal > >absx = array([[1. , 0.5 , 0.33333333], > [0.25 , 0.2 , 0.16666667]]) >axis = (0,) >keepdims = False >nd = 2 >ord = -1 >ret = array([0.8 , 1.42857143, 2. ]) >x = array([[1., 2., 3.], > [4., 5., 6.]]) > >/usr/local/lib/python3.8/site-packages/numpy/linalg/linalg.py:2570: RuntimeWarning >____________________ TestNormSingle.test_vector_return_type ____________________ > >self = <numpy.linalg.tests.test_linalg.TestNormSingle object at 0xc2885ec10> > > def test_vector_return_type(self): > a = np.array([1, 0, 1]) > > exact_types = np.typecodes['AllInteger'] > inexact_types = np.typecodes['AllFloat'] > > all_types = exact_types + inexact_types > > for each_inexact_types in all_types: > at = a.astype(each_inexact_types) > > an = norm(at, -np.inf) > assert_(issubclass(an.dtype.type, np.floating)) > assert_almost_equal(an, 0.0) > > with suppress_warnings() as sup: > sup.filter(RuntimeWarning, "divide by zero encountered") >> an = norm(at, -1) > >a = array([1, 0, 1]) >all_types = 'bBhHiIlLqQpPefdgFDG' >an = 0.0 >at = array([1, 0, 1], dtype=int8) >each_inexact_types = 'b' >exact_types = 'bBhHiIlLqQpP' >inexact_types = 'efdgFDG' >self = <numpy.linalg.tests.test_linalg.TestNormSingle object at 0xc2885ec10> >sup = <numpy.testing._private.utils.suppress_warnings object at 0xc28849a00> > >/usr/local/lib/python3.8/site-packages/numpy/linalg/tests/test_linalg.py:1252: >_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ><__array_function__ internals>:5: in norm > ??? > args = (array([1, 0, 1], dtype=int8), -1) > kwargs = {} > relevant_args = (array([1, 0, 1], dtype=int8),) >_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > >x = array([1., 0., 1.]), ord = -1, axis = (0,), keepdims = False > > @array_function_dispatch(_norm_dispatcher) > def norm(x, ord=None, axis=None, keepdims=False): > """ > Matrix or vector norm. > > This function is able to return one of eight different matrix norms, > or one of an infinite number of vector norms (described below), depending > on the value of the ``ord`` parameter. > > Parameters > ---------- > x : array_like > Input array. If `axis` is None, `x` must be 1-D or 2-D, unless `ord` > is None. If both `axis` and `ord` are None, the 2-norm of > ``x.ravel`` will be returned. > ord : {non-zero int, inf, -inf, 'fro', 'nuc'}, optional > Order of the norm (see table under ``Notes``). inf means numpy's > `inf` object. The default is None. > axis : {None, int, 2-tuple of ints}, optional. > If `axis` is an integer, it specifies the axis of `x` along which to > compute the vector norms. If `axis` is a 2-tuple, it specifies the > axes that hold 2-D matrices, and the matrix norms of these matrices > are computed. If `axis` is None then either a vector norm (when `x` > is 1-D) or a matrix norm (when `x` is 2-D) is returned. The default > is None. > > .. versionadded:: 1.8.0 > > keepdims : bool, optional > If this is set to True, the axes which are normed over are left in the > result as dimensions with size one. With this option the result will > broadcast correctly against the original `x`. > > .. versionadded:: 1.10.0 > > Returns > ------- > n : float or ndarray > Norm of the matrix or vector(s). > > See Also > -------- > scipy.linalg.norm : Similar function in SciPy. > > Notes > ----- > For values of ``ord < 1``, the result is, strictly speaking, not a > mathematical 'norm', but it may still be useful for various numerical > purposes. > > The following norms can be calculated: > > ===== ============================ ========================== > ord norm for matrices norm for vectors > ===== ============================ ========================== > None Frobenius norm 2-norm > 'fro' Frobenius norm -- > 'nuc' nuclear norm -- > inf max(sum(abs(x), axis=1)) max(abs(x)) > -inf min(sum(abs(x), axis=1)) min(abs(x)) > 0 -- sum(x != 0) > 1 max(sum(abs(x), axis=0)) as below > -1 min(sum(abs(x), axis=0)) as below > 2 2-norm (largest sing. value) as below > -2 smallest singular value as below > other -- sum(abs(x)**ord)**(1./ord) > ===== ============================ ========================== > > The Frobenius norm is given by [1]_: > > :math:`||A||_F = [\\sum_{i,j} abs(a_{i,j})^2]^{1/2}` > > The nuclear norm is the sum of the singular values. > > Both the Frobenius and nuclear norm orders are only defined for > matrices and raise a ValueError when ``x.ndim != 2``. > > References > ---------- > .. [1] G. H. Golub and C. F. Van Loan, *Matrix Computations*, > Baltimore, MD, Johns Hopkins University Press, 1985, pg. 15 > > Examples > -------- > >>> from numpy import linalg as LA > >>> a = np.arange(9) - 4 > >>> a > array([-4, -3, -2, ..., 2, 3, 4]) > >>> b = a.reshape((3, 3)) > >>> b > array([[-4, -3, -2], > [-1, 0, 1], > [ 2, 3, 4]]) > > >>> LA.norm(a) > 7.745966692414834 > >>> LA.norm(b) > 7.745966692414834 > >>> LA.norm(b, 'fro') > 7.745966692414834 > >>> LA.norm(a, np.inf) > 4.0 > >>> LA.norm(b, np.inf) > 9.0 > >>> LA.norm(a, -np.inf) > 0.0 > >>> LA.norm(b, -np.inf) > 2.0 > > >>> LA.norm(a, 1) > 20.0 > >>> LA.norm(b, 1) > 7.0 > >>> LA.norm(a, -1) > -4.6566128774142013e-010 > >>> LA.norm(b, -1) > 6.0 > >>> LA.norm(a, 2) > 7.745966692414834 > >>> LA.norm(b, 2) > 7.3484692283495345 > > >>> LA.norm(a, -2) > 0.0 > >>> LA.norm(b, -2) > 1.8570331885190563e-016 # may vary > >>> LA.norm(a, 3) > 5.8480354764257312 # may vary > >>> LA.norm(a, -3) > 0.0 > > Using the `axis` argument to compute vector norms: > > >>> c = np.array([[ 1, 2, 3], > ... [-1, 1, 4]]) > >>> LA.norm(c, axis=0) > array([ 1.41421356, 2.23606798, 5. ]) > >>> LA.norm(c, axis=1) > array([ 3.74165739, 4.24264069]) > >>> LA.norm(c, ord=1, axis=1) > array([ 6., 6.]) > > Using the `axis` argument to compute matrix norms: > > >>> m = np.arange(8).reshape(2,2,2) > >>> LA.norm(m, axis=(1,2)) > array([ 3.74165739, 11.22497216]) > >>> LA.norm(m[0, :, :]), LA.norm(m[1, :, :]) > (3.7416573867739413, 11.224972160321824) > > """ > x = asarray(x) > > if not issubclass(x.dtype.type, (inexact, object_)): > x = x.astype(float) > > # Immediately handle some default, simple, fast, and common cases. > if axis is None: > ndim = x.ndim > if ((ord is None) or > (ord in ('f', 'fro') and ndim == 2) or > (ord == 2 and ndim == 1)): > > x = x.ravel(order='K') > if isComplexType(x.dtype.type): > sqnorm = dot(x.real, x.real) + dot(x.imag, x.imag) > else: > sqnorm = dot(x, x) > ret = sqrt(sqnorm) > if keepdims: > ret = ret.reshape(ndim*[1]) > return ret > > # Normalize the `axis` argument to a tuple. > nd = x.ndim > if axis is None: > axis = tuple(range(nd)) > elif not isinstance(axis, tuple): > try: > axis = int(axis) > except Exception as e: > raise TypeError("'axis' must be None, an integer or a tuple of integers") from e > axis = (axis,) > > if len(axis) == 1: > if ord == Inf: > return abs(x).max(axis=axis, keepdims=keepdims) > elif ord == -Inf: > return abs(x).min(axis=axis, keepdims=keepdims) > elif ord == 0: > # Zero norm > return (x != 0).astype(x.real.dtype).sum(axis=axis, keepdims=keepdims) > elif ord == 1: > # special case for speedup > return add.reduce(abs(x), axis=axis, keepdims=keepdims) > elif ord is None or ord == 2: > # special case for speedup > s = (x.conj() * x).real > return sqrt(add.reduce(s, axis=axis, keepdims=keepdims)) > # None of the str-type keywords for ord ('fro', 'nuc') > # are valid for vectors > elif isinstance(ord, str): > raise ValueError(f"Invalid norm order '{ord}' for vectors") > else: > absx = abs(x) >> absx **= ord >E RuntimeWarning: invalid value encountered in reciprocal > >absx = array([ 1., inf, 1.]) >axis = (0,) >keepdims = False >nd = 1 >ndim = 1 >ord = -1 >x = array([1., 0., 1.]) > >/usr/local/lib/python3.8/site-packages/numpy/linalg/linalg.py:2568: RuntimeWarning >____________________ TestNormInt64.test_vector_return_type _____________________ > >self = <numpy.linalg.tests.test_linalg.TestNormInt64 object at 0xc28858f70> > > def test_vector_return_type(self): > a = np.array([1, 0, 1]) > > exact_types = np.typecodes['AllInteger'] > inexact_types = np.typecodes['AllFloat'] > > all_types = exact_types + inexact_types > > for each_inexact_types in all_types: > at = a.astype(each_inexact_types) > > an = norm(at, -np.inf) > assert_(issubclass(an.dtype.type, np.floating)) > assert_almost_equal(an, 0.0) > > with suppress_warnings() as sup: > sup.filter(RuntimeWarning, "divide by zero encountered") >> an = norm(at, -1) > >a = array([1, 0, 1]) >all_types = 'bBhHiIlLqQpPefdgFDG' >an = 0.0 >at = array([1, 0, 1], dtype=int8) >each_inexact_types = 'b' >exact_types = 'bBhHiIlLqQpP' >inexact_types = 'efdgFDG' >self = <numpy.linalg.tests.test_linalg.TestNormInt64 object at 0xc28858f70> >sup = <numpy.testing._private.utils.suppress_warnings object at 0xc2867e250> > >/usr/local/lib/python3.8/site-packages/numpy/linalg/tests/test_linalg.py:1252: >_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ><__array_function__ internals>:5: in norm > ??? > args = (array([1, 0, 1], dtype=int8), -1) > kwargs = {} > relevant_args = (array([1, 0, 1], dtype=int8),) >_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > >x = array([1., 0., 1.]), ord = -1, axis = (0,), keepdims = False > > @array_function_dispatch(_norm_dispatcher) > def norm(x, ord=None, axis=None, keepdims=False): > """ > Matrix or vector norm. > > This function is able to return one of eight different matrix norms, > or one of an infinite number of vector norms (described below), depending > on the value of the ``ord`` parameter. > > Parameters > ---------- > x : array_like > Input array. If `axis` is None, `x` must be 1-D or 2-D, unless `ord` > is None. If both `axis` and `ord` are None, the 2-norm of > ``x.ravel`` will be returned. > ord : {non-zero int, inf, -inf, 'fro', 'nuc'}, optional > Order of the norm (see table under ``Notes``). inf means numpy's > `inf` object. The default is None. > axis : {None, int, 2-tuple of ints}, optional. > If `axis` is an integer, it specifies the axis of `x` along which to > compute the vector norms. If `axis` is a 2-tuple, it specifies the > axes that hold 2-D matrices, and the matrix norms of these matrices > are computed. If `axis` is None then either a vector norm (when `x` > is 1-D) or a matrix norm (when `x` is 2-D) is returned. The default > is None. > > .. versionadded:: 1.8.0 > > keepdims : bool, optional > If this is set to True, the axes which are normed over are left in the > result as dimensions with size one. With this option the result will > broadcast correctly against the original `x`. > > .. versionadded:: 1.10.0 > > Returns > ------- > n : float or ndarray > Norm of the matrix or vector(s). > > See Also > -------- > scipy.linalg.norm : Similar function in SciPy. > > Notes > ----- > For values of ``ord < 1``, the result is, strictly speaking, not a > mathematical 'norm', but it may still be useful for various numerical > purposes. > > The following norms can be calculated: > > ===== ============================ ========================== > ord norm for matrices norm for vectors > ===== ============================ ========================== > None Frobenius norm 2-norm > 'fro' Frobenius norm -- > 'nuc' nuclear norm -- > inf max(sum(abs(x), axis=1)) max(abs(x)) > -inf min(sum(abs(x), axis=1)) min(abs(x)) > 0 -- sum(x != 0) > 1 max(sum(abs(x), axis=0)) as below > -1 min(sum(abs(x), axis=0)) as below > 2 2-norm (largest sing. value) as below > -2 smallest singular value as below > other -- sum(abs(x)**ord)**(1./ord) > ===== ============================ ========================== > > The Frobenius norm is given by [1]_: > > :math:`||A||_F = [\\sum_{i,j} abs(a_{i,j})^2]^{1/2}` > > The nuclear norm is the sum of the singular values. > > Both the Frobenius and nuclear norm orders are only defined for > matrices and raise a ValueError when ``x.ndim != 2``. > > References > ---------- > .. [1] G. H. Golub and C. F. Van Loan, *Matrix Computations*, > Baltimore, MD, Johns Hopkins University Press, 1985, pg. 15 > > Examples > -------- > >>> from numpy import linalg as LA > >>> a = np.arange(9) - 4 > >>> a > array([-4, -3, -2, ..., 2, 3, 4]) > >>> b = a.reshape((3, 3)) > >>> b > array([[-4, -3, -2], > [-1, 0, 1], > [ 2, 3, 4]]) > > >>> LA.norm(a) > 7.745966692414834 > >>> LA.norm(b) > 7.745966692414834 > >>> LA.norm(b, 'fro') > 7.745966692414834 > >>> LA.norm(a, np.inf) > 4.0 > >>> LA.norm(b, np.inf) > 9.0 > >>> LA.norm(a, -np.inf) > 0.0 > >>> LA.norm(b, -np.inf) > 2.0 > > >>> LA.norm(a, 1) > 20.0 > >>> LA.norm(b, 1) > 7.0 > >>> LA.norm(a, -1) > -4.6566128774142013e-010 > >>> LA.norm(b, -1) > 6.0 > >>> LA.norm(a, 2) > 7.745966692414834 > >>> LA.norm(b, 2) > 7.3484692283495345 > > >>> LA.norm(a, -2) > 0.0 > >>> LA.norm(b, -2) > 1.8570331885190563e-016 # may vary > >>> LA.norm(a, 3) > 5.8480354764257312 # may vary > >>> LA.norm(a, -3) > 0.0 > > Using the `axis` argument to compute vector norms: > > >>> c = np.array([[ 1, 2, 3], > ... [-1, 1, 4]]) > >>> LA.norm(c, axis=0) > array([ 1.41421356, 2.23606798, 5. ]) > >>> LA.norm(c, axis=1) > array([ 3.74165739, 4.24264069]) > >>> LA.norm(c, ord=1, axis=1) > array([ 6., 6.]) > > Using the `axis` argument to compute matrix norms: > > >>> m = np.arange(8).reshape(2,2,2) > >>> LA.norm(m, axis=(1,2)) > array([ 3.74165739, 11.22497216]) > >>> LA.norm(m[0, :, :]), LA.norm(m[1, :, :]) > (3.7416573867739413, 11.224972160321824) > > """ > x = asarray(x) > > if not issubclass(x.dtype.type, (inexact, object_)): > x = x.astype(float) > > # Immediately handle some default, simple, fast, and common cases. > if axis is None: > ndim = x.ndim > if ((ord is None) or > (ord in ('f', 'fro') and ndim == 2) or > (ord == 2 and ndim == 1)): > > x = x.ravel(order='K') > if isComplexType(x.dtype.type): > sqnorm = dot(x.real, x.real) + dot(x.imag, x.imag) > else: > sqnorm = dot(x, x) > ret = sqrt(sqnorm) > if keepdims: > ret = ret.reshape(ndim*[1]) > return ret > > # Normalize the `axis` argument to a tuple. > nd = x.ndim > if axis is None: > axis = tuple(range(nd)) > elif not isinstance(axis, tuple): > try: > axis = int(axis) > except Exception as e: > raise TypeError("'axis' must be None, an integer or a tuple of integers") from e > axis = (axis,) > > if len(axis) == 1: > if ord == Inf: > return abs(x).max(axis=axis, keepdims=keepdims) > elif ord == -Inf: > return abs(x).min(axis=axis, keepdims=keepdims) > elif ord == 0: > # Zero norm > return (x != 0).astype(x.real.dtype).sum(axis=axis, keepdims=keepdims) > elif ord == 1: > # special case for speedup > return add.reduce(abs(x), axis=axis, keepdims=keepdims) > elif ord is None or ord == 2: > # special case for speedup > s = (x.conj() * x).real > return sqrt(add.reduce(s, axis=axis, keepdims=keepdims)) > # None of the str-type keywords for ord ('fro', 'nuc') > # are valid for vectors > elif isinstance(ord, str): > raise ValueError(f"Invalid norm order '{ord}' for vectors") > else: > absx = abs(x) >> absx **= ord >E RuntimeWarning: invalid value encountered in reciprocal > >absx = array([ 1., inf, 1.]) >axis = (0,) >keepdims = False >nd = 1 >ndim = 1 >ord = -1 >x = array([1., 0., 1.]) > >/usr/local/lib/python3.8/site-packages/numpy/linalg/linalg.py:2568: RuntimeWarning >___________________________ TestNormInt64.test_axis ____________________________ > >self = <numpy.linalg.tests.test_linalg.TestNormInt64 object at 0xc28827310> > > def test_axis(self): > # Vector norms. > # Compare the use of `axis` with computing the norm of each row > # or column separately. > A = array([[1, 2, 3], [4, 5, 6]], dtype=self.dt) > for order in [None, -1, 0, 1, 2, 3, np.Inf, -np.Inf]: > expected0 = [norm(A[:, k], ord=order) for k in range(A.shape[1])] >> assert_almost_equal(norm(A, ord=order, axis=0), expected0) > >A = array([[1, 2, 3], > [4, 5, 6]]) >expected0 = [0.8, 1.4285714285714286, 2.0] >expected1 = [3.7416573867739413, 8.774964387392123] >order = -1 >self = <numpy.linalg.tests.test_linalg.TestNormInt64 object at 0xc28827310> > >/usr/local/lib/python3.8/site-packages/numpy/linalg/tests/test_linalg.py:1313: >_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ><__array_function__ internals>:5: in norm > ??? > args = (array([[1, 2, 3], > [4, 5, 6]]),) > kwargs = {'axis': 0, 'ord': -1} > relevant_args = (array([[1, 2, 3], > [4, 5, 6]]),) >_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > >x = array([[1., 2., 3.], > [4., 5., 6.]]), ord = -1, axis = (0,) >keepdims = False > > @array_function_dispatch(_norm_dispatcher) > def norm(x, ord=None, axis=None, keepdims=False): > """ > Matrix or vector norm. > > This function is able to return one of eight different matrix norms, > or one of an infinite number of vector norms (described below), depending > on the value of the ``ord`` parameter. > > Parameters > ---------- > x : array_like > Input array. If `axis` is None, `x` must be 1-D or 2-D, unless `ord` > is None. If both `axis` and `ord` are None, the 2-norm of > ``x.ravel`` will be returned. > ord : {non-zero int, inf, -inf, 'fro', 'nuc'}, optional > Order of the norm (see table under ``Notes``). inf means numpy's > `inf` object. The default is None. > axis : {None, int, 2-tuple of ints}, optional. > If `axis` is an integer, it specifies the axis of `x` along which to > compute the vector norms. If `axis` is a 2-tuple, it specifies the > axes that hold 2-D matrices, and the matrix norms of these matrices > are computed. If `axis` is None then either a vector norm (when `x` > is 1-D) or a matrix norm (when `x` is 2-D) is returned. The default > is None. > > .. versionadded:: 1.8.0 > > keepdims : bool, optional > If this is set to True, the axes which are normed over are left in the > result as dimensions with size one. With this option the result will > broadcast correctly against the original `x`. > > .. versionadded:: 1.10.0 > > Returns > ------- > n : float or ndarray > Norm of the matrix or vector(s). > > See Also > -------- > scipy.linalg.norm : Similar function in SciPy. > > Notes > ----- > For values of ``ord < 1``, the result is, strictly speaking, not a > mathematical 'norm', but it may still be useful for various numerical > purposes. > > The following norms can be calculated: > > ===== ============================ ========================== > ord norm for matrices norm for vectors > ===== ============================ ========================== > None Frobenius norm 2-norm > 'fro' Frobenius norm -- > 'nuc' nuclear norm -- > inf max(sum(abs(x), axis=1)) max(abs(x)) > -inf min(sum(abs(x), axis=1)) min(abs(x)) > 0 -- sum(x != 0) > 1 max(sum(abs(x), axis=0)) as below > -1 min(sum(abs(x), axis=0)) as below > 2 2-norm (largest sing. value) as below > -2 smallest singular value as below > other -- sum(abs(x)**ord)**(1./ord) > ===== ============================ ========================== > > The Frobenius norm is given by [1]_: > > :math:`||A||_F = [\\sum_{i,j} abs(a_{i,j})^2]^{1/2}` > > The nuclear norm is the sum of the singular values. > > Both the Frobenius and nuclear norm orders are only defined for > matrices and raise a ValueError when ``x.ndim != 2``. > > References > ---------- > .. [1] G. H. Golub and C. F. Van Loan, *Matrix Computations*, > Baltimore, MD, Johns Hopkins University Press, 1985, pg. 15 > > Examples > -------- > >>> from numpy import linalg as LA > >>> a = np.arange(9) - 4 > >>> a > array([-4, -3, -2, ..., 2, 3, 4]) > >>> b = a.reshape((3, 3)) > >>> b > array([[-4, -3, -2], > [-1, 0, 1], > [ 2, 3, 4]]) > > >>> LA.norm(a) > 7.745966692414834 > >>> LA.norm(b) > 7.745966692414834 > >>> LA.norm(b, 'fro') > 7.745966692414834 > >>> LA.norm(a, np.inf) > 4.0 > >>> LA.norm(b, np.inf) > 9.0 > >>> LA.norm(a, -np.inf) > 0.0 > >>> LA.norm(b, -np.inf) > 2.0 > > >>> LA.norm(a, 1) > 20.0 > >>> LA.norm(b, 1) > 7.0 > >>> LA.norm(a, -1) > -4.6566128774142013e-010 > >>> LA.norm(b, -1) > 6.0 > >>> LA.norm(a, 2) > 7.745966692414834 > >>> LA.norm(b, 2) > 7.3484692283495345 > > >>> LA.norm(a, -2) > 0.0 > >>> LA.norm(b, -2) > 1.8570331885190563e-016 # may vary > >>> LA.norm(a, 3) > 5.8480354764257312 # may vary > >>> LA.norm(a, -3) > 0.0 > > Using the `axis` argument to compute vector norms: > > >>> c = np.array([[ 1, 2, 3], > ... [-1, 1, 4]]) > >>> LA.norm(c, axis=0) > array([ 1.41421356, 2.23606798, 5. ]) > >>> LA.norm(c, axis=1) > array([ 3.74165739, 4.24264069]) > >>> LA.norm(c, ord=1, axis=1) > array([ 6., 6.]) > > Using the `axis` argument to compute matrix norms: > > >>> m = np.arange(8).reshape(2,2,2) > >>> LA.norm(m, axis=(1,2)) > array([ 3.74165739, 11.22497216]) > >>> LA.norm(m[0, :, :]), LA.norm(m[1, :, :]) > (3.7416573867739413, 11.224972160321824) > > """ > x = asarray(x) > > if not issubclass(x.dtype.type, (inexact, object_)): > x = x.astype(float) > > # Immediately handle some default, simple, fast, and common cases. > if axis is None: > ndim = x.ndim > if ((ord is None) or > (ord in ('f', 'fro') and ndim == 2) or > (ord == 2 and ndim == 1)): > > x = x.ravel(order='K') > if isComplexType(x.dtype.type): > sqnorm = dot(x.real, x.real) + dot(x.imag, x.imag) > else: > sqnorm = dot(x, x) > ret = sqrt(sqnorm) > if keepdims: > ret = ret.reshape(ndim*[1]) > return ret > > # Normalize the `axis` argument to a tuple. > nd = x.ndim > if axis is None: > axis = tuple(range(nd)) > elif not isinstance(axis, tuple): > try: > axis = int(axis) > except Exception as e: > raise TypeError("'axis' must be None, an integer or a tuple of integers") from e > axis = (axis,) > > if len(axis) == 1: > if ord == Inf: > return abs(x).max(axis=axis, keepdims=keepdims) > elif ord == -Inf: > return abs(x).min(axis=axis, keepdims=keepdims) > elif ord == 0: > # Zero norm > return (x != 0).astype(x.real.dtype).sum(axis=axis, keepdims=keepdims) > elif ord == 1: > # special case for speedup > return add.reduce(abs(x), axis=axis, keepdims=keepdims) > elif ord is None or ord == 2: > # special case for speedup > s = (x.conj() * x).real > return sqrt(add.reduce(s, axis=axis, keepdims=keepdims)) > # None of the str-type keywords for ord ('fro', 'nuc') > # are valid for vectors > elif isinstance(ord, str): > raise ValueError(f"Invalid norm order '{ord}' for vectors") > else: > absx = abs(x) > absx **= ord > ret = add.reduce(absx, axis=axis, keepdims=keepdims) >> ret **= (1 / ord) >E RuntimeWarning: invalid value encountered in reciprocal > >absx = array([[1. , 0.5 , 0.33333333], > [0.25 , 0.2 , 0.16666667]]) >axis = (0,) >keepdims = False >nd = 2 >ord = -1 >ret = array([0.8 , 1.42857143, 2. ]) >x = array([[1., 2., 3.], > [4., 5., 6.]]) > >/usr/local/lib/python3.8/site-packages/numpy/linalg/linalg.py:2570: RuntimeWarning >=============================== warnings summary =============================== >../../../../../../../local/lib/python3.8/site-packages/nose/importer.py:12 > /usr/local/lib/python3.8/site-packages/nose/importer.py:12: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses > from imp import find_module, load_module, acquire_lock, release_lock > >-- Docs: https://docs.pytest.org/en/stable/warnings.html >=========================== short test summary info ============================ >FAILED ../../core/tests/test_cpu_dispatcher.py::test_dispatcher - AssertionEr... >FAILED ../../core/tests/test_multiarray.py::test_npymath_complex[complex64-inf-inf-npy_cabs-absolute] >FAILED ../../core/tests/test_multiarray.py::test_npymath_complex[complex64-inf--inf-npy_cabs-absolute] >FAILED ../../core/tests/test_multiarray.py::test_npymath_complex[complex64--inf-inf-npy_cabs-absolute] >FAILED ../../core/tests/test_multiarray.py::test_npymath_complex[complex64--inf--inf-npy_cabs-absolute] >FAILED ../../core/tests/test_multiarray.py::test_npymath_complex[complex128-inf-inf-npy_cabs-absolute] >FAILED ../../core/tests/test_multiarray.py::test_npymath_complex[complex128-inf--inf-npy_cabs-absolute] >FAILED ../../core/tests/test_multiarray.py::test_npymath_complex[complex128--inf-inf-npy_cabs-absolute] >FAILED ../../core/tests/test_multiarray.py::test_npymath_complex[complex128--inf--inf-npy_cabs-absolute] >FAILED ../../core/tests/test_multiarray.py::test_npymath_complex[complex256-inf-inf-npy_cabs-absolute] >FAILED ../../core/tests/test_multiarray.py::test_npymath_complex[complex256-inf--inf-npy_cabs-absolute] >FAILED ../../core/tests/test_multiarray.py::test_npymath_complex[complex256--inf-inf-npy_cabs-absolute] >FAILED ../../core/tests/test_multiarray.py::test_npymath_complex[complex256--inf--inf-npy_cabs-absolute] >FAILED ../../core/tests/test_scalarmath.py::TestBaseMath::test_blocked - Runt... >FAILED ../../core/tests/test_ufunc.py::TestUfuncGenericLoops::test_unary_PyUFunc_O_O_method_full[reciprocal] >FAILED ../../core/tests/test_umath.py::TestPower::test_power_float - RuntimeW... >FAILED ../../core/tests/test_umath.py::TestAVXUfuncs::test_avx_based_ufunc - ... >FAILED ../../core/tests/test_umath_complex.py::TestSpecialComplexAVX::test_array[complex64--1] >FAILED ../../core/tests/test_umath_complex.py::TestSpecialComplexAVX::test_array[complex64-1] >FAILED ../../core/tests/test_umath_complex.py::TestSpecialComplexAVX::test_array[complex128--1] >FAILED ../../core/tests/test_umath_complex.py::TestSpecialComplexAVX::test_array[complex128-1] >FAILED ../../linalg/tests/test_linalg.py::TestNormDouble::test_vector_return_type >FAILED ../../linalg/tests/test_linalg.py::TestNormDouble::test_axis - Runtime... >FAILED ../../linalg/tests/test_linalg.py::TestNormSingle::test_vector_return_type >FAILED ../../linalg/tests/test_linalg.py::TestNormInt64::test_vector_return_type >FAILED ../../linalg/tests/test_linalg.py::TestNormInt64::test_axis - RuntimeW... >26 failed, 14705 passed, 880 skipped, 1253 deselected, 19 xfailed, 3 xpassed, 1 warning in 304.34s (0:05:04)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 259637
:
229258
|
229285
|
229286
|
230615
|
232098
|
232104
|
233138