U
    f/e~                     @   s.   d dl Zd dlmZ dd ZedddZdS )    N)is_list_likec                    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-tiezk1ph/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>6   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   )numc                 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)Zarrr   Ztakerr   r   r   r   9   s    r   )Znumpyr   Zpandas.core.dtypes.commonr   r   intr   r   r   r   r   <module>   s   3