o
    1Y e6_                     @   sr  d Z ddl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l	mZ g dZe
jZejjZejZi Zg ZdZd	d
 Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Zdd Z dd  Z!d!d" Z"d#d$ Z#d%d& Z$d'd( Z%d)d* Z&d+d, Z'd-d. Z(d/d0 Z)d1d2 Z*d3d4 Z+d5d6 Z,d7d8 Z-d9d: Z.d;d< Z/d=d> Z0d?d@ Z1dAdB Z2dCdD Z3dEdF Z4dGdH Z5dIdJ Z6dKdL Z7dMdN Z8dOdP Z9dQdR Z:dSdT Z;dUdV Z<dWdX Z=dYdZ Z>d[d\ Z?d]d^ Z@d_d` ZAdadb ZBdcdd ZCdedf ZDdgdh ZEdidj ZFdkdl ZGdmdn ZHdodp ZIdqdr ZJdsdt ZKdudv ZLdwdx ZMdydz ZNd{d| ZOd}d~ ZPdd ZQdd ZRdd ZSdd ZTdd ZUdd ZVdd ZWdd ZXdd ZYdd ZZdd Z[dd Z\dd Z]dd Z^dd Z_dd Z`dd Zadd ZbeTdeUdeVdeWdeZdeYdePde^de`deadebdiZcdd Zddd Zedd Zfdd Zgdd Zhdd Zidd Zjdd Zkdd Zldd ZmddÄ Znddń ZoG ddǄ depZqG ddɄ dɃZrdd˄ Zsdd̈́ Ztddτ Zuddф Zvddӄ ZwdddՄZxddׄ Zyi fddلZzddۄ Z{dd݄ Z|dd߄ Z}dd Z~dd Zdd Zdd Zdd Zdd ZdddZdd Zi fddZdd ZedejjZedejjZdd Zd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)deepcopy   )__version__)cfuncs)[
applyrules	debugcapi
dictappenderrmessgentitlegetargs2getcallprotoargumentgetcallstatementgetfortrannamegetpymethoddef
getrestdocgetusercodegetusercode1getdimensionhasbodyhascallstatement	hascommonhasexternalshasinitvaluehasnotehasresultnoteisallocatableisarrayisarrayofstringsischaracterischaracterarrayischaracter_or_characterarray	iscomplexiscomplexarrayiscomplexfunctioniscomplexfunction_warnisdoubleisdummyroutine
isexternal
isfunctionisfunction_wrapisint1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isstring_or_stringarrayisstringfunctionissubroutineget_f2py_modulename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_errorisattr_value
deep_mergec                 C   s    t ddrtj|  d S d S )Nverboser   )optionsgetsysstdoutwrite)t ri   B/var/www/myenv/lib/python3.10/site-packages/numpy/f2py/auxfuncs.pyr[   D   s   r[   c                 C   s   dt v S )Ncapi)debugoptionsvarri   ri   rj   r   I      r   c                 C      d| v o| d dkot |  S Ntypespec	characterr(   rm   ri   ri   rj   _ischaracterM      ru   c                 C   rp   rq   rt   rm   ri   ri   rj   	_isstringR   rv   rw   c                 C   s   t | od| vS Ncharselectorru   rm   ri   ri   rj   r!   W      r!   c                 C      t | ot|  S Nr!   r   rm   ri   ri   rj   r   [      r   c                 C      t | ot| S r}   r~   rm   ri   ri   rj   r    _   r{   r    c                 C   s   t | od| v S rx   rz   rm   ri   ri   rj   rK   c   r{   rK   c                 C   r|   r}   rK   r   rm   ri   ri   rj   rI   g   r   rI   c                 C   r   r}   r   rm   ri   ri   rj   rJ   k   r{   rJ   c                 C   s   t | o| d d dkS )N	dimensionz(*))rJ   rm   ri   ri   rj   r   o   s   r   c                 C   s   d| v ot |  S Nr   rt   rm   ri   ri   rj   r   u   r   r   c                 C   s   t | pt| pt|  S r}   )r   rI   r(   rm   ri   ri   rj   rG   y   s   rG   c                 C      t | o
| ddv S Nrr   )complexzdouble complexrG   rd   rm   ri   ri   rj   r"   }      r"   c                 C      t | o
| ddkS )Nrr   logicalr   rm   ri   ri   rj   r:         r:   c                 C   r   )Nrr   integerr   rm   ri   ri   rj   r-      r   r-   c                 C   r   )Nrr   realr   rm   ri   ri   rj   isreal   r   r   c                 C   sH   z| d d W S  t y#   z	| d d W  Y S  t y"   Y Y d S w w )Nkindselector*kindKeyErrorrm   ri   ri   rj   get_kind   s   r   c                 C   s$   |  ddkot| dkot|  S Nrr   r   1)rd   r   r   rm   ri   ri   rj   r+      s
   
