B
    dc                 @   s  d dl mZ ddlmZmZmZ d dlZyPd dlZee	e
ejdd d dk Zee	e
ejdd d d	k ZW n  ek
r   dZd
Zd
ZY nX erdZndZ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dkr0d&d' Znd(d' Zd)d* Z d+d, Z!ejd@d-d.Z"ejd/d0 Z#d1d2 Z$ejd3d4 Z%d5d6 Z&ejd7d8 Z'd9d: Z(d;d< Z)d=d> Z*dS )A    )absolute_import   )CTypeCTypedefTypeCStructOrUnionTypeN.   )r   	      )r   r	      T__builtin__builtinsc             C   s(   | d krdS t | dd }|o&|ddS )NF
directivesZ
np_pythran)getattrget)envr    r   d/work/yifan.wang/ringdown/master-ringdown-env/lib/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rjd|||f S d||dd| f S | jr| jS | jr|  S t
d| t| f d S )Nzunsupported type %s!zpythonic::types::%s<%s,%d>z3pythonic::types::%s<%s,pythonic::types::pshape<%s>>,)longz unsupported pythran type %s (%s))Z	is_bufferndimdtyper   r   cnamer   sign_and_namer   Ztypedef_cname
ValueErrorpythran_is_pre_0_9joinis_pythran_exprpythran_typer   type)ZTyptyper   r   ctyper   r   r   r%   '   s"    



r%   c             C   s   d|  S )Nz(typename std::remove_reference<%s>::typer   )tyr   r   r   type_remove_ref?   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_typeD   s
    r,   c             C   s   d| t |f S )Nzdecltype(%sstd::declval<%s>()))r%   )r+   r   r   r   r   pythran_unaryop_typeM   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>T   s    z!_index_access.<locals>.<listcomp>r   z[%s]z(%s))r#   len)r0   indicesZindexingr   )r0   r   _index_accessR   s    r4   c             C   sj   | \}}|j r8dt|jj  }dtddg| f S |jrJd|  S |jrZd|j	 S t
d| d S )Nr   z"pythonic::%s::functor::slice{}(%s)r   0zstd::declval<%s>()zunsupported indexing type %s!)is_sliceintstepis_nonepythran_builtinsr#   is_intr    r$   r%   r!   )Zindex_with_typer/   Z
index_typenr   r   r   _index_type_codeX   s    
r=   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 )	NZcontiguous_slicer   slicezpythonic::types::%s(%s)r   c             s   s   | ]}|  V  qd S )N)pythran_result)r.   vr   r   r   	<genexpr>o   s    z_index_code.<locals>.<genexpr>zunsupported indexing type %s)r6   startstopr8   r9   r#   r&   r;   
to_pythranr$   r?   r!   )r/   valuesfuncr   r   r   _index_codef   s    rG   c             C   s   t dt| tt|f S )Nzdecltype(std::declval<%s>()%s))r*   r%   r4   r=   )r   r3   r   r   r   pythran_indexing_typew   s    rH   c             C   s
   t t| S )N)r4   rG   )r3   r   r   r   pythran_indexing_code~   s    rI   c             C   s   | j s
g S t| j| jg S )N)Zis_numpy_attributenp_func_to_listobj	attribute)rF   r   r   r   rJ      s    rJ   c             C   s   dS )NFr   )namer   r   r   pythran_is_numpy_func_supported   s    rN   c             C   s>   t jjd }t| }x$|D ]}||d }|d krdS qW dS )NnumpyFT)pythranZtablesZMODULESrJ   r   )rF   ZCurFZFLFr   r   r   rN      s    
c             C   s0   t | } d| d d dg }d|| d f S )Nz::Zfunctorzpythonic::numpy::%s::%s)rJ   r#   )rF   Z
submodulesr   r   r   pythran_functor   s    rS   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   rA      s    z$pythran_func_type.<locals>.<genexpr>zdecltype(%s{}(%s)))r#   rS   )rF   argsr   r   r   pythran_func_type   s    rV   c             C   sn   | j }|jr||  S t|ddddgr4|  S | jrBdt S |d krRt|}| j js^t	d|| 
 f S )Nr$   r   is_float
is_complexzpythonic::%s::Nonezfrom_python<%s>(%s))r&   r;   Z	cast_coderesultis_typer9   r:   r%   Zis_pyobjectAssertionErrorZ	py_result)r+   r'   Zop_typer   r   r   rD      s    rD   c             C   s"   x|D ]}t | |drdS qW dS )NFT)r   )r   typesattrr   r   r   rZ      s    
rZ   c             C   s   | j pt| jS )N)r9   r   r&   )noder   r   r   !is_pythran_supported_node_or_none   s    r_   c             C   s   d}t | |pt| S )N)r$   r;   r   rW   r9   rX   )rZ   r$   )r   pythran_supportedr   r   r   r      s    r   c             C   s   d}t | |pt| S )N)r$   r;   r   rW   rX   )rZ   r$   )r   r`   r   r   r   #is_pythran_supported_operation_type   s    ra   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    re   c             C   s   t | } dd|  S )Nzpythonic/numpy/%s.hpp/)rJ   r#   )rF   r   r   r   pythran_get_func_include_file   s    rg   c             C   s   |  d |  d |  d |  d |  d |  dt  |  d x(dD ] }|  d	|  |  d
|  qPW xdD ]}|  d|  qzW d S )Nzpythonic/core.hppzpythonic/python/core.hppzpythonic/types/bool.hppzpythonic/types/ndarray.hppzpythonic/numpy/power.hppzpythonic/%s/slice.hppz<new>)          @   zpythonic/types/uint%d.hppzpythonic/types/int%d.hpp)
floatZfloat32Zfloat64setr>   tupler7   complexZ	complex64Z
complex128zpythonic/types/%s.hpp)Zadd_include_filer:   )r   itr   r   r   include_pythran_generic   s    







rr   )r   )N)+
__future__r   Z
PyrexTypesr   r   r   cythonrP   rn   mapr7   __version__splitr"   Zpythran_is_pre_0_9_6ImportErrorr:   r   Zccallr   r%   Zcfuncr*   r,   r-   r4   r=   rG   rH   rI   rJ   rN   rS   rV   rD   rZ   r_   r   ra   r$   re   rg   rr   r   r   r   r   <module>   sP   "&

	

	