Files
tinygrad/test/test_lazyop.py
George Hotz 150ea2eb76 create engine folder and move code (#3948)
* retry

* older tf

* that
2024-03-26 20:38:03 -07:00

35 lines
1.1 KiB
Python

import unittest
from tinygrad.tensor import Tensor
from tinygrad.engine.realize import create_schedule
# stuff needed to unpack a kernel
# ruff: noqa: F401
from tinygrad.ops import LazyOp, TernaryOps, BinaryOps, UnaryOps, ReduceOps, BufferOps, MemBuffer, ConstBuffer
from tinygrad.lazy import LazyBuffer
from tinygrad import dtypes
from tinygrad.shape.shapetracker import ShapeTracker
from tinygrad.shape.view import View
from tinygrad.shape.symbolic import Variable
import numpy as np
import time
inf, nan = float('inf'), float('nan')
class TestLazyOp(unittest.TestCase):
def test_lazyop_str(self):
t = Tensor.rand(10) + Tensor.rand(10)
s = create_schedule([t.lazydata])
ast = s[-1].ast
ast_remade = eval(str(ast))
self.assertEqual(ast, ast_remade)
def test_selfreferential_speed(self):
st = time.monotonic()
for i in range(25):
p = Tensor([1]).lazydata
for _ in range(i): p = p.e(BinaryOps.ADD, p)
# sanity check if caching works this should be way faster
assert time.monotonic() -st < 0.5, f"{i}"
if __name__ == '__main__':
unittest.main()