2828def numba_funcify_AllocEmpty (op , node , ** kwargs ):
2929 global_env = {
3030 "np" : np ,
31- "to_scalar" : numba_basic .to_scalar ,
3231 "dtype" : np .dtype (op .dtype ),
3332 }
3433
3534 unique_names = unique_name_generator (
36- ["np" , "to_scalar" , " dtype" , "allocempty" , "scalar_shape" ], suffix_sep = "_"
35+ ["np" , "dtype" , "allocempty" , "scalar_shape" ], suffix_sep = "_"
3736 )
3837 shape_var_names = [unique_names (v , force_unique = True ) for v in node .inputs ]
3938 shape_var_item_names = [f"{ name } _item" for name in shape_var_names ]
4039 shapes_to_items_src = indent (
4140 "\n " .join (
42- f"{ item_name } = to_scalar( { shape_name } )"
41+ f"{ item_name } = { shape_name } .item( )"
4342 for item_name , shape_name in zip (
4443 shape_var_item_names , shape_var_names , strict = True
4544 )
@@ -63,10 +62,10 @@ def allocempty({", ".join(shape_var_names)}):
6362
6463@numba_funcify .register (Alloc )
6564def numba_funcify_Alloc (op , node , ** kwargs ):
66- global_env = {"np" : np , "to_scalar" : numba_basic . to_scalar }
65+ global_env = {"np" : np }
6766
6867 unique_names = unique_name_generator (
69- ["np" , "to_scalar" , " alloc" , "val_np" , "val" , "scalar_shape" , "res" ],
68+ ["np" , "alloc" , "val_np" , "val" , "scalar_shape" , "res" ],
7069 suffix_sep = "_" ,
7170 )
7271 shape_var_names = [unique_names (v , force_unique = True ) for v in node .inputs [1 :]]
@@ -110,9 +109,9 @@ def numba_funcify_ARange(op, **kwargs):
110109 @numba_basic .numba_njit (inline = "always" )
111110 def arange (start , stop , step ):
112111 return np .arange (
113- numba_basic . to_scalar ( start ),
114- numba_basic . to_scalar ( stop ),
115- numba_basic . to_scalar ( step ),
112+ start . item ( ),
113+ stop . item ( ),
114+ step . item ( ),
116115 dtype = dtype ,
117116 )
118117
@@ -187,9 +186,9 @@ def numba_funcify_Eye(op, **kwargs):
187186 @numba_basic .numba_njit (inline = "always" )
188187 def eye (N , M , k ):
189188 return np .eye (
190- numba_basic . to_scalar ( N ),
191- numba_basic . to_scalar ( M ),
192- numba_basic . to_scalar ( k ),
189+ N . item ( ),
190+ M . item ( ),
191+ k . item ( ),
193192 dtype = dtype ,
194193 )
195194
@@ -200,16 +199,16 @@ def eye(N, M, k):
200199def numba_funcify_MakeVector (op , node , ** kwargs ):
201200 dtype = np .dtype (op .dtype )
202201
203- global_env = {"np" : np , "to_scalar" : numba_basic . to_scalar , " dtype" : dtype }
202+ global_env = {"np" : np , "dtype" : dtype }
204203
205204 unique_names = unique_name_generator (
206- ["np" , "to_scalar" ],
205+ ["np" ],
207206 suffix_sep = "_" ,
208207 )
209208 input_names = [unique_names (v , force_unique = True ) for v in node .inputs ]
210209
211210 def create_list_string (x ):
212- args = ", " .join ([f"to_scalar( { i } )" for i in x ] + (["" ] if len (x ) == 1 else []))
211+ args = ", " .join ([f"{ i } .item( )" for i in x ] + (["" ] if len (x ) == 1 else []))
213212 return f"[{ args } ]"
214213
215214 makevector_def_src = f"""
@@ -237,7 +236,7 @@ def tensor_from_scalar(x):
237236def numba_funcify_ScalarFromTensor (op , ** kwargs ):
238237 @numba_basic .numba_njit (inline = "always" )
239238 def scalar_from_tensor (x ):
240- return numba_basic . to_scalar ( x )
239+ return x . item ( )
241240
242241 return scalar_from_tensor
243242
0 commit comments