
    z	i                        S r SSKJr  SSKJr  SSKJrJrJr  SSK	r
SSKJrJr  \\S4   r \ " S S	\5      5       r " S
 S\5      rSS jrSS jrSS jrg)z+
Array shape related classes and functions
    )annotations)Iterable)ProtocolUnionruntime_checkableN)	ArrayLikeNDArrayzIterable[ShapeInput]c                  T    \ rS rSrSr\SS j5       r\S	S j5       r\S	S j5       rSr	g)
Shaped   a  Protocol that defines what it means to be a shaped object.

Note that static type checkers will classify ``numpy.ndarray`` as being :class:`Shaped`.
Moreover, since this protocol is runtime-checkable, we will even have
``isinstance(<numpy.ndarray instance>, Shaped) == True``.
c                    [        S5      e)zThe array shape of this object.z7A `Shaped` protocol must implement the `shape` propertyNotImplementedErrorselfs    \/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/primitives/containers/shape.pyshapeShaped.shape%   s     ""[\\    c                    [        S5      e)z.The number of array dimensions of this object.z6A `Shaped` protocol must implement the `ndim` propertyr   r   s    r   ndimShaped.ndim*        ""Z[[r   c                    [        S5      e)zVThe total dimension of this object, i.e. the product of the entries of :attr:`~shape`.z6A `Shaped` protocol must implement the `size` propertyr   r   s    r   sizeShaped.size/   r   r    N)returntuple[int, ...])r   int)
__name__
__module____qualname____firstlineno____doc__propertyr   r   r   __static_attributes__r   r   r   r   r      sI     ] ] \ \ \ \r   r   c                  Z    \ rS rSr% SrS\S'   S r\S 5       r\S 5       r	\S 5       r
S	rg
)ShapedMixin5   zXMixin class to create :class:`~Shaped` types by only providing :attr:`_shape` attribute.r   _shapec                L    [        U 5      R                   SU R                   S3$ )Nz(<z>))typer!   r   r   s    r   __repr__ShapedMixin.__repr__:   s$    t*%%&bB77r   c                    U R                   $ N)r+   r   s    r   r   ShapedMixin.shape=   s    {{r   c                ,    [        U R                  5      $ r1   )lenr+   r   s    r   r   ShapedMixin.ndimA   s    4;;r   c                Z    [        [        R                  " U R                  [         S95      $ )N)dtype)r    npprodr+   r   s    r   r   ShapedMixin.sizeE   s    2774;;c233r   r   N)r!   r"   r#   r$   r%   __annotations__r.   r&   r   r   r   r'   r   r   r   r)   r)   5   sL    b8       4 4r   r)   c                \    [        U [        5      (       a  U $ [        R                  " U 5      $ )zCoerce the input into an object with a shape attribute.

Copies are avoided.

Args:
    arr: The object to coerce.

Returns:
    Something that is :class:`~Shaped`, and always ``numpy.ndarray`` if the input is not
    already :class:`~Shaped`.
)
isinstancer   r8   asarray)arrs    r   array_coercer@   J   s$     #v
::c?r   c              #    #    U  HY  n [        U[        5      (       a  [        U5       Sh  vN   M.  [        U5      U:X  a  [        U5      v   ML  [	        SU S35      e   g N6! [
        [        4 a  n[	        SU S35      UeSnAff = f7f)z
Yield one integer at a time.

Args:
    arg: Integers or iterables of integers, possibly nested, to be yielded.

Yields:
    The provided integers in depth-first recursive order.

Raises:
    ValueError: If an input is not an iterable or an integer.
Nz	Expected z to be iterable or an integer.)r=   r   _flatten_to_intsr    
ValueError	TypeErrorRecursionError)argitemexs      r   rB   rB   [   s      	W$))+D111Td"$i 9TF2P!QRR  2
 >* 	Wy.LMNTVV	WsN   B#A%A#A%BA%BA% B#A%%B
5BB

Bc                 *    [        [        U 5      5      $ )a  
Flatten the input into a single tuple of integers, preserving order.

Args:
    shapes: Integers or iterables of integers, possibly nested.

Returns:
    A tuple of integers.

Raises:
    ValueError: If some member of ``shapes`` is not an integer or iterable.
)tuplerB   )shapess    r   shape_tuplerL   t   s     !&)**r   )r?   zArrayLike | Shapedr   zNDArray | Shaped)rF   
ShapeInputr   zIterable[int])rK   rM   r   r   )r%   
__future__r   collections.abcr   typingr   r   r   numpyr8   numpy.typingr   r	   r    rM   r   r)   r@   rB   rL   r   r   r   <module>rS      sk    # $ 5 5  +3../
 4 \X \ \04& 4*"W2+r   