@@ -109,7 +109,8 @@ def _concat_check(tup, dtype, out):
109
109
110
110
111
111
### XXX: order the imports DAG
112
- from . _funcs import normalizer , DTypeLike
112
+ from . _funcs import normalizer , DTypeLike , ArrayLike
113
+ from typing import Optional
113
114
114
115
@normalizer
115
116
def concatenate (ar_tuple , axis = 0 , out = None , dtype : DTypeLike = None , casting = "same_kind" ):
@@ -368,55 +369,46 @@ def _xy_helper_corrcoef(x_tensor, y_tensor=None, rowvar=True):
368
369
return x_tensor
369
370
370
371
371
- @_decorators .dtype_to_torch
372
- def corrcoef (x , y = None , rowvar = True , bias = NoValue , ddof = NoValue , * , dtype = None ):
372
+ #@_decorators.dtype_to_torch
373
+ @normalizer
374
+ def corrcoef (x : ArrayLike , y : Optional [ArrayLike ]= None , rowvar = True , bias = NoValue , ddof = NoValue , * , dtype : DTypeLike = None ):
373
375
if bias is not None or ddof is not None :
374
376
# deprecated in NumPy
375
377
raise NotImplementedError
376
-
377
- x_tensor , y_tensor = _helpers .to_tensors_or_none (x , y )
378
- tensor = _xy_helper_corrcoef (x_tensor , y_tensor , rowvar )
378
+ tensor = _xy_helper_corrcoef (x , y , rowvar )
379
379
result = _impl .corrcoef (tensor , dtype = dtype )
380
380
return asarray (result )
381
381
382
382
383
- @_decorators . dtype_to_torch
383
+ @normalizer
384
384
def cov (
385
- m ,
386
- y = None ,
385
+ m : ArrayLike ,
386
+ y : Optional [ ArrayLike ] = None ,
387
387
rowvar = True ,
388
388
bias = False ,
389
389
ddof = None ,
390
- fweights = None ,
391
- aweights = None ,
390
+ fweights : Optional [ ArrayLike ] = None ,
391
+ aweights : Optional [ ArrayLike ] = None ,
392
392
* ,
393
- dtype = None ,
393
+ dtype : DTypeLike = None ,
394
394
):
395
-
396
- m_tensor , y_tensor , fweights_tensor , aweights_tensor = _helpers .to_tensors_or_none (
397
- m , y , fweights , aweights
398
- )
399
- m_tensor = _xy_helper_corrcoef (m_tensor , y_tensor , rowvar )
400
-
401
- result = _impl .cov (
402
- m_tensor , bias , ddof , fweights_tensor , aweights_tensor , dtype = dtype
403
- )
395
+ m = _xy_helper_corrcoef (m , y , rowvar )
396
+ result = _impl .cov (m , bias , ddof , fweights , aweights , dtype = dtype )
404
397
return asarray (result )
405
398
406
399
407
- def bincount (x , / , weights = None , minlength = 0 ):
408
- if not isinstance (x , ndarray ) and x == []:
400
+ @normalizer
401
+ def bincount (x : ArrayLike , / , weights : Optional [ArrayLike ]= None , minlength = 0 ):
402
+ if x .numel () == 0 :
409
403
# edge case allowed by numpy
410
- x = asarray ([], dtype = int )
411
-
412
- x_tensor , weights_tensor = _helpers .to_tensors_or_none (x , weights )
413
- result = _impl .bincount (x_tensor , weights_tensor , minlength )
404
+ x = torch .as_tensor ([], dtype = int )
405
+ result = _impl .bincount (x , weights , minlength )
414
406
return asarray (result )
415
407
416
408
417
- def where ( condition , x = None , y = None , / ):
418
- cond_t , x_t , y_t = _helpers . to_tensors_or_none ( condition , x , y )
419
- result = _impl .where (cond_t , x_t , y_t )
409
+ @ normalizer
410
+ def where ( condition : ArrayLike , x : Optional [ ArrayLike ] = None , y : Optional [ ArrayLike ] = None , / ):
411
+ result = _impl .where (condition , x , y )
420
412
if isinstance (result , tuple ):
421
413
# single-argument where(condition)
422
414
return tuple (asarray (x ) for x in result )
@@ -840,22 +832,19 @@ def nanpercentile():
840
832
raise NotImplementedError
841
833
842
834
843
- def diff (a , n = 1 , axis = - 1 , prepend = NoValue , append = NoValue ):
835
+ @normalizer
836
+ def diff (a : ArrayLike , n = 1 , axis = - 1 , prepend : Optional [ArrayLike ]= NoValue , append : Optional [ArrayLike ]= NoValue ):
844
837
845
838
if n == 0 :
846
839
# match numpy and return the input immediately
847
- return a
848
-
849
- a_tensor , prepend_tensor , append_tensor = _helpers .to_tensors_or_none (
850
- a , prepend , append
851
- )
840
+ return asarray (a )
852
841
853
842
result = _impl .diff (
854
- a_tensor ,
843
+ a ,
855
844
n = n ,
856
845
axis = axis ,
857
- prepend_tensor = prepend_tensor ,
858
- append_tensor = append_tensor ,
846
+ prepend_tensor = prepend ,
847
+ append_tensor = append ,
859
848
)
860
849
return asarray (result )
861
850
0 commit comments