B
     \
                 @   sx   d Z ddlmZ ddl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   )Zreturn_typeZ
is_preciseAssertionErrorr   r   Z	_getvalue)contextbuilder	signatureargsZarrtyZshapesres)r    3lib/python3.7/site-packages/numba/unsafe/ndarray.pycodegen   s
    zempty_inferred.<locals>.codegenC)ndimZlayoutdtype)Znumba.targets.arrayobjr   lenr   Z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 constantr	   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*   |}x t |D ]}t||| | }qW |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_size
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&   r   to_fixed_tuple*   s    



r*   N)__doc__Znumbar   r   Znumba.cgutilsr   Znumba.extendingr   Znumba.targets.imputilsr   Znumba.errorsr   r   tupler
   r   r*   r   r   r   r   <module>   s   