mirror of
https://github.com/tinygrad/tinygrad.git
synced 2026-01-09 15:08:02 -05:00
make the example simpler
This commit is contained in:
@@ -15,11 +15,10 @@ The Tensor class is a wrapper around a numpy array, except it does Tensor things
|
|||||||
### Example
|
### Example
|
||||||
|
|
||||||
```python
|
```python
|
||||||
import numpy as np
|
|
||||||
from tinygrad.tensor import Tensor
|
from tinygrad.tensor import Tensor
|
||||||
|
|
||||||
x = Tensor(np.eye(3))
|
x = Tensor.eye(3)
|
||||||
y = Tensor(np.array([[2.0,0,-2.0]]))
|
y = Tensor([[2.0,0,-2.0]])
|
||||||
z = y.dot(x).sum()
|
z = y.dot(x).sum()
|
||||||
z.backward()
|
z.backward()
|
||||||
|
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -8,7 +8,7 @@ with open(os.path.join(directory, 'README.md'), encoding='utf-8') as f:
|
|||||||
long_description = f.read()
|
long_description = f.read()
|
||||||
|
|
||||||
setup(name='tinygrad',
|
setup(name='tinygrad',
|
||||||
version='0.1.0',
|
version='0.2.0',
|
||||||
description='You like pytorch? You like micrograd? You love tinygrad! heart',
|
description='You like pytorch? You like micrograd? You love tinygrad! heart',
|
||||||
author='George Hotz',
|
author='George Hotz',
|
||||||
license='MIT',
|
license='MIT',
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import numpy as np
|
|||||||
class Tensor:
|
class Tensor:
|
||||||
def __init__(self, data):
|
def __init__(self, data):
|
||||||
#print(type(data), data)
|
#print(type(data), data)
|
||||||
|
if type(data) == list:
|
||||||
|
data = np.array(data, dtype=np.float32)
|
||||||
if type(data) != np.ndarray:
|
if type(data) != np.ndarray:
|
||||||
print("error constructing tensor with %r" % data)
|
print("error constructing tensor with %r" % data)
|
||||||
assert(False)
|
assert(False)
|
||||||
@@ -35,6 +37,10 @@ class Tensor:
|
|||||||
def randn(*shape):
|
def randn(*shape):
|
||||||
return Tensor(np.random.randn(*shape).astype(np.float32))
|
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):
|
def backward(self, allow_fill=True):
|
||||||
#print("running backward on", self)
|
#print("running backward on", self)
|
||||||
if self._ctx is None:
|
if self._ctx is None:
|
||||||
|
|||||||
Reference in New Issue
Block a user