o
    fc                     @   s  d dl mZ ddlmZmZmZ d dlZz(d 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yK   dZd
Zd
ZY nw erQd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u rd&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 u rdS t | dd }|o|ddS )NF
directives
np_pythran)getattrget)envr    r   S/var/www/html/mig_web/myenv/lib/python3.10/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 rA| j| j}}t|tr|j}nt|tr| }nt|tr&|j	}nt
d| tr5d|||f S d||dd| f S | jrG| jS | jrN|  S t
d| t| f )Nzunsupported type %s!zpythonic::types::%s<%s,%d>z3pythonic::types::%s<%s,pythonic::types::pshape<%s>>,)longz unsupported pythran type %s (%s))	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_ref?   s   r1   c                 C   s2   | dkrdt |t |f S dt || t |f 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_typeD   s   r6   c                 C   s   d| t |f S )Nzdecltype(%sstd::declval<%s>())r2   )r3   r   r   r   r   pythran_unaryop_typeM   s   r7   c                    s4   d  fdd|D }t|dkrd| S 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)r;   indicesindexingr   r:   r   _index_accessR   s   r@   c                 C   sf   | \}}|j rdt|jj  }dtddg| f S |jr%d|  S |jr-d|j	 S t
d| )Nr   z"pythonic::%s::functor::slice{}(%s)r   0std::declval<%s>()zunsupported indexing type %s!)is_sliceintstepis_nonepythran_builtinsr)   is_intr%   r*   r+   r'   )index_with_typer9   
index_typenr   r   r   _index_type_codeX   s   
rL   c                 C   s~   | j r(| j| j| jf}| jjrd}|d d }nd}d|ddd |D f S | jjr0t| S | jj	r8| 
 S td| j )	Ncontiguous_slicer   slicezpythonic::types::%s(%s)r   c                 s   s    | ]}|  V  qd S r   )pythran_result)r8   vr   r   r   	<genexpr>o   s    z_index_code.<locals>.<genexpr>zunsupported indexing type %s)rC   startstoprE   rF   r)   r,   rH   
to_pythranr*   rO   r'   )r9   valuesfuncr   r   r   _index_codef   s   rW   c                 C   s   t dt| tt|f S )Nzdecltype(std::declval<%s>()%s))r1   r+   r@   rL   )r   r>   r   r   r   pythran_indexing_typew   s   rX   c                 C   s
   t t| S r   )r@   rW   )r>   r   r   r   pythran_indexing_code~   s   
rY   c                 C   s   | j sg S t| j| jg S r   )is_numpy_attributenp_func_to_listobj	attributerV   r   r   r   r[      s   r[   c                 C   s   dS )NFr   )namer   r   r   pythran_is_numpy_func_supported   s   r`   c                 C   s<   t jjd }t| }|D ]}||d }|d u r dS qdS )NnumpyFT)pythrantablesMODULESr[   r   )rV   CurFFLFr   r   r   r`      s   c                 C   s0   t | } d| d d dg }d|| d f S )Nz::functorzpythonic::numpy::%s::%sr[   r)   )rV   
submodulesr   r   r   pythran_functor   s   rl   c                 C   s$   d dd |D }dt| |f S )Nr   c                 s   s    | ]
}d t |j V  qdS )rB   N)r+   r,   )r8   ar   r   r   rQ      s    z$pythran_func_type.<locals>.<genexpr>zdecltype(%s{}(%s)))r)   rl   )rV   argsr   r   r   pythran_func_type   s   ro   c                 C   sj   | j }|jr||  S t|g dr|  S | jrdt S |d u r't|}| j js-J d|| 	 f S )N)r*   r   is_float
is_complexzpythonic::%s::Nonezfrom_python<%s>(%s))
r,   rH   	cast_coderesultis_typerF   rG   r+   is_pyobject	py_result)r3   r.   op_typer   r   r   rT      s   rT   c                 C   s    |D ]}t | |dr dS qdS )NFT)r   )r   typesattrr   r   r   rt      s
   rt   c                 C   s   | j pt| jS r   )rF   r   r,   )noder   r   r   !is_pythran_supported_node_or_none   s   r{   c                 C      d}t | |p
t| S )N)r*   rH   r   rp   rF   rq   rt   r*   r   pythran_supportedr   r   r   r      s   r   c                 C   r|   )N)r*   rH   r   rp   rq   r}   r~   r   r   r   #is_pythran_supported_operation_type   s   r   c                 C   s   | j S r   )r*   r   r   r   r   r*      s   r*   c                 C   s"   | j ot| jo| jdv o| j S )N)cstrided)is_numpy_bufferr   r#   modecastr   r   r   r   is_pythran_buffer   s
   r   c                 C   s   t | } dd|  S )Nzpythonic/numpy/%s.hpp/rj   r^   r   r   r   pythran_get_func_include_file   s   r   c                 C   s   |  d |  d |  d |  d |  d |  dt  |  d dD ]}|  d	|  |  d
|  q'dD ]	}|  d|  q: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)
floatfloat32float64setrN   tuplerD   complex	complex64
complex128zpythonic/types/%s.hpp)add_include_filerG   )r   itr   r   r   include_pythran_generic   s   





r   )r   r   )+
__future__r   
PyrexTypesr   r   r   cythonrb   r   maprD   __version__splitr(   pythran_is_pre_0_9_6ImportErrorrG   r   ccallr   r+   cfuncr1   r6   r7   r@   rL   rW   rX   rY   r[   r`   rl   ro   rT   rt   r{   r   r   r*   r   r   r   r   r   r   r   <module>   s`   "&


	

	


