Slice migrated in Eye op (#1281)

* Migrated from slice to pad and shrink, made cleaner

* Changed repeat with reshape and expand
This commit is contained in:
Umut Zengin
2023-07-19 19:08:38 +03:00
committed by GitHub
parent a5f5330d91
commit fde9f0e60d
2 changed files with 4 additions and 1 deletions

View File

@@ -168,7 +168,9 @@ class Tensor:
def ones_like(tensor, **kwargs): return Tensor.full_like(tensor, 1, **kwargs)
@staticmethod
def eye(dim, **kwargs): return Tensor([1], **kwargs).slice(((0,dim+1),)).reshape(1, dim+1).expand(dim, dim+1).reshape(dim*(dim+1)).slice(((0,dim*dim),)).reshape(dim, dim)
def eye(dim:int, **kwargs):
return Tensor([1], **kwargs).pad(((0,dim),)).reshape(1, dim+1).expand(dim, dim+1).reshape(dim*(dim+1)).shrink(((0,dim*dim),)).reshape(dim, dim)
# ***** rng hlops *****