Skip to content

Setting a complex tensor to linalg.norm() returns a float tensor #136452

Description

@hyperkai

🐛 Describe the bug

Setting an int tensor to linalg.norm() gets the error message as shown below:

import torch
from torch import linalg

my_tensor = torch.tensor([8, -3, 0, 1])

linalg.norm(input=my_tensor) # Error

RuntimeError: linalg.vector_norm: Expected a floating point or complex tensor as input. Got Long

But, setting a complex tensor to linalg.norm() returns a float tensor as shown below:

import torch
from torch import linalg

my_tensor = torch.tensor([8.+0.j, -3.+0.j, 0.+0.j, 1.+0.j])

linalg.norm(input=my_tensor)
# tensor(8.6023)

linalg.norm(input=my_tensor).dtype
# torch.float32

So, I set dtype=torch.complex64 to linalg.norm() but it still returns a float tensor as shown below:

import torch
from torch import linalg

my_tensor = torch.tensor([8.+0.j, -3.+0.j, 0.+0.j, 1.+0.j])
                           # ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
linalg.norm(input=my_tensor, dtype=torch.complex64)
# tensor(8.6023)

linalg.norm(input=my_tensor, dtype=torch.complex64).dtype
# torch.float32

Versions

import torch

torch.__version__ # '2.3.0'

cc @svekars @sekyondaMeta @AlannaBurke @ezyang @anjali411 @dylanbespalko @mruberry @nikitaved @amjames @jianyuh @walterddr @lezcano @pearu @xwang233

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: complexRelated to complex number support in PyTorchmodule: docsRelated to our documentation, both in docs/ and docblocksmodule: linear algebraIssues related to specialized linear algebra operations in PyTorch; includes matrix multiply matmultriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions