Make creation helpers use fp32 by default (#374)

* Make creation helpers use fp32 by default

half the big = twice the fast

* Fix flake8 with an extra multiply
This commit is contained in:
Ollin Boer Bohan
2022-09-04 13:47:27 -07:00
committed by GitHub
parent 1a54ea2417
commit 2c6f4e4c66

View File

@@ -90,17 +90,17 @@ class Tensor:
def empty(cls, *shape, **kwargs): return cls(np.empty(shape, dtype=np.float32), **kwargs)
@classmethod
def randn(cls, *shape, **kwargs): return cls(np.random.randn(*shape).astype(np.float32), **kwargs)
def randn(cls, *shape, **kwargs): return cls(np.random.default_rng().standard_normal(size=shape, dtype=np.float32), **kwargs)
@classmethod
def arange(cls, stop, start=0, **kwargs): return cls(np.arange(start=start, stop=stop).astype(np.float32), **kwargs)
def arange(cls, stop, start=0, **kwargs): return cls(np.arange(start=start, stop=stop, dtype=np.float32), **kwargs)
# TODO: uniform should be a late binding thing
@classmethod
def uniform(cls, *shape, **kwargs): return cls((np.random.uniform(-1., 1., size=shape)/np.sqrt(prod(shape))).astype(np.float32), **kwargs)
def uniform(cls, *shape, **kwargs): return cls(((np.random.default_rng().random(size=shape, dtype=np.float32) * 2 - 1) * prod(shape)**-0.5), **kwargs)
@classmethod
def eye(cls, dim, **kwargs): return cls(np.eye(dim).astype(np.float32), **kwargs)
def eye(cls, dim, **kwargs): return cls(np.eye(dim, dtype=np.float32), **kwargs)
# ***** toposort and backward pass *****