From 3f39c183f04cfe90975ea2214f4ea655c67182ff Mon Sep 17 00:00:00 2001 From: Javier Vargas Date: Sat, 23 Oct 2021 16:14:33 +0200 Subject: [PATCH] Added modules --- experiment1/modules.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 experiment1/modules.py diff --git a/experiment1/modules.py b/experiment1/modules.py new file mode 100644 index 0000000..8ff38ec --- /dev/null +++ b/experiment1/modules.py @@ -0,0 +1,30 @@ +import torch as T + + +class Adder(object): + def __init__(self) -> None: + """Init adder module""" + super().__init__() + + def __call__(self, X: T.Tensor) -> T.Tensor: + """Calling the adding operation without gradient""" + with T.no_grad(): + return X[0] + X[1] + + +class Substracter(object): + def __init__(self) -> None: + """Init substracter module""" + super().__init__() + + def __call__(self, X: T.Tensor) -> T.Tensor: + """Calling the adding operation without gradient""" + with T.no_grad(): + return X[0] - X[1] + + +if __name__ == "__main__": + adder = Adder() + x = T.rand(2) + y = adder(x) + print(x,y) \ No newline at end of file