U
    ,d
                     @   sp   d Z ddlmZmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZmZ ddlmZ edd	 Zed
d ZdS )zd
This file provides internal compiler utilities that support certain special
operations with numpy.
    )typestyping)unpack_tuple)	intrinsic)impl_ret_new_ref)RequireLiteralValueTypingError)tuple_setitemc                    sB   ddl m   fdd}t|}tj|dtjd}||}||fS )zA version of numpy.empty whose dtype is inferred by the type system.

    Expects `shape` to be a int-tuple.

    There is special logic in the type-inferencer to handle the "refine"-ing
    of undefined dtype.
    r   _empty_nd_implc                    s@   |j }| stt||d } | |||}t| ||| S )Nr   )return_typeZ
is_preciseAssertionErrorr   r   Z	_getvalue)contextbuilder	signatureargsZarrtyZshapesresr
    ;/tmp/pip-unpacked-wheel-eu7e0c37/numba/np/unsafe/ndarray.pycodegen   s
    zempty_inferred.<locals>.codegenC)ndimZlayoutdtype)Znumba.np.arrayobjr   lenr   ArrayZ	undefined)	typingctxshaper   ZndZarray_tysigr   r
   r   empty_inferred   s    	
r   c                    sh   t |tjstd|jdkr.td|jt|j tj	|j
 d||} fdd}||fS )zConvert *array* into a tuple of *length*

    Returns ``UniTuple(array.dtype, length)``

    ** Warning **
    - No boundchecking.
      If *length* is longer than *array.size*, the behavior is undefined.
    z$*length* argument must be a constant   zNot supported on array.ndim={})r   countc                    sf   dd }|j d tjg}tjf| }| tj}| }|d | |g}	| ||||	}
|
S )Nc                 S   s&   |}t |D ]}t||| | }q|S )N)ranger	   )arraylengthempty_tupleoutir   r   r   impl?   s    z-to_fixed_tuple.<locals>.codegen.<locals>.implr   )r   r   Zintpr   r   Zget_value_typeZget_constant_undefZcompile_internal)r   r   r   r   r'   Zinner_argtypesZ	inner_sigZll_idx_typer$   Z
inner_argsr   
tuple_sizeZ
tuple_typer   r   r   >   s    
zto_fixed_tuple.<locals>.codegen)
isinstancer   ZIntegerLiteralr   r   r   formatintZliteral_valueZUniTupler   )r   r"   r#   r   r   r   r(   r   to_fixed_tuple)   s    



r-   N)__doc__Z
numba.corer   r   Znumba.core.cgutilsr   Znumba.core.extendingr   Znumba.core.imputilsr   Znumba.core.errorsr   r   Znumba.cpython.unsafe.tupler	   r   r-   r   r   r   r   <module>   s   
