
    z	i/                    h    S r SSKJr  SSKJr  SSKrSSKJr     S         S	S jjr	S
SS jjr
g)z*
Object ND-array initialization function.
    )annotations)SequenceN)	ArrayLikec                   ^ [        U [        R                  5      (       a2  U R                  [        :w  d  Uc  USL a  U R                  [        XS9n U $ [        U [        U5      S9n[        R                  " U[        US9nU(       d  UR                  U 5        U$ U4S jmT" U [        U5      5      n[        U5      UR                  :w  a  [        S5      e[        R                  " U[        [        U5      S9Ul        U$ )a  Convert an array-like of objects into an object array.

.. note::

    If the objects in the array like input define ``__array__`` methods
    this avoids calling them and will instead set the returned array values
    to the Python objects themselves.

Args:
    arr: An array-like input.
    order: Optional, the order of the returned array (C, F, A, K). If None
           the default NumPy ordering of C is used.
    copy: If True make a copy of the input if it is already an array.
    list_types: Optional, a sequence of types to treat as lists of array
        element objects when inferring the array shape from the input.

Returns:
    A NumPy ND-array with ``dtype=object``.

Raises:
    ValueError: If the input cannot be coerced into an object array.
T)ordercopy
list_types)dtyper   c           	     n   > US:X  a  U $ U  VVs/ s H  nT" X!S-
  5        H  o3PM     M     snn$ s  snnf )N    )nestedksublistitem_flattens       c/home/james-whalen/.local/lib/python3.13/site-packages/qiskit/primitives/containers/object_array.pyr   object_array.<locals>._flattenD   s;    Av,2XFxUVQV?Wt?WFXXXs   1ztInput object size does not match the inferred array shape. This most likely occurs when the input is a ragged array.)r   count)
isinstancenpndarrayr   objectastype_infer_shapetupleemptyfilllensize
ValueErrorfromiterflat)arrr   r   r
   shapeobj_arr	flattenedr   s          @r   object_arrayr)      s    8 #rzz""99%"3tt|**V5*<C
z):;EhhuF%8G 	S( N	Y S#e*-	y>W\\)M  {{9F#i.QN    c                    [        U [        R                  5      (       a  U R                  $ [        U [        /UQ75      (       d  g[        U 5      nUS:X  a  U4$ U/[        U S   US9Q7$ )z7Infer the shape of an array-like object without castingr   r   r	   )r   r   r   r&   listr    r   )objr
   r!   s      r   r   r   U   se    #rzz""yycD.:.//s8Dqyw?<A:>??r*   )NTr   )
r%   r   r   z
str | Noner   boolr
   zSequence[type] | Nonereturnz
np.ndarray)r   )r-   r   r
   ztuple[type, ...]r/   ztuple[int, ...])__doc__
__future__r   collections.abcr   numpyr   numpy.typingr   r)   r   r   r*   r   <module>r5      s]    # $  "
 (*	:	:: : &	:
 :z	@r*   