From fd6f377b779d1c8d3c7de2ff06a9a4038d75c2ba Mon Sep 17 00:00:00 2001 From: Vijay Janapa Reddi Date: Tue, 30 Sep 2025 12:36:00 -0400 Subject: [PATCH] Update activation examples to use PyTorch-style callable API Updated docstring examples to use cleaner callable syntax: - sigmoid(x) instead of sigmoid.forward(x) - relu(x) instead of relu.forward(x) - tanh(x) instead of tanh.forward(x) - gelu(x) instead of gelu.forward(x) - softmax(x) instead of softmax.forward(x) This demonstrates the proper usage pattern with the __call__ methods we just added, making examples more Pythonic and PyTorch-compatible. --- modules/source/02_activations/activations_dev.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/source/02_activations/activations_dev.py b/modules/source/02_activations/activations_dev.py index 50352c24..edadfae7 100644 --- a/modules/source/02_activations/activations_dev.py +++ b/modules/source/02_activations/activations_dev.py @@ -215,7 +215,7 @@ class Sigmoid: EXAMPLE: >>> sigmoid = Sigmoid() >>> x = Tensor([-2, 0, 2]) - >>> result = sigmoid.forward(x) + >>> result = sigmoid(x) >>> print(result.data) [0.119, 0.5, 0.881] # All values between 0 and 1 @@ -330,7 +330,7 @@ class ReLU: EXAMPLE: >>> relu = ReLU() >>> x = Tensor([-2, -1, 0, 1, 2]) - >>> result = relu.forward(x) + >>> result = relu(x) >>> print(result.data) [0, 0, 0, 1, 2] # Negative values become 0, positive unchanged @@ -448,7 +448,7 @@ class Tanh: EXAMPLE: >>> tanh = Tanh() >>> x = Tensor([-2, 0, 2]) - >>> result = tanh.forward(x) + >>> result = tanh(x) >>> print(result.data) [-0.964, 0.0, 0.964] # Range (-1, 1), symmetric around 0 @@ -573,7 +573,7 @@ class GELU: EXAMPLE: >>> gelu = GELU() >>> x = Tensor([-1, 0, 1]) - >>> result = gelu.forward(x) + >>> result = gelu(x) >>> print(result.data) [-0.159, 0.0, 0.841] # Smooth, like ReLU but differentiable everywhere @@ -697,7 +697,7 @@ class Softmax: EXAMPLE: >>> softmax = Softmax() >>> x = Tensor([1, 2, 3]) - >>> result = softmax.forward(x) + >>> result = softmax(x) >>> print(result.data) [0.090, 0.245, 0.665] # Sums to 1.0, larger inputs get higher probability @@ -862,7 +862,7 @@ def test_module(): softmax = Softmax() # Test different dimensions - result_last = softmax.forward(data_3d, dim=-1) + result_last = softmax(data_3d, dim=-1) assert result_last.shape == (2, 2, 3), "Softmax should preserve shape" # Check that last dimension sums to 1