From d6656b139ae4607818152dd1046a06110b2c6734 Mon Sep 17 00:00:00 2001 From: ItayHadas <5610394+ItayHadas@users.noreply.github.com> Date: Fri, 24 Feb 2023 11:07:28 -0800 Subject: [PATCH 1/3] blitz --- PyTorch_Blitz.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 PyTorch_Blitz.py diff --git a/PyTorch_Blitz.py b/PyTorch_Blitz.py new file mode 100644 index 00000000..1487c209 --- /dev/null +++ b/PyTorch_Blitz.py @@ -0,0 +1,62 @@ +import torch +import numpy as np + +data = [[1, 2], [3, 4]] +x_data = torch.tensor(data) + +np_array = np.array(data) +x_np = torch.from_numpy(np_array) + +x_ones = torch.ones_like(x_data) # retains the properties of x_data +print(f"Ones Tensor: \n {x_ones} \n") + +x_rand = torch.rand_like(x_data, dtype=torch.float) # overrides the datatype of x_data +print(f"Random Tensor: \n {x_rand} \n") + +shape = (2, 3,) +rand_tensor = torch.rand(shape) +ones_tensor = torch.ones(shape) +zeros_tensor = torch.zeros(shape) + +print(f"Random Tensor: \n {rand_tensor} \n") +print(f"Ones Tensor: \n {ones_tensor} \n") +print(f"Zeros Tensor: \n {zeros_tensor}") + +tensor = torch.rand(3, 4) + +print(f"Shape of tensor: {tensor.shape}") +print(f"Datatype of tensor: {tensor.dtype}") +print(f"Device tensor is stored on: {tensor.device}") + +if torch.cuda.is_available(): + tensor = tensor.to('cuda') + print(f"Device tensor is stored on: {tensor.device}") + +tensor = torch.ones(4, 4) +tensor[:,1] = 0 +print(tensor) + +tensor = torch.ones(4, 4) +tensor[:,1] = 0 +print(tensor) + +t1 = torch.cat([tensor, tensor, tensor], dim=1) +print(t1) + +# This computes the element-wise product +print(f"tensor.mul(tensor) \n {tensor.mul(tensor)} \n") +# Alternative syntax: +print(f"tensor * tensor \n {tensor * tensor}") + +print(f"tensor.matmul(tensor.T) \n {tensor.matmul(tensor.T)} \n") +# Alternative syntax: +print(f"tensor @ tensor.T \n {tensor @ tensor.T}") + +print(tensor, "\n") +tensor.add_(5) +print(tensor) + +t = torch.ones(5) +print(f"t: {t}") +n = t.numpy() +print(f"n: {n}") \ No newline at end of file From 4c32d04850549792a73ee22766fcaee3f8aa94c0 Mon Sep 17 00:00:00 2001 From: ItayHadas <5610394+ItayHadas@users.noreply.github.com> Date: Fri, 24 Feb 2023 11:33:57 -0800 Subject: [PATCH 2/3] ubuntu_blitz --- PyTorch_Ubuntu_Blitz.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 PyTorch_Ubuntu_Blitz.py diff --git a/PyTorch_Ubuntu_Blitz.py b/PyTorch_Ubuntu_Blitz.py new file mode 100644 index 00000000..ad5b1aba --- /dev/null +++ b/PyTorch_Ubuntu_Blitz.py @@ -0,0 +1,40 @@ +import torch +import numpy as np + +data = [[1, 2], [3, 4]] +x_data = torch.tensor(data) + +np_array = np.array(data) +x_np = torch.from_numpy(np_array) + +x_ones = torch.ones_like(x_data) # retains the properties of x_data +print(f"Ones Tensor: \n {x_ones} \n") + +x_rand = torch.rand_like(x_data, dtype=torch.float) # overrides the datatype of x_data +print(f"Random Tensor: \n {x_rand} \n") + +shape = (2, 3,) +rand_tensor = torch.rand(shape) +ones_tensor = torch.ones(shape) +zeros_tensor = torch.zeros(shape) + +print(f"Random Tensor: \n {rand_tensor} \n") +print(f"Ones Tensor: \n {ones_tensor} \n") +print(f"Zeros Tensor: \n {zeros_tensor}") + +tensor = torch.rand(3, 4) + +print(f"Shape of tensor: {tensor.shape}") +print(f"Datatype of tensor: {tensor.dtype}") +print(f"Device tensor is stored on: {tensor.device}") + +if torch.cuda.is_available(): + tensor = tensor.to('cuda') + print(f"Device tensor is stored on: {tensor.device}") + +tensor = torch.ones(4, 4) +tensor[:,1] = 0 +print(tensor) + +t1 = torch.cat([tensor, tensor, tensor], dim=1) +print(t1) \ No newline at end of file From 8b42af5fb17a0faef1e6dabc180bebebf8b542d3 Mon Sep 17 00:00:00 2001 From: ItayHadas <5610394+ItayHadas@users.noreply.github.com> Date: Fri, 24 Feb 2023 11:44:52 -0800 Subject: [PATCH 3/3] blitz --- PyTorch_Blitz.py => PyTorch_WSL_Blitz.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename PyTorch_Blitz.py => PyTorch_WSL_Blitz.py (100%) diff --git a/PyTorch_Blitz.py b/PyTorch_WSL_Blitz.py similarity index 100% rename from PyTorch_Blitz.py rename to PyTorch_WSL_Blitz.py