2
2
from __future__ import annotations
3
3
import time , math , itertools , functools , struct , sys , inspect , pathlib , string , hashlib , weakref
4
4
from contextlib import ContextDecorator
5
- from typing import List , Tuple , Callable , Optional , ClassVar , Union , Sequence , cast , get_args , Literal , TYPE_CHECKING , SupportsIndex
5
+ from typing import Callable , Optional , ClassVar , Union , Sequence , cast , get_args , Literal , TYPE_CHECKING , SupportsIndex
6
6
from tinygrad .dtype import DType , DTypeLike , dtypes , ImageDType , ConstType , least_upper_float , least_upper_dtype , sum_acc_dtype , to_dtype , truncate
7
7
from tinygrad .helpers import argfix , make_tuple , flatten , prod , all_int , round_up , merge_dicts , argsort , getenv , all_same , fully_flatten , dedup
8
8
from tinygrad .helpers import IMAGE , WINO , _METADATA , Metadata , TRACEMETA , ceildiv , fetch , polyN , unwrap
@@ -68,7 +68,7 @@ def get_shape(x) -> tuple[int, ...]:
68
68
if not all_same (subs := [get_shape (xi ) for xi in x ]): raise ValueError (f"inhomogeneous shape from { x } " )
69
69
return (len (subs ),) + (subs [0 ] if subs else ())
70
70
71
- def _frompy (x :Union [List , Tuple , bytes ], dtype :DType ) -> UOp :
71
+ def _frompy (x :Union [list , tuple , bytes ], dtype :DType ) -> UOp :
72
72
if isinstance (x , bytes ): ret , data = UOp .metaop (Ops .EMPTY , (len (x )// dtype .itemsize ,), dtype , "PYTHON" ), x
73
73
else :
74
74
ret = UOp .metaop (Ops .EMPTY , get_shape (x ), dtype , "PYTHON" )
@@ -131,7 +131,7 @@ class Tensor(SimpleMathTrait):
131
131
training : ClassVar [bool ] = False
132
132
no_grad : ClassVar [bool ] = False
133
133
134
- def __init__ (self , data :Union [None , ConstType , bytes , List , Tuple , UOp , 'np.ndarray' , pathlib .Path ], # type: ignore [name-defined] # noqa: F821
134
+ def __init__ (self , data :Union [None , ConstType , bytes , list , tuple , UOp , 'np.ndarray' , pathlib .Path ], # type: ignore [name-defined] # noqa: F821
135
135
device :Optional [Union [str , tuple , list ]]= None , dtype :Optional [DTypeLike ]= None , requires_grad :Optional [bool ]= None ):
136
136
if dtype is not None : dtype = to_dtype (dtype )
137
137
if device is None and isinstance (data , pathlib .Path ): device = f"DISK:{ data .resolve ()} " # keep it on the disk if device is None
@@ -329,7 +329,7 @@ def item(self) -> ConstType:
329
329
assert self .numel () == 1 , "must have one element for item"
330
330
return self .data ()[(0 ,) * len (self .shape )]
331
331
332
- # TODO: should be Tensor.tolist() -> Union[list[ConstType], ConstType]. The List is Sequence because mypy expects memoryview.tolist() -> list[int]
332
+ # TODO: should be Tensor.tolist() -> Union[list[ConstType], ConstType]. The list is Sequence because mypy expects memoryview.tolist() -> list[int]
333
333
# src: https://github.com/python/mypy/blob/release-1.6/mypy/typeshed/stdlib/builtins.pyi#L803
334
334
def tolist (self ) -> Union [Sequence [ConstType ], ConstType ]:
335
335
"""
@@ -1185,7 +1185,7 @@ def __getitem__(self, indices) -> Tensor:
1185
1185
"""
1186
1186
Retrieve a sub-tensor using indexing.
1187
1187
1188
- Supported Index Types: `int | slice | Tensor | None | List | Tuple | Ellipsis`
1188
+ Supported Index Types: `int | slice | Tensor | None | list | tuple | Ellipsis`
1189
1189
1190
1190
Examples:
1191
1191
```python exec="true" source="above" session="tensor" result="python"
@@ -2036,7 +2036,7 @@ def _resolve_pool_pads(self, padding:Union[int, Sequence[int]], dims:int) -> Seq
2036
2036
raise ValueError (f"Padding must be an int or a sequence of length { dims } or { 2 * dims } , but got { padding = } for { self .shape = } with { dims = } ." )
2037
2037
return [padding ]* 2 * dims if isinstance (padding , int ) else (padding if len (padding ) == 2 * dims else [p for p in padding for _ in range (2 )][::- 1 ])
2038
2038
2039
- def _apply_ceil_mode (self , pads :Sequence [int ], k_ :Tuple [sint , ...], s_ :Union [Tuple [int , ...], int ], d_ :Union [Tuple [int , ...], int ]) -> List [int ]:
2039
+ def _apply_ceil_mode (self , pads :Sequence [int ], k_ :tuple [sint , ...], s_ :Union [tuple [int , ...], int ], d_ :Union [tuple [int , ...], int ]) -> list [int ]:
2040
2040
(d_ ,s_ ), i_ = (make_tuple (x , len (k_ )) for x in (d_ ,s_ )), self .shape [- len (k_ ):]
2041
2041
pads , grouped_pads = list (pads ), _flat_to_grouped (pads )
2042
2042
# https://arxiv.org/pdf/1603.07285 section 5.1, relationship 15.
@@ -2059,10 +2059,10 @@ def avg_pool2d(self, kernel_size=(2,2), stride=None, dilation=1, padding=0, ceil
2059
2059
1. `int` (single value):
2060
2060
Applies the same padding value uniformly to all spatial dimensions.
2061
2061
2062
- 2. `Tuple [int, ...]` (length = number of spatial dimensions):
2062
+ 2. `tuple [int, ...]` (length = number of spatial dimensions):
2063
2063
Specifies a distinct padding value for each spatial dimension in the form `(padding_height, padding_width, ...)`.
2064
2064
2065
- 3. `Tuple [int, ...]` (length = 2 * number of spatial dimensions):
2065
+ 3. `tuple [int, ...]` (length = 2 * number of spatial dimensions):
2066
2066
Specifies explicit padding for each side of each spatial dimension in the form
2067
2067
`(padding_left, padding_right, padding_top, padding_bottom, ...)`.
2068
2068
@@ -2106,10 +2106,10 @@ def max_pool2d(self, kernel_size=(2,2), stride=None, dilation=1, padding=0, ceil
2106
2106
1. `int` (single value):
2107
2107
Applies the same padding value uniformly to all spatial dimensions.
2108
2108
2109
- 2. `Tuple [int, ...]` (length = number of spatial dimensions):
2109
+ 2. `tuple [int, ...]` (length = number of spatial dimensions):
2110
2110
Specifies a distinct padding value for each spatial dimension in the form `(padding_height, padding_width, ...)`.
2111
2111
2112
- 3. `Tuple [int, ...]` (length = 2 * number of spatial dimensions):
2112
+ 3. `tuple [int, ...]` (length = 2 * number of spatial dimensions):
2113
2113
Specifies explicit padding for each side of each spatial dimension in the form
2114
2114
`(padding_left, padding_right, padding_top, padding_bottom, ...)`.
2115
2115
@@ -2144,10 +2144,10 @@ def conv2d(self, weight:Tensor, bias:Optional[Tensor]=None, groups=1, stride=1,
2144
2144
1. `int` (single value):
2145
2145
Applies the same padding value uniformly to all spatial dimensions.
2146
2146
2147
- 2. `Tuple [int, ...]` (length = number of spatial dimensions):
2147
+ 2. `tuple [int, ...]` (length = number of spatial dimensions):
2148
2148
Specifies a distinct padding value for each spatial dimension in the form `(padding_height, padding_width, ...)`.
2149
2149
2150
- 3. `Tuple [int, ...]` (length = 2 * number of spatial dimensions):
2150
+ 3. `tuple [int, ...]` (length = 2 * number of spatial dimensions):
2151
2151
Specifies explicit padding for each side of each spatial dimension in the form
2152
2152
`(padding_left, padding_right, padding_top, padding_bottom, ...)`.
2153
2153
@@ -2217,10 +2217,10 @@ def conv_transpose2d(self, weight:Tensor, bias:Optional[Tensor]=None, groups=1,
2217
2217
1. `int` (single value):
2218
2218
Applies the same padding value uniformly to all spatial dimensions.
2219
2219
2220
- 2. `Tuple [int, ...]` (length = number of spatial dimensions):
2220
+ 2. `tuple [int, ...]` (length = number of spatial dimensions):
2221
2221
Specifies a distinct padding value for each spatial dimension in the form `(padding_height, padding_width, ...)`.
2222
2222
2223
- 3. `Tuple [int, ...]` (length = 2 * number of spatial dimensions):
2223
+ 3. `tuple [int, ...]` (length = 2 * number of spatial dimensions):
2224
2224
Specifies explicit padding for each side of each spatial dimension in the form
2225
2225
`(padding_left, padding_right, padding_top, padding_bottom, ...)`.
2226
2226
0 commit comments