r+   c                 C   s*   t | sdS | ddvrdS t| dkS )Nr   rr   r   r   8rG   rd   r   rm   ri   ri   rj   r?      
   r?   c                 C   *   t | sdS | ddkrdS t| dkS )Nr   rr   r   -1r   rm   ri   ri   rj   rR      r   rR   c                 C   r   )Nr   rr   r   -2r   rm   ri   ri   rj   rV      r   rV   c                 C   r   )Nr   rr   r   -4r   rm   ri   ri   rj   rQ      r   rQ   c                 C   r   )Nr   rr   r   -8r   rm   ri   ri   rj   rT      r   rT   c                 C   *   t | sdS | ddksdS t| dkS )Nr   rr   r   r   r   rm   ri   ri   rj   r&      r   r&   c                 C   r   )Nr   rr   r   16r   rm   ri   ri   rj   r=      r   r=   c                 C   s   t | sdS t| dkS )Nr   32)r"   r   rm   ri   ri   rj   r<      s   r<   c                 C   r   r   )r   rd   rm   ri   ri   rj   r#      r   r#   c                 C   s"   t | o| ddkot| dkS r   r   rd   r   rm   ri   ri   rj   r,         
r,   c                 C   "   t | o| ddv ot| dkS )Nrr   r   r   r   rm   ri   ri   rj   rS      r   rS   c                 C   r   )Nrr   r   r   r   rm   ri   ri   rj   rW      r   rW   c                 C   r   )Nrr   r   r   r   rm   ri   ri   rj   isunsignedarray   r   r   c                 C   r   )Nrr   r   r   r   rm   ri   ri   rj   rU      r   rU   c                 C   r   )Nrr   r   r   r   rm   ri   ri   rj   issigned_chararray   r   r   c                 C   r   )Nrr   r   2r   rm   ri   ri   rj   issigned_shortarray   r   r   c                 C   r   )Nrr   r   4r   rm   ri   ri   rj   issigned_array  r   r   c                 C   r   )Nrr   r   r   r   rm   ri   ri   rj   rH     r   rH   c                 C      d| v o	d| d v S )Nattrspecallocatableri   rm   ri   ri   rj   r        r   c                 C   s   d| vpt |  S r   )rI   rm   ri   ri   rj   	ismutable  r   r   c                 C      d| v S )N
modulenameri   routri   ri   rj   rB     ro   rB   c                 C      d| v o	d| d kS )Nblockmoduleri   r   ri   ri   rj   rA     r   rA   c                 C   r   )Nr   functionri   r   ri   ri   rj   r)     r   r)   c                 C   s"   t | rdS tot| ot|  S Nr   )r/   	wrapfuncsr)   r(   r   ri   ri   rj   r*   !  s   r*   c                 C   r   )Nr   
subroutineri   r   ri   ri   rj   rM   '  r   rM   c                 C   s   t | rdS t| ot| S r   )r/   rM   hasassumedshaper   ri   ri   rj   rO   +     rO   c                 C      d|  dg v S )Nvaluer   rd   rm   ri   ri   rj   r`   0  r{   r`   c                 C   sV   |  drdS | d D ]}| d  |i  dg D ]}|dkr'd| d<   dS qqdS )Nr   Targsvarsr   :Fr   )r   adri   ri   rj   r   4  s   
r   c                 C      t | pt| S r}   )rB   r   r   ri   ri   rj   requiresf90wrapper?  r{   r   c                 C   r   r}   )r)   rM   r   ri   ri   rj   rF   C  r{   rF   c                 C   F   t | sdS d| v r| d }n| d }|| d v r!t| d | S dS Nr   resultnamer   )r)   r:   r   r   ri   ri   rj   r;   G     
r;   c                 C   r   r   )r)   r?   r   ri   ri   rj   r@   S  r   r@   c                 C   r   r   )r)   r=   r   ri   ri   rj   r>   _  r   r>   c                 C   r   r   )r)   r"   r   ri   ri   rj   r$   k  r   r$   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.
        When using GNU gcc/g77 compilers, codes should work
        correctly for callbacks with:
        f2py -c -DF2PY_CB_RETURNCOMPLEX
    **************************************************************
