3
hT              R   @   s  d Z ddlZddlZddlZddlmZ ddlmZ ddlmZ ddd	d
dddddddddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLdMdNdOdPdQdRdSdTdUdVdWdXgRZ	ej
ZejjZejZi Zg ZdZdYdT ZdZd Zd[d\ Zd]dD Zd^d_ Zd`dE Zdad Zdbd ZdcdB Zddd Zded5 Zdfd( Zdgdh Zdidj Z dkd: Z!dldK Z"dmdO Z#dndJ Z$dodM Z%dpd" Z&dqd8 Z'drd7 Z(dsd Z)dtd' Z*dudL Z+dvdP Z,dwdx Z-dydN Z.dzd{ Z/d|d} Z0d~d Z1ddC Z2dd Z3dd Z4dd= Z5dd< Z6dd% Z7dd& Z8ddG Z9ddH Z:dd Z;ddA Z<dd6 Z=dd; Z>dd9 Z?dd  Z@dd! ZAddF ZBdd ZCddI ZDdd ZEdd> ZFdd$ ZGdd@ ZHdd/ ZIdd0 ZJdd3 ZKdd. ZLdd2 ZMdd* ZNdd ZOdd, ZPdd4 ZQdd+ ZRdd1 ZSdd) ZTdd ZUdd ZVdd ZWeIdeJdeKdeLdeOdeNdeFdeSdeUdeVdeWdiZXdd? ZYdd ZZdd Z[dd Z\dd Z]dd Z^dd Z_dd Z`dd Zadd ZbddƄ ZcddȄ ZdG ddʄ deeZfG ddX dXZgddQ ZhddS ZiddR Zjdd# Zkdd Zlddd҄Zmdd Zni fddZodd Zpdd Zqdd Zrddل Zsdd Ztdd Zudd Zvddބ ZwddW ZxdddUZydd	 Zzi fddZ{dS )aW  

Auxiliary functions for f2py2e.

Copyright 1999,2000 Pearu Peterson all rights reserved,
Pearu Peterson <pearu@ioc.ee>
Permission to use, modify, and distribute this software is given under the
terms of the NumPy (BSD style) LICENSE.


NO WARRANTY IS EXPRESSED OR IMPLIED.  USE AT YOUR OWN RISK.
$Date: 2005/07/24 19:01:55 $
Pearu Peterson

    N)reduce   )__version__)cfuncs
