(x:list|tuple|bytes, dtype:DType, device:str|tuple[str,...])
| 51 | return (len(subs),) + (subs[0] if subs else ()) |
| 52 | |
| 53 | def _frompy(x:list|tuple|bytes, dtype:DType, device:str|tuple[str,...]) -> UOp: |
| 54 | if isinstance(x, bytes): ret, data = UOp.new_buffer("PYTHON", len(x)//dtype.itemsize, dtype), x |
| 55 | else: |
| 56 | ret = UOp.empty(shape:=get_shape(x), dtype, "PYTHON") |
| 57 | assert dtype.fmt is not None, f"{dtype=} has None fmt" |
| 58 | truncate_function = truncate[dtype] |
| 59 | data = struct.pack(f"{prod(shape)}{dtype.fmt}", *[truncate_function(dtype.const(xi)) for xi in fully_flatten(x)]) |
| 60 | # fake realize. if target device is PYTHON it needs bytearray to be writable |
| 61 | ret.buffer.allocate(memoryview(data if device != "PYTHON" else bytearray(data))) |
| 62 | return ret |
| 63 | |
| 64 | def _get_winograd_matcols(mat, dims:int, shp:tuple[sint, ...], device:str|tuple[str, ...]|None, dtype:DType) -> list[list[Tensor]]: |
| 65 | return [[Tensor.cat(*[Tensor.full(shp[:dim] + (1,) + shp[dim+1:], float(m[k]), device=device, dtype=dtype, buffer=False) for m in mat], dim=dim) |
no test coverage detected
searching dependent graphs…