3
?!]M                 @   sz  d dl mZ ddlmZmZmZ d dlZy.d dlZee	e
ejjdd d d;k ZW n ek
rr   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dk rd"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/d0 Z#d1d2 Z$ejd3d4 Z%d5d6 Z&d7d8 Z'd9d: Z(dS )>    )absolute_import   )CTypeCTypedefTypeCStructOrUnionTypeN.   	   Tc             C   s(   | d krdS t | dd }|o&|jddS )NF
directives
np_pythran)getattrget)envr
    r   g/home/psgendb/BIRCHDEV/lib-linux-x86_64/python/lib64/python3.6/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_type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:|j }nt|trL|j	}nt
d| trjd|||f S d||djd| f S | jr| jS | jr| j 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))r   )	is_bufferndimdtyper   r   cnamer   sign_and_namer   typedef_cname
ValueErrorpythran_is_pre_0_9joinis_pythran_exprpythran_typer   type)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_ref8   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%   )optA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_typeF   s    r0   c                s0   dj  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>M   s    z!_index_access.<locals>.<listcomp>r   z[%s]z(%s))r#   len)r3   indicesindexingr   )r3   r   _index_accessK   s    r8   c             C   sf   | \}}|j r4dt|jj  }ddjdg|  S |jrFd|j  S |jrVd|j S t	d| d S )Nr   z+pythonic::__builtin__::functor::slice{}(%s)r   0zstd::declval<%s>()zunsupported indexing type %s!)
is_sliceintstepis_noner#   is_intr   r$   r%   r!   )index_with_typer2   
index_typenr   r   r   _index_type_codeQ   s    
rB   c             C   s   | j rP| j| j| jf}| jjr0d}|d d }nd}d|djdd |D f S | jjr`t| S | jj	rp| j
 S td| j d S )	Ncontiguous_slicer   slicezpythonic::types::%s(%s)r   c             s   s   | ]}|j  V  qd S )N)pythran_result)r1   vr   r   r   	<genexpr>f   s    z_index_code.<locals>.<genexpr>zunsupported indexing type %s)r:   startstopr<   r=   r#   r&   r>   
to_pythranr$   rE   r!   )r2   valuesfuncr   r   r   _index_code]   s    rM   c             C   s   t dt| tt|f S )Nzdecltype(std::declval<%s>()%s))r+   r%   r8   rB   )r   r6   r   r   r   pythran_indexing_typen   s    rN   c             C   s
   t t| S )N)r8   rM   )r6   r   r   r   pythran_indexing_codeu   s    rO   c             C   s   | j s
g S t| j| jg S )N)is_numpy_attributenp_func_to_listobj	attribute)rL   r   r   r   rQ   x   s    rQ   c             C   s   dS )NFr   )namer   r   r   pythran_is_numpy_func_supported~   s    rU   c             C   s>   t jjd }t| }x$|D ]}|j|d }|d krdS qW dS )NnumpyFT)pythrantablesZMODULESrQ   r   )rL   ZCurFZFLFr   r   r   rU      s    
c             C   s0   t | } dj| d d dg }d|| d f S )Nz::r   functorzpythonic::numpy::%s::%sr[   )rQ   r#   )rL   
submodulesr   r   r   pythran_functor   s    r]   c             C   s$   dj 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&   )r1   ar   r   r   rG      s    z$pythran_func_type.<locals>.<genexpr>zdecltype(%s{}(%s)))r#   r]   )rL   argsr   r   r   pythran_func_type   s    r`   c             C   sj   | j }|jr|j| j S t|ddddgr4| j S | jr>dS |d krNt|}| j jsZtd|| j	 f S )Nr$   r   is_float
is_complexzpythonic::__builtin__::Nonezfrom_python<%s>(%s))
r&   r>   	cast_coderesultis_typer=   r%   is_pyobjectAssertionError	py_result)r,   r(   op_typer   r   r   rJ      s    rJ   c             C   s"   x|D ]}t | |drdS qW dS )NFT)r   )r   typesattrr   r   r   re      s    
re   c             C   s   | j pt| jS )N)r=   r   r&   )noder   r   r   !is_pythran_supported_node_or_none   s    rm   c             C   s   d}t | |pt| S )Nr$   r>   r   ra   r=   rb   )r$   r>   r   ra   r=   rb   )re   r$   )r   pythran_supportedr   r   r   r      s    r   c             C   s   d}t | |pt| S )Nr$   r>   r   ra   rb   )r$   r>   r   ra   rb   )re   r$   )r   rn   r   r   r   #is_pythran_supported_operation_type   s    ro   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cstrided)rp   rq   )is_numpy_bufferr   r   modecast)r   r   r   r   is_pythran_buffer   s    ru   c             C   s   t | } ddj|  S )Nzpythonic/numpy/%s.hpp/)rQ   r#   )rL   r   r   r   pythran_get_func_include_file   s    rw   c          
   C   s   | j d | j d | j d | j d | j d | j d | j d x(dD ] }| j d|  | j d|  qLW xdD ]}| j d|  qvW d S )Nzpythonic/core.hppzpythonic/python/core.hppzpythonic/types/bool.hppzpythonic/types/ndarray.hppzpythonic/numpy/power.hppzpythonic/__builtin__/slice.hppz<new>          @   zpythonic/types/uint%d.hppzpythonic/types/int%d.hppfloatfloat32float64setrD   tupler;   complex	complex64
complex128zpythonic/types/%s.hpp)rx   ry   rz   r{   )
r|   r}   r~   r   rD   r   r;   r   r   r   )add_include_file)r   itr   r   r   include_pythran_generic   s    







r   )r   r	   )r   )N))
__future__r   
PyrexTypesr   r   r   cythonrW   r   mapr;   __version__splitr"   ImportErrorr   ccallr   r%   cfuncr+   r/   r0   r8   rB   rM   rN   rO   rQ   rU   r]   r`   rJ   re   rm   r   ro   r$   ru   rw   r   r   r   r   r   <module>   sF   &

	

	