applyrules	debugcapi
dictappenderrmessgentitlegetargs2getcallprotoargumentgetcallstatementgetfortrannamegetpymethoddef
getrestdocgetusercodegetusercode1hasbodyhascallstatement	hascommonhasexternalshasinitvaluehasnotehasresultnoteisallocatableisarrayisarrayofstrings	iscomplexiscomplexarrayiscomplexfunctioniscomplexfunction_warnisdoubleisdummyroutine
isexternal
isfunctionisfunction_wrapisint1array	isintegerisintent_aux
isintent_cisintent_callbackisintent_copyisintent_dictisintent_hideisintent_inisintent_inoutisintent_inplaceisintent_nothideisintent_outisintent_overwrite	islogicalislogicalfunctionislong_complexislong_doubleislong_doublefunctionislong_longislong_longfunctionismoduleismoduleroutine
isoptional	isprivate
isrequired	isroutineisscalarissigned_long_longarrayisstringisstringarrayisstringfunctionissubroutineissubroutine_wrapisthreadsafe
isunsignedisunsigned_charisunsigned_chararrayisunsigned_long_longisunsigned_long_longarrayisunsigned_shortisunsigned_shortarrayl_andl_notl_oroutmessreplaceshow
stripcommathrow_errorc             C   s   t jddrtjj|  d S )Nverboser   )optionsgetsysstdoutwrite)t r_   4/tmp/pip-build-fibhr3ey/numpy/numpy/f2py/auxfuncs.pyrS   >   s    c             C   s   dt kS )NZcapi)debugoptions)varr_   r_   r`   r   C   s    c             C   s   d| ko| d dkot |  S )Ntypespec	character)r#   )rb   r_   r_   r`   	_isstringG   s    re   c             C   s   t | ot|  S )N)re   r   )rb   r_   r_   r`   rC   L   s    c             C   s   t | od| kS )NZcharselector)rC   )rb   r_   r_   r`   ischaracterP   s    rf   c             C   s   t | ot| S )N)r   re   )rb   r_   r_   r`   rD   T   s    c             C   s   t | o| d d dkS )N	dimensionr   z(*))rD   )rb   r_   r_   r`   r   X   s    c             C   s   d| kot |  S )Nrg   )r#   )rb   r_   r_   r`   r   ^   s    c             C   s   t | pt| pt|  S )N)r   rC   r#   )rb   r_   r_   r`   rA   b   s    c             C   s   t | o| jddkS )Nrc   complexdouble complex)ri   rj   )rA   rZ   )rb   r_   r_   r`   r   f   s    c             C   s   t | o| jddkS )Nrc   logical)rA   rZ   )rb   r_   r_   r`   r4   k   s    c             C   s   t | o| jddkS )Nrc   integer)rA   rZ   )rb   r_   r_   r`   r'   o   s    c             C   s   t | o| jddkS )Nrc   real)rA   rZ   )rb   r_   r_   r`   isreals   s    rn   c             C   sH   y| d d S  t k
rB   y| d d S  t k
r<   Y nX Y nX d S )NZkindselector*kind)KeyError)rb   r_   r_   r`   get_kindw   s    rr   c             C   s*   t | sdS | jddkrdS t| dkS )Nr   rc   rl   rk   8)rl   rk   )rA   rZ   rr   )rb   r_   r_   r`   r9      s
    c             C   s*   t | sdS | jddkrdS t| dkS )Nr   rc   rl   z-1)rA   rZ   rr   )rb   r_   r_   r`   rJ      s
    c             C   s*   t | sdS | jddkrdS t| dkS )Nr   rc   rl   z-2)rA   rZ   rr   )rb   r_   r_   r`   rN      s
    c             C   s*   t | sdS | jddkrdS t| dkS )Nr   rc   rl   z-4)rA   rZ   rr   )rb   r_   r_   r`   rI      s
    c             C   s*   t | sdS | jddkrdS t| dkS )Nr   rc   rl   z-8)rA   rZ   rr   )rb   r_   r_   r`   rL      s
    c             C   s*   t | sdS | jddksdS t| dkS )Nr   rc   rm   rs   )rA   rZ   rr   )rb   r_   r_   r`   r!      s
    c             C   s*   t | sdS | jddksdS t| dkS )Nr   rc   rm   Z16)rA   rZ   rr   )rb   r_   r_   r`   r7      s
    c             C   s   t | sdS t| dkS )Nr   Z32)r   rr   )rb   r_   r_   r`   r6      s    c             C   s   t | o| jddkS )Nrc   ri   double complex)ri   rt   )r   rZ   )rb   r_   r_   r`   r      s    c             C   s"   t | o | jddko t| dkS )Nrc   rl   1)r   rZ   rr   )rb   r_   r_   r`   r&      s    c             C   s"   t | o | jddko t| dkS )Nrc   rl   rk   z-1)rl   rk   )r   rZ   rr   )rb   r_   r_   r`   rK      s    c             C   s"   t | o | jddko t| dkS )Nrc   rl   rk   z-2)rl   rk   )r   rZ   rr   )rb   r_   r_   r`   rO      s    c             C   s"   t | o | jddko t| dkS )Nrc   rl   rk   z-4)rl   rk   )r   rZ   rr   )rb   r_   r_   r`   isunsignedarray   s    rv   c             C   s"   t | o | jddko t| dkS )Nrc   rl   rk   z-8)rl   rk   )r   rZ   rr   )rb   r_   r_   r`   rM      s    c             C   s"   t | o | jddko t| dkS )Nrc   rl   rk   ru   )rl   rk   )r   rZ   rr   )rb   r_   r_   r`   issigned_chararray   s    rw   c             C   s"   t | o | jddko t| dkS )Nrc   rl   rk   2)rl   rk   )r   rZ   rr   )rb   r_   r_   r`   issigned_shortarray   s    ry   c             C   s"   t | o | jddko t| dkS )Nrc   rl   rk   4)rl   rk   )r   rZ   rr   )rb   r_   r_   r`   issigned_array   s    r{   c             C   s"   t | o | jddko t| dkS )Nrc   rl   rk   rs   )rl   rk   )r   rZ   rr   )rb   r_   r_   r`   rB      s    c             C   s   d| kod| d kS )NattrspecZallocatabler_   )rb   r_   r_   r`   r      s    c             C   s   d| kpt |  S )Nrg   )rC   )rb   r_   r_   r`   	ismutable   s    r}   c             C   s   d| kS )N
