Skip to content

Extra whitespace issue when printing complex tensors #36279

@choidongyeon

Description

@choidongyeon

Printing complex tensors yields extra white spaces that follow the element. This seems to be related to the way that self.max_width is set in the Formatter constructor.

This is a follow up to the conversation that can be found here: #35841

To Reproduce

print(torch.tensor([[1 + 1.340j, 3 + 4j], [1.2 + 1.340j, 6.5 + 7j]], dtype=torch.complex64))

Will yield

tensor([[                     (1.0000 + 1.3400j),
                              (3.0000 + 4.0000j)],
        [                     (1.2000 + 1.3400j),
                              (6.5000 + 7.0000j)]], dtype=torch.complex64)

Expected behavior

Instead, we want it to look like

tensor([[(1.0000 + 1.3400j),
         (3.0000 + 4.0000j)],
        [(1.2000 + 1.3400j),
         (6.5000 + 7.0000j)]], dtype=torch.complex64) 

cc @ezyang @anjali411 @dylanbespalko

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: complexRelated to complex number support in PyTorchtriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions