B
    ž†\£  ã               @   sh  d dl mZ ddlmZmZmZ d dlZy"d dlZejZ	e	dkpFe	dkZ
W n ek
rf   dZ	dZ
Y nX dd	„ Zejd
d„ ƒZd:dd„Zejdd„ ƒZdd„ Zdd„ Zejdd„ ƒZdd„ Zdd„ Zdd„ Zdd„ Zdd „ Ze	rêd!d"„ Znd#d"„ Zd$d%„ Zd&d'„ Zejd;d(d)„ƒZejd*d+„ ƒZd,d-„ Zejd.d/„ ƒZ d0d1„ Z!ejd2d3„ ƒZ"d4d5„ Z#d6d7„ Z$d8d9„ Z%dS )<é    )Úabsolute_importé   )ÚCTypeÚCTypedefTypeÚCStructOrUnionTypeNz0.9z0.8.7Fc             C   s(   | d krdS t | dd ƒ}|o&| dd¡S )NFÚ
directivesZ
np_pythran)ÚgetattrÚget)Úenvr   © r   ú6lib/python3.7/site-packages/Cython/Compiler/Pythran.pyÚhas_np_pythran   s    r   c             C   s   t | tƒrt| jƒS | jS )N)Ú
isinstancer   Úis_pythran_supported_typeZtypedef_base_typeÚ
is_numeric)Útype_r   r   r   Úis_pythran_supported_dtype   s    

r   Úndarrayc             C   s´   | j r‚| j| j }}t|tƒr&|j}n2t|tƒr:| ¡ }nt|tƒrL|j	}nt
d| ƒ‚trtd||d d| ¡f S d|||f S | jrŽ| jS | jrœ|  ¡ S t
d| t| ƒf ƒ‚d S )Nzunsupported type %s!z3pythonic::types::%s<%s,pythonic::types::pshape<%s>>ú,)Z
Py_ssize_tzpythonic::types::%s<%s,%d>z unsupported pythran type %s (%s))Z	is_bufferÚndimÚdtyper   r   Zcnamer   Úsign_and_namer   Ztypedef_cnameÚ
ValueErrorÚpythran_is_0_8_7ÚjoinÚis_pythran_exprÚpythran_typer   Útype)ZTyÚptyper   r   Zctyper   r   r   r   !   s"    



r   c             C   s   d|  S )Nz(typename std::remove_reference<%s>::typer   )Ztyr   r   r   Útype_remove_ref9   s    r   c             C   s6   | dkrdt |ƒt |ƒf S dt |ƒ| t |ƒf S d S )Nz**zSdecltype(pythonic::numpy::functor::power{}(std::declval<%s>(), std::declval<%s>()))z2decltype(std::declval<%s>() %s std::declval<%s>()))r   )ÚopZtAZtBr   r   r   Úpythran_binop_type>   s
    r!   c             C   s   d| t |ƒf S )Nzdecltype(%sstd::declval<%s>()))r   )r    r   r   r   r   Úpythran_unaryop_typeG   s    r"   c                s0   d  ‡ fdd„|D ƒ¡}t|ƒdkr(dnd| S )Nr   c                s   g | ]}ˆ |ƒ‘qS r   r   )Ú.0Úidx)Ú
