类型信息
可以通过 torch.finfo 或 torch.iinfo 访问 torch.dtype 的数值属性。
torch
class torch.finfo¶
torch.finfo 是表示浮点 torch.dtype (即torch.float32,torch.float64和torch.float16)的数值属性的对象。 这类似于 numpy.finfo 。
torch.finfo 提供以下属性:
|
名称
|
类型
|
描述
|
| --- | --- | --- |
| 位 | 整型 | 类型占用的位数。 |
| eps | 浮动 | 最小可表示数字,例如1.0 + eps != 1.0。 |
| 最大值 | float | 可表示的最大数字。 |
| 分 | float | 最小的可表示数字(通常为-max)。 |
| 小 | float | 可表示的最小正数。 |
注意
可以不带参数地调用 torch.finfo 的构造函数,在这种情况下,将为 pytorch 默认 dtype 创建类(由 torch.get_default_dtype() 返回)。
torch
class torch.iinfo¶
torch.iinfo 是代表整数 torch.dtype (即torch.uint8,torch.int8,torch.int16,torch.int32和torch.int64)。 这类似于 numpy.iinfo 。
torch.iinfo 提供以下属性:
|
Name
|
Type
|
Description
| | --- | --- | --- | | bits | int | The number of bits occupied by the type. | | max | int | The largest representable number. | | min | int | 可表示的最小数字。 |