modulenamer_   )routr_   r_   r`   r<      s    c             C   s   d| kod| d kS )Nblockmoduler_   )r   r_   r_   r`   r;      s    c             C   s   d| kod| d kS )Nr   functionr_   )r   r_   r_   r`   r$     s    c             C   s"   t | rdS to t| o t|  S )Nr   )r)   	wrapfuncsr$   r#   )r   r_   r_   r`   r%     s    c             C   s   d| kod| d kS )Nr   Z
subroutiner_   )r   r_   r_   r`   rF   
  s    c             C   s   t | rdS t| ot| S )Nr   )r)   rF   hasassumedshape)r   r_   r_   r`   rG     s    c             C   sZ   | j drdS xF| d D ]:}x4| d j |i j dg D ]}|dkr6d| d< dS q6W qW dS )Nr   Targsvarsrg   :F)rZ   )r   adr_   r_   r`   r     s    
r   c             C   s   t | pt| S )N)r$   rF   )r   r_   r_   r`   r@     s    c             C   sF   t | sdS d| kr| d }n| d }|| d krBt| d | S dS )Nr   resultnamer   )r$   r4   )r   r   r_   r_   r`   r5   #  s    
c             C   sF   t | sdS d| kr| d }n| d }|| d krBt| d | S dS )Nr   r   r   r   )r$   r9   )r   r   r_   r_   r`   r:   /  s    
c             C   sF   t | sdS d| kr| d }n| d }|| d krBt| d | S dS )Nr   r   r   r   )r$   r7   )r   r   r_   r_   r`   r8   ;  s    
c             C   sF   t | sdS d| kr| d }n| d }|| d krBt| d | S dS )Nr   r   r   r   )r$   r   )r   r   r_   r_   r`   r   G  s    
c             C   s   t | rtd dS dS )Na      **************************************************************
        Warning: code with a function returning complex value
        may not work correctly with your Fortran compiler.
        Run the following test before using it in your applications:
        $(f2py install dir)/test-site/{b/runme_scalar,e/runme}
        When using GNU gcc/g77 compilers, codes should work correctly.
    **************************************************************
r   r   )r   rS   )r   r_   r_   r`   r    S  s
    c             C   sF   t | sdS d| kr| d }n| d }|| d krBt| d | S dS )Nr   r   r   r   )r$   rC   )r   r   r_   r_   r`   rE   a  s    
