Last active
March 15, 2022 03:36
-
-
Save zetyquickly/730fd23e37ff7d06cdc9654b62d2974c to your computer and use it in GitHub Desktop.
Revisions
-
zetyquickly revised this gist
Mar 15, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,4 +19,4 @@ def test_view(tensor, sizes): # Apply view-function that change contiguity and try again perm_tens_A = tens_A.permute(0,2,1) # change order of axis test_view(perm_tens_A, sizes) # this will result in RuntimeError("Use .reshape(...) instead") -
zetyquickly revised this gist
Mar 15, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,4 +19,4 @@ def test_view(tensor, sizes): # Apply view-function that change contiguity and try again perm_tens_A = tens_A.permute(0,2,1) # change order of axis test_view(perm_tens_A, sizes) # this will result in RuntimeError -
zetyquickly created this gist
Mar 15, 2022 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ import torch # Tensor of interest tens_A = torch.rand((2,3,4)) # 3-dimensional tensor of shape (2,3,4) def test_view(tensor, sizes): try: tensor.view(*sizes) except Exception as e: print(e) print(f"View was Failed: tensor.is_contiguos == {tensor.is_contiguous()}") else: print(f"View was Successful: tensor.is_contiguos == {tensor.is_contiguous()}") sizes = (3,4,2) # Let's try to use view test_view(tens_A, sizes) # Apply view-function that change contiguity and try again perm_tens_A = tens_A.permute(0,2,1) # change order of axis test_view(perm_tens_A, sizes)