From 43591a1e71abfbdb4ce688dcb4757e8526a18010 Mon Sep 17 00:00:00 2001 From: George Hotz Date: Mon, 26 Oct 2020 09:19:20 -0700 Subject: [PATCH] make the example simpler --- README.md | 5 ++--- setup.py | 2 +- tinygrad/tensor.py | 6 ++++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6a0f0acb09..722f33a476 100644 --- a/README.md +++ b/README.md @@ -15,11 +15,10 @@ The Tensor class is a wrapper around a numpy array, except it does Tensor things ### Example ```python -import numpy as np from tinygrad.tensor import Tensor -x = Tensor(np.eye(3)) -y = Tensor(np.array([[2.0,0,-2.0]])) +x = Tensor.eye(3) +y = Tensor([[2.0,0,-2.0]]) z = y.dot(x).sum() z.backward() diff --git a/setup.py b/setup.py index ce53a01c03..7fff335f7f 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ with open(os.path.join(directory, 'README.md'), encoding='utf-8') as f: long_description = f.read() setup(name='tinygrad', - version='0.1.0', + version='0.2.0', description='You like pytorch? You like micrograd? You love tinygrad! heart', author='George Hotz', license='MIT', diff --git a/tinygrad/tensor.py b/tinygrad/tensor.py index f61f3db286..5e0e192d62 100644 --- a/tinygrad/tensor.py +++ b/tinygrad/tensor.py @@ -8,6 +8,8 @@ import numpy as np class Tensor: def __init__(self, data): #print(type(data), data) + if type(data) == list: + data = np.array(data, dtype=np.float32) if type(data) != np.ndarray: print("error constructing tensor with %r" % data) assert(False) @@ -35,6 +37,10 @@ class Tensor: def randn(*shape): return Tensor(np.random.randn(*shape).astype(np.float32)) + @staticmethod + def eye(dim): + return Tensor(np.eye(dim).astype(np.float32)) + def backward(self, allow_fill=True): #print("running backward on", self) if self._ctx is None: