<p dir="auto">If you add <code class="notranslate">inf, -inf</code> into the list <a href="https://github.com/pytorch/pytorch/blob/master/test/test_torch.py#L9274">https://github.com/pytorch/pytorch/blob/master/test/test_torch.py#L9274</a> it'll fail the test.</p>
<p dir="auto">So from numpy doc, <code class="notranslate">inf</code> norm is defined as <code class="notranslate">max(sum(abs(x), axis=1))</code> for matrix and <code class="notranslate">max(abs(x))</code> for vector, but it seems we always implemented <code class="notranslate">max(abs(x))</code>.</p>
<p dir="auto">short repro:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [1]: import torch

In [2]: import numpy as np

In [3]: a = torch.rand(3, 3)

In [4]: b = a.numpy()

In [5]: import math

In [6]: torch.norm(a, math.inf)
Out[6]: tensor(0.7553)

In [7]: np.linalg.norm(b, math.inf)
Out[7]: 1.4294269"><pre class="notranslate"><code class="notranslate">In [1]: import torch

In [2]: import numpy as np

In [3]: a = torch.rand(3, 3)

In [4]: b = a.numpy()

In [5]: import math

In [6]: torch.norm(a, math.inf)
Out[6]: tensor(0.7553)

In [7]: np.linalg.norm(b, math.inf)
Out[7]: 1.4294269
</code></pre></div>
<p dir="auto"><code class="notranslate">torch.norm</code> currently have the following inconsistent behavior where for matrix inputs and <code class="notranslate">ord</code> is a numerical value, <strong>vector</strong> norm is computed instead:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="            =====  ============================  ==========================
            ord    matrix norm                   vector norm
            =====  ============================  ==========================
            None   Frobenius norm                2-norm
            'fro'  Frobenius norm                --
            'nuc'  nuclear norm                  --
            Other  as vec norm when dim is None  sum(abs(x)**ord)**(1./ord)
            =====  ============================  =========================="><pre class="notranslate"><code class="notranslate">            =====  ============================  ==========================
            ord    matrix norm                   vector norm
            =====  ============================  ==========================
            None   Frobenius norm                2-norm
            'fro'  Frobenius norm                --
            'nuc'  nuclear norm                  --
            Other  as vec norm when dim is None  sum(abs(x)**ord)**(1./ord)
            =====  ============================  ==========================
</code></pre></div>
<p dir="auto">(Even though the last row reads <code class="notranslate">when dim is None</code>, same behavior happens when <code class="notranslate">dim</code> is a 2-tuple).</p>
<p dir="auto">However, the matrix Lpq norms are useful. And users are justified in expecting that <code class="notranslate">mat.norm(2)</code> computes the L2 norm (max e-value) since <code class="notranslate">mat.norm('fro')</code> computes the matrix Frobenius norm. If we follow the <a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.norm.html" rel="nofollow">NumPy interface</a>, the following behavior should be less surprising and error prune:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="
    =====  ============================  ==========================
    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)
    =====  ============================  =========================="><pre class="notranslate"><code class="notranslate">
    =====  ============================  ==========================
    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)
    =====  ============================  ==========================
</code></pre></div>
<p dir="auto">cc <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/ezyang/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/ezyang">@ezyang</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/gchanan/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/gchanan">@gchanan</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/zou3519/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/zou3519">@zou3519</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/ssnl/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/ssnl">@ssnl</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/vishwakftw/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/vishwakftw">@vishwakftw</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/jianyuh/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/jianyuh">@jianyuh</a></p>