index_coder   r   ú
<listcomp>N   s    z!_index_access.<locals>.<listcomp>r   z[%s]z(%s))r   Úlen)r%   ÚindicesZindexingr   )r%   r   Ú_index_accessL   s    r)   c             C   sr   | \}}|j r@|jjr d}d}nd}d}d|d dg| ¡f S |jrRd| ¡  S |jrbd|j S td	| ƒ‚d S )
NÚcontiguous_sliceé   Úsliceé   zpythonic::types::%s(%s)r   Ú0zstd::declval<%s>()zunsupported indexing type %s!)	Úis_sliceÚstepÚis_noner   Úis_intr   r   r   r   )Zindex_with_typer$   Z
index_typeÚfuncÚnr   r   r   Ú_index_type_codeR   s    
r5   c             C   s‚   | j rP| j| j| jf}| jjr0d}|d d… }nd}d|d dd„ |D ƒ¡f S | jjr`t| ƒS | jj	rp|  
¡ S td| j ƒ‚d S )	Nr*   r+   r,   zpythonic::types::%s(%s)r   c             s   s   | ]}|  ¡ V  qd S )N)Úpythran_result)r#   Úvr   r   r   ú	<genexpr>m   s    z_index_code.<locals>.<genexpr>zunsupported indexing type %s)r/   ÚstartÚstopr0   r1   r   r   r2   Ú
to_pythranr   r6   r   )r$   Úvaluesr3   r   r   r   Ú_index_coded   s    r=   c             C   s   t dt| ƒtt|ƒf ƒS )Nzdecltype(std::declval<%s>()%s))r   r   r)   r5   )r   r(   r   r   r   Úpythran_indexing_typeu   s    r>   c             C   s
   t t| ƒS )N)r)   r=   )r(   r   r   r   Úpythran_indexing_code|   s    r?   c             C   s   | j s
g S t| jƒ| jg S )N)Zis_numpy_attributeÚnp_func_to_listÚobjZ	attribute)r3   r   r   r   r@      s    r@   c             C   s>   t jjd }t| ƒ}x$|D ]}| |d ¡}|d krdS qW dS )NZnumpyFT)ÚpythranZtablesZMODULESr@   r	   )r3   ZCurFZFLÚFr   r   r   Úpythran_is_numpy_func_supported…   s    
rD   c             C   s   dS )NFr   )Únamer   r   r   rD   Ž   s    c             C   s0   t | ƒ} d | d d… dg ¡}d|| d f S )Nz::éÿÿÿÿZfunctorzpythonic::numpy::%s::%s)r@   r   )r3   Z
submodulesr   r   r   Úpythran_functor‘   s    rG   c             C   s$   d  dd„ |D ƒ¡}dt| ƒ|f S )Nr   c             s   s   | ]}d t |jƒ V  qdS )zstd::declval<%s>()N)r   r   )r#   Úar   r   r   r8   —   s    z$pythran_func_type.<locals>.<genexpr>zdecltype(%s{}(%s)))r   rG   )r3   Úargsr   r   r   Úpythran_func_type–   s    rJ   c             C   sj   | j }|jr| |  ¡ ¡S t|ddddgƒr4|  ¡ S | jr>dS |d krNt|ƒ}| j jsZt‚d||  	¡ f S )Nr   r   Úis_floatÚ
is_complexzpythonic::__builtin__::Nonezfrom_python<%s>(%s))
r   r2   Z	cast_codeÚresultÚis_typer1   r   Zis_pyobjectÚAssertionErrorZ	py_result)r    r   Zop_typer   r   r   r;   ›   s    r;   c             C   s"   x|D ]}t | |dƒrdS qW dS )NFT)r   )r   ÚtypesÚattrr   r   r   rN   ¬   s    
rN   c             C   s   | j pt| jƒS )N)r1   r   r   )Znoder   r   r   Ú!is_pythran_supported_node_or_none´   s    rR   c             C   s   d}t | |ƒpt| ƒS )N)r   r2   r   rK   r1   rL   )rN   r   )r   Úpythran_supportedr   r   r   r   ¸   s    r   c             C   s   d}t | |ƒpt| ƒS )N)r   r2   r   rK   rL   )rN   r   )r   rS   r   r   r   Ú#is_pythran_supported_operation_type¿   s    rT   c             C   s   | j S )N)r   )r   r   r   r   r   Å   s    r   c             C   s"   | j o t| jƒo | jdko | j S )N)ÚcZstrided)Zis_numpy_bufferr   r   ÚmodeÚcast)r   r   r   r   Úis_pythran_bufferÊ   s    rX   c             C   s   t | ƒ} dd | ¡ S )Nzpythonic/numpy/%s.hppú/)r@   r   )r3   r   r   r   Úpythran_get_func_include_fileÎ   s    rZ   c             C   s†   |   d¡ |   d¡ |   d¡ |   d¡ |   d¡ |   d¡ x(dD ] }|   d| ¡ |   d	| ¡ qBW xd
D ]}|   d| ¡ qlW d S )Nzpythonic/core.hppzpythonic/python/core.hppzpythonic/types/bool.hppzpythonic/types/ndarray.hppzpythonic/numpy/power.hppz<new>)é   é   é    é@   zpythonic/types/uint%d.hppzpythonic/types/int%d.hpp)
ÚfloatZfloat32Zfloat64Úsetr,   ÚtupleÚintÚcomplexZ	complex64Z
complex128zpythonic/types/%s.hpp)Zadd_include_file)r
   ÚiÚtr   r   r   Úinclude_pythran_genericÒ   s    







rf   )r   )N)&Z
__future__r   Z
PyrexTypesr   r   r   ZcythonrB   Ú__version__Zpythran_versionr   ÚImportErrorr   Zccallr   r   Zcfuncr   r!   r"   r)   r5   r=   r>   r?   r@   rD   rG   rJ   r;   rN   rR   r   rT   r   rX   rZ   rf   r   r   r   r   Ú<module>   sH   

	
	