r   r   )r$   r[   r   ri   ri   rj   r%   w  s   r%   c                 C   r   r   )r)   rI   r   ri   ri   rj   rL     r   rL   c                 C      d| v o| d S )N	externalsri   r   ri   ri   rj   r     r{   r   c                 C   r   )Nf2pyenhancements
threadsaferi   r   ri   ri   rj   rP     s   
rP   c                 C   r   )Nr   ri   r   ri   ri   rj   hasvariables  r{   r   c                 C   s(   d| v od| d v od| d vot | S )Nr   optionalrequired)r7   rm   ri   ri   rj   rC     s
   
rC   c                 C   r   )Nr   externalri   rm   ri   ri   rj   r(     r   r(   c                    sH   d d|   v r tdd | d D r" fdd| d D d S d S d S )Nz	\((.*?)\)r   c                 s   s    | ]}d |v V  qdS )r   Nri   ).0sri   ri   rj   	<genexpr>  s    zgetdimension.<locals>.<genexpr>c                    s   g | ]}t  |qS ri   )refindall)r   v
dimpatternri   rj   
<listcomp>      z getdimension.<locals>.<listcomp>r   )keysanyrm   ri   r   rj   r     s   r   c                 C   s   t |  ot| S r}   )rC   r7   rm   ri   ri   rj   rE     r   rE   c                 C   sp   d| vrdS d| d v rdS d| d v rdS d| d v rdS d| d v r&dS d| d v r.dS d	| d v r6dS dS )
Nintentr   hider   inplaceinoutinoutoutinri   rm   ri   ri   rj   r4     s   r4   c                 C   sD   d| v o!d| d v sd| d v o!d| d vo!d| d vo!d| d vS )Nr   r   r   r   r   r   ri   rm   ri   ri   rj   r5     s   



r5   c                 C   r   )Nr   r   r   rm   ri   ri   rj   r8     r{   r8   c                 C   s<   d| v od| d v pd| d v od| d vot tt|  S )Nr   r   r   r   )rZ   r5   r6   rm   ri   ri   rj   r3     s   r3   c                 C   s
   t |  S r}   )r3   rm   ri   ri   rj   r7        
r7   c                 C   r   )Ncr   r   rm   ri   ri   rj   r/     r{   r/   c                 C   r   )Ncacher   r   rm   ri   ri   rj   isintent_cache  r{   r   c                 C   r   )Ncopyr   r   rm   ri   ri   rj   r1     r{   r1   c                 C   r   )N	overwriter   r   rm   ri   ri   rj   r9     r{   r9   c                 C   r   )Ncallbackr   r   rm   ri   ri   rj   r0     r{   r0   c                 C   r   )Nr   r   r   rm   ri   ri   rj   r6     r{   r6   c                 C   r   )Nauxr   r   rm   ri   ri   rj   r.     r{   r.   c                 C   r   )Naligned4r   r   rm   ri   ri   rj   isintent_aligned4  r{   r   c                 C   r   )Naligned8r   r   rm   ri   ri   rj   isintent_aligned8  r{   r   c                 C   r   )N	aligned16r   r   rm   ri   ri   rj   isintent_aligned16  r{   r   	INTENT_ININTENT_INOUT
INTENT_OUTINTENT_HIDEINTENT_CACHEINTENT_COPTIONALINTENT_INPLACEINTENT_ALIGNED4INTENT_ALIGNED8INTENT_ALIGNED16c                 C   r   )Nr   privateri   rm   ri   ri   rj   rD     r   rD   c                 C   r   )N=ri   rm   ri   ri   rj   r     ro   r   c                 C   s   t | sdS | d d dv S )Nr   r  )"')r   rm   ri   ri   rj   hasinitvalueasstring  r   r  c                 C   r   )Nnoteri   rm   ri   ri   rj   r     ro   r   c                 C   r   r   )r)   r   r   ri   ri   rj   r     r   r   c                 C   r   )Ncommonri   r   ri   ri   rj   r   )  ro   r   c                 C   s4   t | rdS t| r| d D ]	}t|r dS qdS )Nr   bodyr   )r   r   containscommon)r   bri   ri   rj   r  -  s   r  c                 C   s8   t | rdS t| sdS | d D ]	}t|r dS qdS )Nr   r   r
  )rA   r   containsmodule)r   r  ri   ri   rj   r  7  s   r  c                 C   r   )Nr
  ri   r   ri   ri   rj   r   B  ro   r   c                 C   s   t | d uS r}   )r   r   ri   ri   rj   r   F  s   r   c                 C      dS )Nr   ri   rm   ri   ri   rj   istrueJ     r  c                 C   r  r   ri   rm   ri   ri   rj   isfalseN  r  r  c                   @   s   e Zd ZdS )	F2PYErrorN)__name__
__module____qualname__ri   ri   ri   rj   r  R  s    r  c                   @   s   e Zd Zdd Zdd ZdS )r_   c                 C   s
   || _ d S r}   )mess)selfr  ri   ri   rj   __init__X  r   zthrow_error.__init__c                 C   s   d|| j f }t|)Nz

  var = %s
  Message: %s
)r  r  )r  rn   r  ri   ri   rj   __call__[  s   zthrow_error.__call__N)r  r  r  r  r  ri   ri   ri   rj   r_   V  s    r_   c                  G   N   dg }}t t| D ]}d|||f }|d|  qtd|d|f S )Nlambda v%s,f%d=f[%d]f%d(v)%s:%sz and rangelenappendevaljoinfl1l2iri   ri   rj   rX   `  
   
rX   c                  G   r  )Nr  r  r  r  z or r  r%  ri   ri   rj   rZ   h  r*  rZ   c                 C   s   t dS )Nzlambda v,f=f:not f(v))r#  )r&  ri   ri   rj   rY   p  ro   rY   c                 C   s(   z	| d d dkW S  t y   Y dS w )Nr   fortranname r   r   r   ri   ri   rj   r'   t  s
   r'   c                 C   sT   z| d d }|dkrt |std| d   t W |S  t y)   | d }Y |S w )Nr   r+  r,  z"Failed to use fortranname from %s
r   )r   r
   )r   r   ri   ri   rj   r   {  s   
r   c                 C   s
  z	| d  |}W n
 ty   Y d S w |sd S |dkr#t|tr#d S t|tr4|t|kr0d S || }|d d dkr|rQd| d t| d |dd   }n|dd  }|dd  dkry|rq|d d d	 t| d
 }|S |d d }|S 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
)rd   r   
isinstancestrlistr!  reprr
   )r   	blocknamecommentcounterrri   ri   rj   getmultilineblock  sF   


r7  c                 C   
   t | dS )Ncallstatementr7  r   ri   ri   rj   r     r   r   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| r0|	ddg | d	 D ]J}| d
 | }t
|rAq4||v rL|| d }n-||}ttttt|r[nt|r`nt|sh|d }t|stt|stt|ry|d || q4d|| }	|	sd}	|	S )Ncallprotoargumentr   )r4  z<warning: callstatement is defined without callprotoargument
r   )getctypezchar*size_tr   r   _typedefr   ,void)r7  r   r[   	capi_mapsr<  rX   rL   rY   r*   extendr0   r/   rZ   rG   r"   rI   r`   r   rJ   r"  r$  )
r   cb_mapr6  r<  	arg_types
arg_types2nrn   ctype
proto_argsri   ri   rj   r     sH   

r   c                 C   r8  )Nusercoder:  r   ri   ri   rj   r     r   r   c                 C   s   t | dddS )NrI  r   )r5  r:  r   ri   ri   rj   r     s   r   c                 C   r8  )Npymethoddefr:  r   ri   ri   rj   r     r   r   c                 C   sv   g g }}d| v r7| d }d| v r3| d D ]}||v r | | q|D ]}||vr.| | q#||fS | d }||fS )Nr   sortvars)r"  )r   sortargsr   r   ri   ri   rj   getargs  s   


rM  c                    s   g  dg }  fddd  D }|   dv rAd D ]}| v r.|| q# D ]}||vr<|| q1 |fS |d  } |fS )Nr   c                    s(   g | ]}t d  | r| vr|qS )r   )r.   )r   r   r   r   ri   rj   r     s    zgetargs2.<locals>.<listcomp>r   rK  )rd   r   r"  )r   rL  auxvarsr   ri   rN  rj   r     s   

r   c                 C   s<   d| vrd S d }| d dkr| d | d f}| d  |d S )Nf2pymultilinesr   zpython moduler   r   )r   kri   ri   rj   r     s   r   c                 C   s*   dt |  d d }d|d | |d f S )NP         z/*%s %s %s*/r   )r!  )r   lnri   ri   rj   r     s   r   c                 C   s$   t | trttfdd| g S | gS )Nc                 S   s   | || S r}   ri   )xyr&  ri   ri   rj   <lambda>  s    zflatlist.<locals>.<lambda>)r/  r1  r   flatlist)lstri   ri   rj   rY    s   
rY  c                 C   s    | r| d dkr| d d S | S )Nr   r?  ri   )r   ri   ri   rj   r^     s   r^   r,  c              	      s   t  trfdd D S t tr fddD S dt   D ];}|dkr-q&d v r>| d v r> d | }n}t  | trWd| |t | q&d|  | q&S )Nc                    s   g | ]}t | qS ri   r\   r   _m)
defaultsepr0  ri   rj   r     r   zreplace.<locals>.<listcomp>c                    s   g | ]}t | qS ri   r[  r\  )r   r^  ri   rj   r     r   rT  separatorsforz#%s#)r/  r1  r   r\   r$  rY  )r0  r   r^  rQ  sepri   )r   r^  r0  rj   r\     s   

 r\   c                 C   s(  t |tr|D ]}t| |} q| S | D ]|}|d dkrq|| v rt | | tr0| | g| |< t | | trSt || trI| | ||  | |< q| | ||  qt | | trt || tr|dkr||  D ]}|| | vr}|| | | | |< qkqt| | || | |< q|| | |< q| S )Nr   _r_  )r/  r1  r	   r   r0  r"  dict)rdarr   rQ  k1ri   ri   rj   r	   ,  s4   
r	   c                 C   s  i }t | tr | D ]}t|||}t||}d|v r |S q	|S d| v r,| d |s,|S d| v rEtd| d i||}d|v rEt|d  |  D ]}|dkrV| | ||< qIt | | trgt| | |||< nt | | trg ||< | | D ]}t||i||}	||	v r|| 	|	|  qvn|d dkrqIt | | t
rg ||< | |  D ]l}
t |
tjr|
|rt | | |
 tr| | |
 D ]$}t |t
rtd|i||}d|v r|d }nd	}|| 	t|| qq| | |
 }t |t
r
td|i|}d|v r|d }nd	}|| 	t|| qn
td
t| |   t || trCt|| dkr9|| d ||< || g krC||= qI|S )N_break_checkneedneedsr_  r   ra  	supertextr,  zapplyrules: ignoring rule %s.
r   )r/  r1  r   r	   r   append_needsr   r0  r\   r"  rb  typesFunctionTyper
   r2  r!  )rulesr   rn   retr6  rrresrQ  r)  rd  re  ri   ri   rj   r   I  s|   



	

r   c                 C   sd   t | }| D ]'\}}||v r+t|| tr&t|tr&t|| |||< q|||< q|||< q|S )a%  Recursively merge two dictionaries into a new dictionary.

    Parameters:
    - dict1: The base dictionary.
    - dict2: The dictionary to merge into a copy of dict1.
             If a key exists in both, the dict2 value will take precedence.

    Returns:
    - A new merged dictionary.
    )r   itemsr/  rb  ra   )dict1dict2merged_dictkeyr   ri   ri   rj   ra     s   

ra   z%\s*python\s*module\s*(?P<name>[\w_]+)z4\s*python\s*module\s*(?P<name>[\w_]*?__user__[\w_]*)c                 C   sp   d }t | (}|D ]}t|}|rt|rq	|d} n	q	W d    |S W d    |S 1 s1w   Y  |S )Nr   )open_f2py_module_name_match_f2py_user_module_name_matchgroup)sourcer   r&  linemri   ri   rj   rN     s$   



rN   )r   r   )r,  )__doc__pprintre   r   rl  	functoolsr   r   r   r,  r   r   __all__versionf2py_versionstderrrg   r
   r]   rc   rl   r   r[   r   ru   rw   r!   r   r    rK   rI   rJ   r   r   rG   r"   r:   r-   r   r   r+   r?   rR   rV   rQ   rT   r&   r=   r<   r#   r,   rS   rW   r   rU   r   r   r   rH   r   r   rB   rA   r)   r*   rM   rO   r`   r   r   rF   r;   r@   r>   r$   r%   rL   r   rP   r   rC   r(   r   rE   r4   r5   r8   r3   r7   r/   r   r1   r9   r0   r6   r.   r   r   r   r2   rD   r   r  r   r   r   r  r  r   r   r  r  	Exceptionr  r_   rX   rZ   rY   r'   r   r7  r   r   r   r   r   rM  r   r   r   rY  r^   r\   r	   r   ra   compileImatchrx  ry  rN   ri   ri   ri   rj   <module>   s(  



'	
=