Функция PyTorch torch.can_cast
Справочное руководство Pytorch torch
torch.can_castЭто функция в PyTorch, используемая для проверки возможности выполнения преобразования типов. Она проверяет, возможно ли преобразование из исходного типа данных в целевой тип данных.
Определение функции
torch.can_cast(from_dtype, to_dtype)
Пример использования
Пример
import torch
# Проверить, можно ли выполнить преобразование типа
print(torch.can_cast(torch.float32, torch.int32)) # True
print(torch.can_cast(torch.float64, torch.int8)) # True
print(torch.can_cast(torch.int64, torch.bool)) # True
# Преобразовать из bool
print(torch.can_cast(torch.bool, torch.float32)) # True
# Проверить, можно ли выполнить преобразование типа
print(torch.can_cast(torch.float32, torch.int32)) # True
print(torch.can_cast(torch.float64, torch.int8)) # True
print(torch.can_cast(torch.int64, torch.bool)) # True
# Преобразовать из bool
print(torch.can_cast(torch.bool, torch.float32)) # True
Другие расширения