PyTorch torch.ldexp function
PyTorch torch reference manual
torch.ldexp is a function in PyTorch used to multiply the mantissa by 2 raised to the power of the exponent; it is the inverse operation of frexp.
Function definition
torch.ldexp(input, other, out=None)
Usage examples
Example
import
torch
Decompose using frexp
x
=
torch.
tensor
(
[
8.0
,
4.5
,
2.0
]
)
mantissa
,
exponent
=
torch.
frexp
(
x
)
Reconstruct using ldexp
reconstructed
=
torch.
ldexp
(
mantissa
,
exponent
)
(
"Reconstructed values:"
,
reconstructed
)
The output is:
重建值: tensor([8., 4.5, 2.])