aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaghuram Subramani <raghus2247@gmail.com>2024-05-29 18:11:05 +0530
committerRaghuram Subramani <raghus2247@gmail.com>2024-05-29 18:11:05 +0530
commit22f6c7e5b3fd45480f2ef7827474fdb9d6c6f82c (patch)
tree7d97cc24147ff1d8ffa7e1978a13418514df5c8b
parenta4c99c97b66c6aed0737430aa9bdeb8ec64e3d9f (diff)
Value -> Scalar
-rwxr-xr-xexample.py10
-rw-r--r--src/graph.py6
-rw-r--r--src/scalar.py (renamed from src/value.py)8
3 files changed, 12 insertions, 12 deletions
diff --git a/example.py b/example.py
index 218adc3..84fb9f0 100755
--- a/example.py
+++ b/example.py
@@ -1,12 +1,12 @@
#!/usr/bin/env python
-from src.value import Value
+from src.scalar import Scalar
from src.graph import Graph
-a = Value(2, label='a')
-b = Value(-3, label='b')
-c = Value(10, label='c')
-f = Value(-2, label='f')
+a = Scalar(2, label='a')
+b = Scalar(-3, label='b')
+c = Scalar(10, label='c')
+f = Scalar(-2, label='f')
d = a * b; d.label = 'd'
e = d + c; e.label = 'e'
diff --git a/src/graph.py b/src/graph.py
index 2067071..9aecde1 100644
--- a/src/graph.py
+++ b/src/graph.py
@@ -4,10 +4,10 @@ from graphviz import Digraph
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
-from .value import Value
+from .scalar import Scalar
class Graph:
- def __init__(self, root: Value) -> None:
+ def __init__(self, root: Scalar) -> None:
self.dot = Digraph(format='png', graph_attr={ 'rankdir': 'LR' })
self.nodes = set()
@@ -16,7 +16,7 @@ class Graph:
self.build(root)
self.draw()
- def build(self, x: Value):
+ def build(self, x: Scalar):
self.nodes.add(x)
for child in x._prev:
# Add a line from child to x
diff --git a/src/value.py b/src/scalar.py
index af0ab35..a67b7ae 100644
--- a/src/value.py
+++ b/src/scalar.py
@@ -1,4 +1,4 @@
-class Value:
+class Scalar:
def __init__(self, data, _children=(), _op='', label='') -> None:
self.label = label
@@ -9,12 +9,12 @@ class Value:
self._op = _op
def __repr__(self) -> str:
- return f'Value({self.data})'
+ return f'Scalar({self.data})'
def __add__(self, y):
result = self.data + y.data
- return Value(result, (self, y), _op='+')
+ return Scalar(result, (self, y), _op='+')
def __mul__(self, y):
result = self.data * y.data
- return Value(result, (self, y), _op='*')
+ return Scalar(result, (self, y), _op='*')