c             C   s   d| ko| d S )NZ	externalsr_   )r   r_   r_   r`   r   m  s    c             C   s   d| kod| d kS )Nf2pyenhancementsZ
threadsafer_   )r   r_   r_   r`   rH   q  s    c             C   s   d| ko| d S )Nr   r_   )r   r_   r_   r`   hasvariablesv  s    r   c             C   s(   d| ko&d| d ko&d| d ko&t | S )Nr|   optionalrequired)r1   )rb   r_   r_   r`   r=   z  s    c             C   s   d| kod| d kS )Nr|   Zexternalr_   )rb   r_   r_   r`   r#     s    c             C   s   t |  ot| S )N)r=   r1   )rb   r_   r_   r`   r?     s    c             C   sp   d| krdS d| d krdS d| d kr,dS d| d kr<dS d| d krLdS d| d kr\dS d	| d krldS dS )
Nintentr   hider   inplaceinoutinoutoutinr_   )rb   r_   r_   r`   r.     s    c             C   sD   d| koBd| d ks d| d koBd| d koBd| d koBd| d kS )Nr   r   r   r   r   r   r_   )rb   r_   r_   r`   r/     s    c             C   s   d| j dg kS )Nr   r   )rZ   )rb   r_   r_   r`   r2     s    c             C   s<   d| ko:d| d kp:d| d ko:d| d ko:t tt|  S )Nr   r   r   r   )rR   r/   r0   )rb   r_   r_   r`   r-     s    c             C   s
   t |  S )N)r-   )rb   r_   r_   r`   r1     s    c             C   s   d| j dg kS )Ncr   )rZ   )rb   r_   r_   r`   r)     s    c             C   s   d| j dg kS )Ncacher   )rZ   )rb   r_   r_   r`   isintent_cache  s    r   c             C   s   d| j dg kS )Ncopyr   )rZ   )rb   r_   r_   r`   r+     s    c             C   s   d| j dg kS )N	overwriter   )rZ   )rb   r_   r_   r`   r3     s    c             C   s   d| j dg kS )Ncallbackr   )rZ   )rb   r_   r_   r`   r*     s    c             C   s   d| j dg kS )Nr   r   )rZ   )rb   r_   r_   r`   r0     s    c             C   s   d| j dg kS )NZauxr   )rZ   )rb   r_   r_   r`   r(     s    c             C   s   d| j dg kS )NZaligned4r   )rZ   )rb   r_   r_   r`   isintent_aligned4  s    r   c             C   s   d| j dg kS )NZaligned8r   )rZ   )rb   r_   r_   r`   isintent_aligned8  s    r   c             C   s   d| j dg kS )NZ	aligned16r   )rZ   )rb   r_   r_   r`   isintent_aligned16  s    r   Z	INTENT_INZINTENT_INOUTZ
INTENT_OUTZINTENT_HIDEZINTENT_CACHEZINTENT_COPTIONALZINTENT_INPLACEZINTENT_ALIGNED4ZINTENT_ALIGNED8ZINTENT_ALIGNED16c             C   s   d| kod| d kS )Nr|   Zprivater_   )rb   r_   r_   r`   r>     s    c             C   s   d| kS )N=r_   )rb   r_   r_   r`   r     s    c             C   s   t | sdS | d d dkS )Nr   r   "')r   r   )r   )rb   r_   r_   r`   hasinitvalueasstring  s    r   c             C   s   d| kS )NZnoter_   )rb   r_   r_   r`   r     s    c             C   sF   t | sdS d| kr| d }n| d }|| d krBt| d | S dS )Nr   r   r   r   )r$   r   )r   r   r_   r_   r`   r     s    
c             C   s   d| kS )Ncommonr_   )r   r_   r_   r`   r     s    c             C   s6   t | rdS t| r2x| d D ]}t|rdS qW dS )Nr   bodyr   )r   r   containscommon)r   br_   r_   r`   r      s    r   c             C   s:   t | rdS t| sdS x| d D ]}t|r"dS q"W dS )Nr   r   r   )r;   r   containsmodule)r   r   r_   r_   r`   r   
  s    r   c             C   s   d| kS )Nr   r_   )r   r_   r_   r`   r     s    c             C   s   t | d k	S )N)r   )r   r_   r_   r`   r     s    c             C   s   dS )Nr   r_   )rb   r_   r_   r`   istrue  s    r   c             C   s   dS )Nr   r_   )rb   r_   r_   r`   isfalse!  s    r   c               @   s   e Zd ZdS )	F2PYErrorN)__name__
__module____qualname__r_   r_   r_   r`   r   %  s   r   c               @   s   e Zd Zdd Zdd ZdS )rW   c             C   s
   || _ d S )N)mess)selfr   r_   r_   r`   __init__+  s    zthrow_error.__init__c             C   s   d|| j f }t|d S )Nz

  var = %s
  Message: %s
)r   r   )r   rb   r   r_   r_   r`   __call__.  s    zthrow_error.__call__N)r   r   r   r   r   r_   r_   r_   r`   rW   )  s   c              G   sR   dg  }}x0t t| D ] }d|||f }|jd|  qW td|dj|f S )Nzlambda vz%s,f%d=f[%d]zf%d(v)z%s:%sz and )rangelenappendevaljoin)fll2ir_   r_   r`   rP   3  s
    
