PyTorch torch.adjoint Function


Pytorch torch 参考手册PyTorch torch Reference Manual

torch.adjointIt is a function in PyTorch used to compute the conjugate transpose (adjoint) of a matrix. For real matrices, it is equivalent to transpose; for complex matrices, it returns the transpose and takes the conjugate of each element.

Function Definition

torch.adjoint(input)

Parameters:

  • input(Tensor): Input tensor.

Return Value:

  • torch.Tensor: Returns the conjugate transpose of the input tensor.

Usage Example

Example - Real Matrix

import torch

# Create a real matrix
A = torch.tensor([[1, 2, 3], [4, 5, 6]])

# Compute the conjugate transpose
result = torch.adjoint(A)

print("Original matrix:")
print(A)
print("Shape:", A.shape)
print("Conjugate transpose:")
print(result)
print("Shape:", result.shape)

The output result is:

原矩阵:
tensor([[1, 2, 3],
        [4, 5, 6]])
形状: torch.Size([2, 3])
共轭转置:
tensor([[1, 4],
        [2, 5],
        [3, 6]])
形状: torch.Size([3, 2])

Example - Complex Matrix

import torch

# Create a complex matrix
A = torch.tensor([[1+1j, 2+2j], [3+3j, 4+4j]])

# Compute the conjugate transpose
result = torch.adjoint(A)

print("Original matrix:")
print(A)
print("Conjugate transpose:")
print(result)

Pytorch torch 参考手册PyTorch torch Reference Manual

Other Extensions