chapter 3 - It Starts with a Tensor

Oct 20, 2023

Types of operations

Storage

In [23]: p = torch.tensor([[4,1],[5,3],[2,1.0]])
    ...: p_t = p.t()
    ...: p_t, p_t.storage(), p_t.stride(), p_t.is_contiguous()

Out[23]: (tensor([[4., 5., 2.],
         [1., 3., 1.]]),
          4.0
          1.0
          5.0
          3.0
          2.0
          1.0
         [torch.storage.TypedStorage(dtype=torch.float32, device=cpu) of size 6],
         (1, 2),
         False)


In [24]: p_t_c = p_t.contiguous()
    ...: p_t_c, p_t_c.storage(), p_t_c.stride()

Out[24]: (tensor([[4., 5., 2.],
         [1., 3., 1.]]),
          4.0
          5.0
          2.0
          1.0
          3.0
          1.0
         [torch.storage.TypedStorage(dtype=torch.float32, device=cpu) of size 6],
         (3, 1))

Moving tensors to the GPU

Numpy compatibility

serializing tensors

exercises

notebook

↑ up