remove numpy usage
MODIFY
tinygrad/helpers.py
tinygrad/helpers.py
@@ -2,6 +2,10 @@ from collections import namedtuple
import math
def prod(x): return math.prod(x)
+
+# https://stackoverflow.com/questions/3382352/equivalent-of-numpy-argsort-in-basic-python
+def argsort(x): return sorted(range(len(x)), key=x.__getitem__)
+
def reduce_shape(shape, axis):
return [1 if i in axis else shape[i] for i in range(len(shape))]

MODIFY
tinygrad/llops/ops_torch.py
tinygrad/llops/ops_torch.py
import torch
-import numpy as np
from tinygrad.llops.ops_cpu import CPUBuffer
from tinygrad.ops import MovementOps, ProcessingOps

MODIFY
tinygrad/mlops.py
tinygrad/mlops.py
-import numpy as np # TODO: remove this, it's used for np.prod and np.argsort
-from tinygrad.helpers import prod, reduce_shape, get_conv_args
+from tinygrad.helpers import prod, argsort, reduce_shape, get_conv_args
from tinygrad.ops import UnaryOps, BinaryOps, ReduceOps, MovementOps, ProcessingOps
from tinygrad.tensor import Function
@@ -138,7 +137,7 @@ class Permute(Function):
return x.movement_op(MovementOps.PERMUTE, order)
def backward(ctx, grad_output):
- norder = np.argsort(ctx.input_order).tolist()
+ norder = argsort(ctx.input_order)
return grad_output.movement_op(MovementOps.PERMUTE, norder)
# TODO: merge Slice and Flip into Stride with the 3 arguments

remove numpy usage