
PyTorch에서는 Tensor type이 Variable과 Constant를 포함합니다.
기존에는 Variable 타입이 있었지만, 이는 자동미분을 위한 것이었는데, 이 기능을 Tensor 타입에 포함 시켰습니다.






tensor_var.type() -> inplace 명령이 아님

GPU 를 사용하기 위해 Cuda에서 사용하는 데이터타입으로 바꾸어줘야 한다.
방법 세가지!

대부분 그냥 이렇게 사용합니다!

torch.add: 덧셈torch.sub: 뺄셈torch.mul: 곱셈torch.div: 나눗셈torch.pow: n 제곱torch.nagetive: 음수 부호
torch.abs: 절대값torch.sign: 부호torch.round: 반올림torch.ceil: 올림torch.floor: 내림torch.square: 제곱torch.sqrt: 제곱근torch.maximum: 두 텐서의 각 원소에서 최댓값만 반환.torch.minimum: 두 텐서의 각 원소에서 최솟값만 반환.torch.cumsum: 누적합torch.cumprod: 누적곱
PyTorch는 기본이 reduce 연산


torch.reshape.viewtorch.transposetorch.view(a, (4, -1)) 이렇게 못씀

expand_dims 함수 대신에 unsqueeze 함수가 있다.


_를 붙이면 inplace명령이 된다.(안되는 함수가 존재함)
RuntimeError: view size is not compatible with input tensor's size and stride (at least one dimension spans across two contiguous subspaces). Use .reshape(...) instead.
이는 PyTorch가 데이터를 메모리에 저장하는 방식과 view, reshape, transpose 연산들이 연산을 수행하는 방식의 차이에 기인한다.
메모리상의 데이터의 물리적 위치와 index가 일치 할 때 contiguous 하다고 표현하는데, view는 contiguous해야만 연산을 수행할 수 있다.
이를 해결하기위해 tensor.contiguous() 함수를 호출하여 데이터를 정리해주면 된다.




