@@ -3469,34 +3469,6 @@ def reshape(array: ArrayLike | float, new_shape: int | Shape) -> float | Array:
34693469 return m
34703470
34713471
3472- def _shape (a : ArrayLike | float , s : Shape ) -> Shape :
3473- """
3474- Get the shape of the array.
3475-
3476- We only test the first index at each depth for speed.
3477- """
3478-
3479- # Found a scalar input
3480- if not isinstance (a , Sequence ):
3481- return s
3482-
3483- # Get the length
3484- size = len (a )
3485-
3486- # Array is empty, return the shape
3487- if not size :
3488- return (size ,)
3489-
3490- # Recursively get the shape of the first entry and compare against the others
3491- first = _shape (a [0 ], s )
3492- for r in range (1 , size ):
3493- if _shape (a [r ], s ) != first :
3494- raise ValueError ('Ragged lists are not supported' )
3495-
3496- # Construct the final shape
3497- return (size ,) + first
3498-
3499-
35003472@overload
35013473def _quick_shape (a : float ) -> EmptyShape :
35023474 ...
@@ -3519,7 +3491,7 @@ def _quick_shape(a: TensorLike) -> TensorShape:
35193491
35203492def _quick_shape (a : ArrayLike | float ) -> Shape :
35213493 """
3522- Acquire shape taking shortcuts by assume a non-ragged, consistently shaped array.
3494+ Acquire shape taking shortcuts by assuming a non-ragged, consistently shaped array.
35233495
35243496 No checking for consistency is performed allowing for a quicker check.
35253497 """
@@ -3558,7 +3530,25 @@ def shape(a: TensorLike) -> TensorShape:
35583530def shape (a : ArrayLike | float ) -> Shape :
35593531 """Get the shape of a list."""
35603532
3561- return _shape (a , ())
3533+ # Found a scalar input
3534+ if not isinstance (a , Sequence ):
3535+ return ()
3536+
3537+ # Get the length
3538+ size = len (a )
3539+
3540+ # Array is empty, return the shape
3541+ if not size :
3542+ return (size ,)
3543+
3544+ # Recursively get the shape of the first entry and compare against the others
3545+ first = shape (a [0 ])
3546+ for r in range (1 , size ):
3547+ if shape (a [r ]) != first :
3548+ raise ValueError ('Ragged lists are not supported' )
3549+
3550+ # Construct the final shape
3551+ return (size ,) + first
35623552
35633553
35643554def fill_diagonal (matrix : Matrix | Tensor , val : float | ArrayLike , wrap : bool = False ) -> None :
0 commit comments