목록PyTorch Reference API/torch (3)
찬호의 Too Much Intelligence
torch.is_complex(input: Tensor) -> boolReturn True if the data type of input is a complex data type i.e., one of torch.complex64, and torch.complex128. import torcht = torch.tensor([1,2,3], dtype=torch.complex64) # Trueprint(torch.is_complex(t))t = torch.tensor([1,2,3], dtype=torch.int32) # False print(torch.is_complex(t)) ❓torch.complex64, torch.complex128?PyTorch에서 복소수(complex number)를 다루..
torch.is_storage(obj, /)Returns True if obj is a PyTorch storage object. import torcht = torch.tensor([1, 2, 3, 4])s = t.storage()print(torch.is_storage(t)) # Falseprint(torch.is_storage(s)) # True ❓PyTorch에서 storage란?Pytorch storage object는 Tensor가 실제 데이터를 저장하는 low-level 메모리 버퍼 객체를 말한다. Pytorch의 Tensor는 데이터를 담는 컨테이너이다.그런데, Tensor 자체가 데이터를 바로 들고 있는 건 아니고, storage라는 하위 객체를 참조한다.Tensor ├─ shape (..
torch.is_tensor(obj, /)Returns True if obj is a PyTorch tensor.내부에서 isinstance(obj, Tensor)를 수행하므로, is_tensor보다 isinstance를 사용하는게 mypy의 type checking 측면에서 더 명확하고 낫다.따라서 is_tensor보다 isinstance를 사용하자.x = torch.tensor([1,2,3])print(torch.is_tensor(x)) # True# better to use isinstanceprint(isinstance(x, torch.Tensor)) # True