c              G   sR   dg  }}x0t t| D ] }d|||f }|jd|  qW td|dj|f S )Nzlambda vz%s,f%d=f[%d]zf%d(v)z%s:%sz or )r   r   r   r   r   )r   r   r   r   r_   r_   r`   rR   ;  s
    
c             C   s   t dS )Nzlambda v,f=f:not f(v))r   )r   r_   r_   r`   rQ   C  s    c             C   s*   y| d d dkS  t k
r$   dS X d S )Nr   fortranname r   )rq   )r   r_   r_   r`   r"   G  s    c             C   sV   y4| d d }|dkrt |s2td| d   t W n t k
rP   | d }Y nX |S )Nr   r   r   z"Failed to use fortranname from %s
r   )rq   r	   )r   r   r_   r_   r`   r   N  s    c             C   s  y| d j |}W n tk
r&   d S X |s0d S |dkrFt|trFd S t|trh|t|kr`d S || }|d d dkr|rd| d t| d |dd   }n|dd  }|dd  dkr|r|d d d t| d	 }n|d d }ntd
|t|f  |S )Nr   r      z'''z
	/* start z multiline (z) */
z
	/* end multiline (z)*/z-%s multiline block should end with `'''`: %s
r   r   )rZ   rq   
isinstancestrlistr   reprr	   )r   Z	blocknamecommentcounterrr_   r_   r`   getmultilineblock\  s.    
&r   c             C   s
   t | dS )NZcallstatement)r   )r   r_   r_   r`   r   z  s    c       
      C   s  t | ddd}|r|S t| r*td d S ddlm} g g  }}tttt| r`|j	ddg x| d	 D ]}| d
 | }t
|rqj||kr|| d }nJ||}ttttt|rnt|rn|d }t|st|r|jd |j| qjW dj|| }	|	s
d}	|	S )NZcallprotoargumentr   )r   z<warning: callstatement is defined without callprotoargument
r   )getctypezchar*Zsize_tr   r   Z_typedefro   ,void)r   r   rS   Z	capi_mapsr   rP   rE   rQ   r%   extendr*   r)   rR   rA   r   rC   r   r   r   )
r   Zcb_mapr   r   Z	arg_typesZ
arg_types2nrb   ctypeZ
proto_argsr_   r_   r`   r   ~  s<    

c             C   s
   t | dS )Nusercode)r   )r   r_   r_   r`   r     s    c             C   s   t | dddS )Nr   r   )r   )r   )r   r_   r_   r`   r     s    c             C   s
   t | dS )NZpymethoddef)r   )r   r_   r_   r`   r     s    c             C   sx   g g  }}d| krp| d }d| krhx"| d D ]}||kr,|j | q,W x(|D ]}||krL|j | qLW n| d }||fS )Nr   sortvars)r   )r   sortargsr   r   r_   r_   r`   getargs  s    

r   c                s   g j dg  }  fddd j D }|   dkrx"d D ]}| krH|j| qHW x, D ]}||krh|j| qhW n|d  } |fS )Nr   c                s(   g | ] }t d  | r| kr|qS )r   )r(   ).0r   )r   r   r_   r`   
<listcomp>  s    zgetargs2.<locals>.<listcomp>r   r   )rZ   keysr   )r   r   Zauxvarsr   r_   )r   r   r`   r     s    
c             C   s<   d| krd S d }| d dkr,| d | d f}| d j |d S )NZf2pymultilinesr   zpython moduler   )rZ   )r   kr_   r_   r`   r     s    c             C   s*   dt |  d d }d|d | |d f S )NP         z/*%s %s %s*/ro   )r   )r   r   r_   r_   r`   r
     s    c             C   s$   t | trttfdd| g S | gS )Nc             S   s   | || S )Nr_   )xyr   r_   r_   r`   <lambda>  s    zflatlist.<locals>.<lambda>)r   r   r   flatlist)r   r_   r_   r`   r     s    
r   c             C   s    | r| d dkr| d d S | S )Nr   r   rh   rh   r_   )sr_   r_   r`   rV     s    r   c                s   t  trfdd D S t tr< fddD S xdt j  D ]v}|dkr\qNd kr~| d kr~ d | }n}t  | trjd| |jt | qNjd|  | qNW S )Nc                s   g | ]}t | qS r_   )rT   )r   _m)
defaultsepr   r_   r`   r     s    zreplace.<locals>.<listcomp>c                s   g | ]}t | qS r_   )rT   )r   r   )r   r   r_   r`   r     s    r   separatorsforz#%s#)r   r   r   rT   r   r   )r   r   r   r   sepr_   )r   r   r   r`   rT     s    

 c             C   s@  t |tr&x|D ]}t| |} qW | S x|j D ]}|d dkrFq2|| kr,t | | trl| | g| |< t | | trt || tr| | ||  | |< n| | j||  nxt | | tr8t || tr8|dkrxL|| j D ]$}|| | kr|| | | | |< qW nt| | || | |< q2|| | |< q2W | S )Nr   _r   )r   r   r   r   r   r   dict)rdarr   r   k1r_   r_   r`   r     s.    



c             C   s  i }t | tr@x,| D ]$}t|||}t||}d|krP qW |S d| krZ| d | rZ|S d| krtd| d i||}d|krtj|d  x | j D ]}|dkr| | ||< qt | | trt| | |||< nt | | tr0g ||< x:| | D ].}t||i||}	||	kr|| j	|	|  qW n:|d dkrDqn&t | | t
rVg ||< x| | j D ]}
t |
tjrj|
|rjt | | |
 trx| | |
 D ]N}t |t
rtd|i||}d|kr|d }nd	}|| j	t|| qW nR| | |
 }t |t
r:td|i|}d|kr6|d }nd	}|| j	t|| qjW ntd
t| |   t || trt|| dkr|| d ||< || g kr||= qW |S )N_break_checkZneedZneedsr   r   r   Z	supertextr   zapplyrules: ignoring rule %s.
r   )r   r   r   r   r   Zappend_needsr   r   rT   r   r   typesFunctionTyper	   r   r   )rulesr   rb   retr   Zrrresr   r   r   r   r_   r_   r`   r     sl    







)r   r   )r   )|__doc__pprintr[   r   	functoolsr   r   r   r   __all__versionZf2py_versionstderrr]   r	   rU   rY   ra   r   rS   r   re   rC   rf   rD   r   r   rA   r   r4   r'   rn   rr   r9   rJ   rN   rI   rL   r!   r7   r6   r   r&   rK   rO   rv   rM   rw   ry   r{   rB   r   r}   r<   r;   r$   r%   rF   rG   r   r@   r5   r:   r8   r   r    rE   r   rH   r   r=   r#   r?   r.   r/   r2   r-   r1   r)   r   r+   r3   r*   r0   r(   r   r   r   r,   r>   r   r   r   r   r   r   r   r   r   r   r   	Exceptionr   rW   rP   rR   rQ   r"   r   r   r   r   r   r   r   r   r   r   r
   r   rV   rT   r   r   r_   r_   r_   r`   <module>   s"  






$	
