mirror of
https://github.com/tinygrad/tinygrad.git
synced 2026-01-22 21:38:10 -05:00
* new version * fix abstractions * try remove test * Revert "try remove test" This reverts commit2fc18a9f8e. * assert_allclose * minimize the test * minimize the test * minimize the test * minimize the test * Revert "minimize the test" This reverts commite0c0929596. * Revert "minimize the test" This reverts commit88240551b1. * Revert "minimize the test" This reverts commit78328a7ce2. * Revert "minimize the test" This reverts commit989523fded. * skip test inside body * oops * oops
24 lines
875 B
Python
24 lines
875 B
Python
import numpy as np
|
|
import unittest
|
|
|
|
from tinygrad.lazy import Device
|
|
from tinygrad.ops import GlobalCounters, Compiled
|
|
from tinygrad.tensor import Tensor
|
|
|
|
class TestLinearizer(unittest.TestCase):
|
|
def test_arg_dedup(self):
|
|
if not isinstance(Device[Device.DEFAULT], Compiled):
|
|
self.skipTest("Only Compiled supports cache")
|
|
a, b = Tensor.randn(4), Tensor.randn(4)
|
|
np_a, np_b = a.numpy(), b.numpy()
|
|
GlobalCounters.cache = []
|
|
c = ((a.shrink(((0, 2),)) - a.shrink(((2, 4),))) - (b.shrink(((0, 2),)) - b.shrink(((2, 4),)))).realize()
|
|
rawbufs = GlobalCounters.cache[0][1]
|
|
GlobalCounters.cache = None
|
|
assert len(rawbufs) == 3 and set(rawbufs[1:]) == {a.lazydata.realized, b.lazydata.realized}
|
|
np_c = (np_a[:2] - np_a[2:]) - (np_b[:2] - np_b[2:])
|
|
np.testing.assert_allclose(np_c, c.numpy())
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main()
|