U
    c                     @  sP   d dl mZ d dlZd dlmZ d dlmZ ddddZd	d
d	dddZ	dS )    )annotationsN)NumpyIndexT)is_list_likezlist[np.ndarray])returnc                   s   d}t | st|| D ]}t |st|qt| dkr>g S tjdd | D tjd}t|}t|dk rxtdt	|d d d< |d dkr|d | n
t
| fd	d
t| D S )a  
    Numpy version of itertools.product.
    Sometimes faster (for large inputs)...

    Parameters
    ----------
    X : list-like of list-likes

    Returns
    -------
    product : list of ndarrays

    Examples
    --------
    >>> cartesian_product([list('ABC'), [1, 2]])
    [array(['A', 'A', 'B', 'B', 'C', 'C'], dtype='<U1'), array([1, 2, 1, 2, 1, 2])]

    See Also
    --------
    itertools.product : Cartesian product of input iterables.  Equivalent to
        nested for-loops.
    z'Input must be a list-like of list-likesr   c                 s  s   | ]}t |V  qd S )N)len).0x r	   </tmp/pip-unpacked-wheel-g7fro6k3/pandas/core/reshape/util.py	<genexpr>+   s     z$cartesian_product.<locals>.<genexpr>)Zdtypez+Product space too large to allocate arrays!   c                   s0   g | ](\}}t t|| t | qS r	   )tile_compatnprepeatproduct)r   ir   abr	   r
   
<listcomp><   s
   z%cartesian_product.<locals>.<listcomp>)r   	TypeErrorr   r   ZfromiterZintpZ
cumproductany
ValueErrorZrollZ
zeros_like	enumerate)Xmsgr   ZlenXZcumprodXr	   r   r
   cartesian_product
   s(    


r   r   int)arrnumr   c                 C  s8   t | tjrt| |S ttt| |}| |S )zf
    Index compat for np.tile.

    Notes
    -----
    Does not support multi-dimensional `num`.
    )
isinstancer   ZndarrayZtileZaranger   Ztake)r   r    Ztakerr	   r	   r
   r   E   s    r   )

__future__r   Znumpyr   Zpandas._typingr   Zpandas.core.dtypes.commonr   r   r   r	   r	   r	   r
   <module>   s
   ;