a
    <bn                     @   sl  d Z ddlmZmZ ddlmZ ddlmZ ddl	Z	ddl
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ ddlmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z( ddl)m*Z*m+Z+m,Z,m-Z-m.Z. dd	l/m0Z0 dd
l1m2Z2 ddl3m4Z4 ddl5m6Z6 ddl7m8Z8m9Z9 ddl:m;Z; ddl5m<Z<m=Z= ddddddddddddddddd d!Z>G d"d# d#e6Z?dS )$aq  
Fortran code printer

The FCodePrinter converts single SymPy expressions into single Fortran
expressions, using the functions defined in the Fortran 77 standard where
possible. Some useful pointers to Fortran can be found on wikipedia:

https://en.wikipedia.org/wiki/Fortran

Most of the code below is based on the "Professional Programmer's Guide to
Fortran77" by Clive G. Page:

http://www.star.le.ac.uk/~cgp/prof77.html

Fortran is a case-insensitive language. This might cause trouble because
SymPy is case sensitive. So, fcode adds underscores to variable names when
it is necessary to make them different for Fortran.
    )DictAny)defaultdict)chainN)
AssignmentDeclarationPointervalue_constfloat32float64float80	complex64
complex128int8int16int32int64intcrealintegerbool_complex_)allocatableisigndsigncmplxmerge
literal_dp	elementalpure	intent_in
intent_outintent_inout)SAddNFloatSymbol)Function)Eq)Range)CodePrinter)
precedence
PRECEDENCE)printer_context)fcodeprint_fcodesincostanasinacosatanatan2sinhcoshtanhlogexperfabsZconjgmaxmin)r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   Abs	conjugateZMaxZMinc                       s  e Zd ZdZdZdZeeee	e
eiZedede	dededed	ed
edededediZeddiiZdddi ddddddd
ZddddddZdd iZd fd!d"	Zed#d$ Z f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> Z)d?d@ Z*dAdB Z+dCdD Z,dEdF Z-dGdH Z.dIdJ Z/dKdL Z0dMdN Z1dOdP Z2dQdR Z3dSdT Z4dUdV Z5dWdX Z6dYdZ Z7d[d\ Z8d]d^ Z9d_d` Z:dadb Z;dcdd Z<dedf Z=dgdh Z>didj Z?dkdl Z@dmdn ZAdodp ZBdqdr ZCdsdt ZDdudv ZEdwdx ZFdydz ZGd{d| ZHd}d~ ZIdd ZJdd ZKdd ZLdd ZMdd ZNdd ZOdd ZPdd ZQdd ZRdd ZSdd ZTdd ZUdd ZV  ZWS )FCodePrinterzAA printer to convert SymPy expressions to strings of Fortran codeZ_fcodeZFortranzinteger(c_int)zreal*4zreal*8zreal*10z	complex*8z
complex*16z	integer*1z	integer*2z	integer*4z	integer*8logicaliso_c_bindingc_intNauto   TFfixedM   )
orderZ	full_prec	precisionuser_functionsZhumanZallow_unknown_functionssource_formatZcontractstandardname_manglingz.and.z.or.z.neqv.z.eqv.z.not. )andorxorZ
equivalentnotz!=z/=c                    s   |si }i | _ g | _tt| j |di  | _tt| j |di  | _t 	| tt
| _
|di }| j
| h d}| jd |vrtd| jd  tt| _d S )Ntype_aliasestype_mappingsrM   >   B   rJ     i  Z   _   rO   zUnknown Fortran standard: %s)mangled_symbols	used_namedictr   rU   itemspoprV   super__init__known_functionsgetupdate	_settings
ValueErrorr   setmodule_uses)selfsettingsZ	userfuncsZ	standards	__class__ f/Users/vegardjervell/Documents/master/model/venv/lib/python3.9/site-packages/sympy/printing/fortran.pyra   z   s(    
zFCodePrinter.__init__c                 C   sJ   | j d dkrddddS | j d dkr4ddd	dS td
| j d  d S )NrN   rI   z      z     @ zC     )codecontcommentfree z! zUnknown source format: %s)re   rf   ri   rm   rm   rn   _lead   s
    zFCodePrinter._leadc                    s   | j d dkrv|| jvrj|j}| | jv r6|d7 }q| j|  ||jkr\|| j|< nt|| j|< || j}t 	|}|S )NrP   T_)
re   r[   namelowerr\   appendr'   Zxreplacer`   _print_Symbol)ri   exprrw   rk   rm   rn   rz      s    


zFCodePrinter._print_Symbolc                 C   s
   | d S )N   rm   )ri   prm   rm   rn   _rate_index_position   s    z!FCodePrinter._rate_index_positionc                 C   s   |S Nrm   )ri   Z
codestringrm   rm   rn   _get_statement   s    zFCodePrinter._get_statementc                 C   s
   d |S )Nz! {})format)ri   textrm   rm   rn   _get_comment   s    zFCodePrinter._get_commentc                 C   s   d || |S )Nzparameter ({} = {}))r   _print)ri   rw   valuerm   rm   rn   _declare_number_const   s    z"FCodePrinter._declare_number_constc                 C   s(   | j |t|| jd f t|S )NrL   )Z_number_symbolsaddr&   Zevalfre   strri   r{   rm   rm   rn   _print_NumberSymbol   s     z FCodePrinter._print_NumberSymbolc                 C   s   |  | |S r   )_wrap_fortranindent_code)ri   linesrm   rm   rn   _format_code   s    zFCodePrinter._format_codec                    s    |j \ } fddt|D S )Nc                 3   s$   | ]}t  D ]}||fV  qqd S r   )range).0jirowsrm   rn   	<genexpr>       z8FCodePrinter._traverse_matrix_indices.<locals>.<genexpr>)shaper   )ri   matcolsrm   r   rn   _traverse_matrix_indices   s    
z%FCodePrinter._traverse_matrix_indicesc                 C   s^   g }g }|D ]H}t | j|j|jd |jd g\}}}|d|||f  |d q||fS )N   zdo %s = %s, %send do)mapr   labelrx   upperry   )ri   indicesZ
open_linesZclose_linesr   varstartstoprm   rm   rn   _get_loop_opening_ending   s    
z%FCodePrinter._get_loop_opening_endingc                 C   s   ddl m} |j\}|jr4tdtd|t|d}nb|js@|jrrtt	t
dt
d||| t||t
d}n$tt
dtt
d|t|t
d}| |S )Nr   )rA   r   )Z$sympy.functions.elementary.complexesrA   args
is_integerr   r   r)   Z
is_complexis_infiniter   r   r   r   )ri   r{   rA   argZnew_exprrm   rm   rn   _print_sign   s    2$zFCodePrinter._print_signc           
      C   s:  |j d jdkrtdg }|trt|j D ]t\}\}}|dkrZ|d| |  n:|t|j d kr|dkr|d n|d| |  || | q0|d	 d
	|S | j
d dkr.d}| |j d j}t|j d d }|r*| \}}| |}| |}	|j|||	d}q|S tdd S )NTzAll Piecewise expressions must contain an (expr, True) statement to be used as a default condition. Without one, the generated expression may not evaluate to anything under some condition.r   zif (%s) thenr   elsezelse if (%s) thenend if
rO   rZ   zmerge({T}, {F}, {COND}))TFZCONDzmUsing Piecewise as an expression using inline operators is not supported in standards earlier than Fortran95.)r   condrf   Zhasr   	enumeratery   r   lenjoinre   r{   listr_   r   NotImplementedError)
ri   r{   r   r   ecpatternro   Ztermsr   rm   rm   rn   _print_Piecewise   s0    




zFCodePrinter._print_Piecewisec                 C   s,   d | j|jtd dd|jd |jd S )Nz
{}({}, {})ZAtomT)strictr   )r   parenthesizeparentr-   r   r   r   rm   rm   rn   _print_MatrixElement  s
    z!FCodePrinter._print_MatrixElementc           
      C   s  g }g }g }|j D ]>}|jr.|jr.|| q|jrF|jrF|| q|| q|r |rt|}t| }| |}|drd}	|dd  }nd}	t||k rd| }d| t| | t	j
 t|  |	|f S d| t| | t	j
 t|  f S nt| |S d S )N-r   +z(%s)zcmplx(%s,%s) %s %szcmplx(%s,%s))r   	is_numberZis_realry   is_imaginaryr,   r$   r   
startswithr#   ImaginaryUnitr+   
_print_Add)
ri   r{   Z	pure_realZpure_imaginarymixedr   PRECZtermtsignrm   rm   rn   r     s<    


zFCodePrinter._print_Addc                    sR   | j d   fdd|jD }|j| }t|ts<| |S t| |j| S d S )NrL   c                    s   g | ]}t | qS rm   )r%   )r   aprecrm   rn   
<listcomp>0  r   z0FCodePrinter._print_Function.<locals>.<listcomp>)re   r   func
isinstancer(   r   r+   _print_Function)ri   r{   r   Z	eval_exprrm   r   rn   r   -  s    



zFCodePrinter._print_Functionc                 C   sB   | j d dv rd}t|n"|j\}}d| || |S d S )NrO   )rW   rJ   z]Python % operator and SymPy's Mod() function are not supported by Fortran 66 or 77 standards.z      modulo({}, {}))re   r   r   r   r   )ri   r{   msgxyrm   rm   rn   
_print_Mod7  s
    

zFCodePrinter._print_Modc                 C   s   dS )Nz
cmplx(0,1)rm   r   rm   rm   rn   _print_ImaginaryUnitD  s    z!FCodePrinter._print_ImaginaryUnitc                 C   s   t |S r   r   r   rm   rm   rn   
_print_intH  s    zFCodePrinter._print_intc                 C   s2   |j r"|jr"d| tj |  S t| |S d S )Nzcmplx(0,%s))r   r   r   r#   r   r+   
_print_Mulr   rm   rm   rn   r   K  s
    zFCodePrinter._print_Mulc                 C   s   t |}|jdkr2d| td| |j|f S |jdkr|jjrn|jjr\d| |j S d| |j S qd| |j S nt	| |S d S )Nr   z%s/%sr   g      ?zsqrt(%s.0d0)zsqrt(dble(%s))zsqrt(%s))
r,   r<   r   r   r   baser   Z	is_Numberr+   
_print_Pow)ri   r{   r   rm   rm   rn   r   T  s    

zFCodePrinter._print_Powc                 C   s"   t |jt |j }}d||f S )Nz%d.0d0/%d.0d0)intr}   q)ri   r{   r}   r   rm   rm   rn   _print_Rationalg  s    zFCodePrinter._print_Rationalc                 C   sF   t | |}|d}|dkr>d|d | ||d d  f S d| S )Nr   r   z%sd%sr   z%sd0)r+   _print_Floatfind)ri   r{   Zprintedr   rm   rm   rn   r   k  s
    
 zFCodePrinter._print_Floatc                 C   sD   |  |j}|  |j}|j}|| jvr,|n| j| }d|||S )Nz{} {} {})r   lhsrhsZrel_op_relationalsr   )ri   r{   lhs_coderhs_codeoprm   rm   rn   _print_Relationalr  s
    zFCodePrinter._print_Relationalc                    s0    fdd|j D }d |jjd|f S )Nc                    s   g | ]}  |qS rm   r   )r   r   rt   rm   rn   r   z  r   z/FCodePrinter._print_Indexed.<locals>.<listcomp>%s(%s), )r   r   r   r   r   )ri   r{   Zindsrm   rt   rn   _print_Indexedy  s    zFCodePrinter._print_Indexedc                 C   s   |  |jS r   )r   r   r   rm   rm   rn   
_print_Idx}  s    zFCodePrinter._print_Idxc                    s>     |j}  |j} djt fdd||j|g S )Nz{0} = {0} {1} {2}c                    s
     | S r   r   r   rt   rm   rn   <lambda>  r   z9FCodePrinter._print_AugmentedAssignment.<locals>.<lambda>)r   r   r   r   r   r   binop)ri   r{   r   r   rm   rt   rn   _print_AugmentedAssignment  s    
z'FCodePrinter._print_AugmentedAssignmentc                 C   s^   |  |j}|jd kr*|d|  |j 7 }|jd krH|d|  |j 7 }d|jjd|f S )Nr   z, mask=r   rv   )r   arraydimmaskrl   __name__rstrip)ri   smparamsrm   rm   rn   _print_sum_  s    

zFCodePrinter._print_sum_c                 C   s
   |  |S r   )r   )ri   prodrm   rm   rn   _print_product_  s    zFCodePrinter._print_product_c                    s\   dg}|j dkr |d d}nd}d| d jf d|jr>dndi|j fd	d
|dS )N
concurrentr   steprs   , {step}z*do {concurrent}{counter} = {first}, {last}z
{body}
end do
zconcurrent c                    s
     | S r   r   r   rt   rm   rn   r     r   z(FCodePrinter._print_Do.<locals>.<lambda>)applyexclude)r   ry   r   r   kwargs)ri   doZexclr   rm   rt   rn   	_print_Do  s    


zFCodePrinter._print_Doc                    s:   |j dkrdnd}d| d jf i |j fdddS )	Nr   rs   r   z$({expr}, {counter} = {first}, {last})c                    s
     | S r   r   r   rt   rm   rn   r     r   z3FCodePrinter._print_ImpliedDoLoop.<locals>.<lambda>r   )r   r   r   )ri   Zidlr   rm   rt   rn   _print_ImpliedDoLoop  s    z!FCodePrinter._print_ImpliedDoLoopc                 C   sP   |  |j}t|jtr(|jj\}}}ntd|  |j}dj|||||dS )Nz*Only iterable currently supported is Rangez3do {target} = {start}, {stop}, {step}
{body}
end do)targetr   r   r   body)	r   r  r   iterabler*   r   r   r  r   )ri   r{   r  r   r   r   r  rm   rm   rn   
_print_For  s    zFCodePrinter._print_Forc                 C   sP   | j ||}| j||j}| j|}|rL|D ]\}}| j| | q2|S r   )rU   rc   rV   rw   type_modulesrh   r   )ri   type_Ztype_strrh   kvrm   rm   rn   _print_Type  s    zFCodePrinter._print_Typec                    s,   dj  |jdt fdd|jdS )Nz{symbol}({idxs})r   c                    s
     | S r   r   r   rt   rm   rn   r     r   z-FCodePrinter._print_Element.<locals>.<lambda>)symbolZidxs)r   r   r  r   r   r   )ri   elemrm   rt   rn   _print_Element  s    
zFCodePrinter._print_Elementc                 C   s   t |S r   r   )ri   extrm   rm   rn   _print_Extent  s    zFCodePrinter._print_Extentc              
      sT  |j j}d}fddtttfD }|ddkrBd}n2|ddkrhdg d	|d  }ntd
  t	t
rtd jd dkrdj jtjv rdnd|rddt fdd| nd|tjv rdnd jd}|d krP|d | 7 }n:tjv s(|r0tddt fddjjg}|S )NZ	dimensionc                    s   g | ]}| j v qS rm   )attrs)r   intent)r   rm   rn   r     r   z3FCodePrinter._print_Declaration.<locals>.<listcomp>Tr   rs   r   z, intent(%s))inoutZinoutz!Multiple intents specified for %sz1Pointers are not available by default in Fortran.rO   rY   z"{t}{vc}{dim}{intent}{alloc} :: {s}z, parameterz, dimension(%s)r   c                    s
     | S r   r   r   rt   rm   rn   r     r   z1FCodePrinter._print_Declaration.<locals>.<lambda>z, allocatable)r   Zvcr   r  Zallocsz = %sz0F77 init./parameter statem. req. multiple lines. c                    s
     | S r   r   r   rt   rm   rn   r     r   )variabler   attr_paramsr    r!   r"   countindexrf   r   r   r   re   r   r   typer	   r  r   r   r   r  )ri   r{   valr   Zintentsr  resultrm   )ri   r   rn   _print_Declaration  s4    


"

 zFCodePrinter._print_Declarationc                 C   s   d|  td S )Nz(huge(%s) + 1)r   )r   r   r   rm   rm   rn   _print_Infinity  s    zFCodePrinter._print_Infinityc                    s    dj f i |j fdddS )Nz$do while ({condition})
{body}
end doc                    s
     | S r   r   r   rt   rm   rn   r     r   z+FCodePrinter._print_While.<locals>.<lambda>r  r   r   r   rm   rt   rn   _print_While  s    
zFCodePrinter._print_Whilec                 C   s   dS )Nz.true.rm   r   rm   rm   rn   _print_BooleanTrue  s    zFCodePrinter._print_BooleanTruec                 C   s   dS )Nz.false.rm   r   rm   rm   rn   _print_BooleanFalse  s    z FCodePrinter._print_BooleanFalsec                 C   sR   g }|D ]D}| dr8|| jd |dd     q|| jd |  q|S )N!rq   r   ro   )r   ry   ru   lstrip)ri   r   r  linerm   rm   rn   _pad_leading_columns  s    
"z!FCodePrinter._pad_leading_columnsc                    s  t dtj tj  t d fdd}g }| jd dkrBd}nd}|D ]}|| jd	 r t|d
kr|ddd
}|dkrd
}|d| }||d 	 }|
| |r|ddd}|dkst|dk rd}|d| }||d 	 }|
d| jd	 |f  qn
|
| qJ|| jd r||d
}|d|  }||d 	 }|rj||7 }|
| |r||d}|d|  }||d 	 }|r||7 }|
d| jd |f  qtqJ|
| qJ|S )zWrap long Fortran lines

           Argument:
             lines  --  a list of lines (without \n character)

           A comment line is split at white space. Code lines are split with a more
           complex rule to give nice results.
        z_+-.z 	()c                    sJ   t  |krt  S |} fdd}||sF|d8 }|dkr(|S q(|S )Nc                    sp    |  v r | d  vpn |  vr8 | d  v pn |  v rT | d  vpn |  von | d  v S )Nr   rm   )pos)r'  my_alnummy_whiterm   rn   r     s    zDFCodePrinter._wrap_fortran.<locals>.split_pos_code.<locals>.<lambda>r   r   )r   )r'  endposr)  splitr*  r+  )r'  rn   split_pos_code  s    z2FCodePrinter._wrap_fortran.<locals>.split_pos_coderN   rr   z &rs   rq   H   r     r   Nr   rW   %s%sro   A   rp   )rg   stringdigitsascii_lettersre   r   ru   r   rfindr&  ry   r   )ri   r   r/  r  Ztrailingr'  r)  Zhunkrm   r.  rn   r     sP    





zFCodePrinter._wrap_fortranc                    s@  t |tr$| |d}d|S | jd dk}dd |D }dd fd	d|D } fd
d|D }dd |D }d}d}d}	g }
t|D ]\}}|dv r|
| q||| 8 }|rd||	 |  }nd| |	 }d||f }|s| |gd }|
| || rd|	 }nd}||| 7 }q|s<| 	|
S |
S )z0Accepts a string of code or a list of code linesTrs   rN   rr   c                 S   s   g | ]}| d qS )z 	)r&  r   r'  rm   rm   rn   r   L  r   z,FCodePrinter.indent_code.<locals>.<listcomp>)zdo zif(zif zdo
r   programZ	interface)r   Zenddor   endifr   zend programzend interfacec                    s    g | ]}t tt|j qS rm   r   anyr   r   r8  )inc_keywordrm   rn   r   Q  s   c                    s    g | ]}t tt|j qS rm   r;  r8  )dec_keywordrm   rn   r   S  s   c                 S   s$   g | ]}t tt|jd dgqS )&z&
)r   r<  r   endswithr8  rm   rm   rn   r   U  s   r      )rs   r   r  r2     )
r   r   r   
splitlinesr   re   r   ry   r(  r   )ri   ro   Z
code_linesrr   ZincreaseZdecreaseZcontinuationlevelZcont_paddingZtabwidthZnew_coder   r'  paddingrm   )r>  r=  rn   r   E  sN    








zFCodePrinter.indent_codec                    sL   |j r2djdt fdd|j |j dS |j\}d | S d S )Nzgo to ({labels}), {expr}r   c                    s
     | S r   r   r   rt   rm   rn   r   z  r   z*FCodePrinter._print_GoTo.<locals>.<lambda>)labelsr{   zgo to %s)r{   r   r   r   rF  r   )ri   gotoZlblrm   rt   rn   _print_GoTow  s    
zFCodePrinter._print_GoToc                    s    dj f i |j fdddS )Nz"program {name}
{body}
end program
c                    s
     | S r   r   r   rt   rm   rn   r     r   z-FCodePrinter._print_Program.<locals>.<lambda>r  r!  )ri   progrm   rt   rn   _print_Program  s    zFCodePrinter._print_Programc                    s    dj f i |j fdddS )NzAmodule {name}
{declarations}

contains

{definitions}
end module
c                    s
     | S r   r   r   rt   rm   rn   r     r   z,FCodePrinter._print_Module.<locals>.<lambda>r  r!  )ri   modrm   rt   rn   _print_Module  s    zFCodePrinter._print_Modulec                 C   sp   |j dkr,| jd dkr,| jd d dS |j dkrX| jd dkrX| jd d d	S |j dkrfd
S |j S d S )NstdoutrO   rX   rE   zstdint=>input_unitZ
input_unitstderrzstdint=>error_unitZ
error_unit*)rw   re   rh   r   )ri   strmrm   rm   rn   _print_Stream  s    
zFCodePrinter._print_Streamc                    s@   |j d kr |j }nd}dj|dt fdd|jdS )NrO  zprint {fmt}, {iolist}r   c                    s
     | S r   r   r   rt   rm   rn   r     r   z+FCodePrinter._print_Print.<locals>.<lambda>)fmtZiolist)format_stringr   r   r   r   Z
print_args)ri   ZpsrR  rm   rt   rn   _print_Print  s    

zFCodePrinter._print_Printc                 C   s&   |j \}dj| jdd| |dS )Nz{result_name} = {arg}result_nameZsympy_result)rU  r   )r   r   _contextrc   r   )ri   rsr   rm   rm   rn   _print_Return  s
    zFCodePrinter._print_Returnc                 C   s"   |j \}|rd| | S dS d S )Nz	return %sreturn)r   r   )ri   Zfrsr   rm   rm   rn   _print_FortranReturn  s    z!FCodePrinter._print_FortranReturnc                    s   | d}|d u rd}n|r(d|d  nd} jdd }dj| |jd fd	d
|jD |rnd| nd|dt fdd|jdS )NZbind_Crs   z bind(C, name="%s")r   z bind(C)rU  z<{entity}{name}({arg_names}){result}{bind}
{arg_declarations}r   c                    s   g | ]}  |jqS rm   )r   r  )r   r   rt   rm   rn   r     r   z&FCodePrinter._head.<locals>.<listcomp>z result(%s)r   c                    s     t| S r   )r   r   r   rt   rm   rn   r     r   z$FCodePrinter._head.<locals>.<lambda>)entityrw   	arg_namesr  bindZarg_declarations)	r  re   rc   r   r   rw   r   
parametersr   )ri   r[  fpr   Zbind_C_paramsr]  rU  rm   rt   rn   _head  s    

zFCodePrinter._headc                 C   s&   d | |j}dj | ||dS )N{} function z4interface
{function_head}
end function
end interface)function_head)r   r   return_typer`  )ri   r_  r[  rm   rm   rn   _print_FunctionPrototype  s
    
z%FCodePrinter._print_FunctionPrototypec                 C   s   t |jv rd}nt|jv r d}nd}d| |j}t| |jd0 dj|| ||| |j	dW  d    S 1 sz0    Y  d S )Nz
elemental zpure rs   ra  )rU  z,{prefix}{function_head}
{body}
end function
)prefixrb  r  )
r   r  r   r   r   rc  r.   rw   r`  r  )ri   fdre  r[  rm   rm   rn   _print_FunctionDefinition  s    



z&FCodePrinter._print_FunctionDefinitionc                 C   s   dj | d|| |jdS )Nz({subroutine_head}
{body}
end subroutine
zsubroutine )Zsubroutine_headr  )r   r`  r   r  )ri   subrm   rm   rn   _print_Subroutine  s
    

zFCodePrinter._print_Subroutinec                    s,   dj  |jdt fdd|jdS )Nzcall {name}({args})r   c                    s
     | S r   r   r   rt   rm   rn   r     r   z4FCodePrinter._print_SubroutineCall.<locals>.<lambda>)rw   r   )r   r   rw   r   r   Zsubroutine_args)ri   Zscallrm   rt   rn   _print_SubroutineCall  s    
z"FCodePrinter._print_SubroutineCallc                    s   dt t fdd|j S )Nz%s => %sc                    s
     | S r   r   r   rt   rm   rn   r     r   z0FCodePrinter._print_use_rename.<locals>.<lambda>)tupler   r   )ri   rnmrm   rt   rn   _print_use_rename  s    zFCodePrinter._print_use_renamec                    sl   d  |j }|jd kr<|dd fdd|jD  7 }|jd krh|dd fdd|jD  7 }|S )Nzuse %sr   c                    s   g | ]}  |qS rm   r   )r   rl  rt   rm   rn   r     r   z+FCodePrinter._print_use.<locals>.<listcomp>z, only: c                    s   g | ]}  |qS rm   r   )r   Znlyrt   rm   rn   r     r   )r   	namespacerenamer   only)ri   Zuser  rm   rt   rn   
_print_use  s    
"
"zFCodePrinter._print_usec                 C   s   dS )Nexitrm   ri   rv   rm   rm   rn   _print_BreakToken  s    zFCodePrinter._print_BreakTokenc                 C   s   dS )Ncyclerm   rs  rm   rm   rn   _print_ContinueToken  s    z!FCodePrinter._print_ContinueTokenc                    s4    j d dkrdnd}|dt fdd|j S )NrO   rX   z[%s]z(/%s/)r   c                    s
     | S r   r   r   rt   rm   rn   r     r   z6FCodePrinter._print_ArrayConstructor.<locals>.<lambda>)re   r   r   elements)ri   acZfmtstrrm   rt   rn   _print_ArrayConstructor  s    z$FCodePrinter._print_ArrayConstructor)N)Xr   
__module____qualname____doc__Zprintmethodlanguager   r   r   r   r   r   rU   r   r
   r   r   r   r   r   r   rV   r  Z_default_settings
_operatorsr   ra   propertyru   rz   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r   r"  r#  r$  r(  r   r   rH  rJ  rL  rQ  rT  rX  rZ  r`  rd  rg  ri  rj  rm  rq  rt  rv  ry  __classcell__rm   rm   rk   rn   rC   D   s   	
*'
		!	G2
		
rC   )@r|  typingr   ZtDictr   collectionsr   	itertoolsr   r4  Zsympy.codegen.astr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   Zsympy.codegen.fnodesr   r   r   r   r   r   r   r   r    r!   r"   Z
sympy.corer#   r$   r%   r&   r'   Zsympy.core.functionr(   Zsympy.core.relationalr)   Z
sympy.setsr*   Zsympy.printing.codeprinterr+   Zsympy.printing.precedencer,   r-   Zsympy.printing.printerr.   r/   r0   rb   rC   rm   rm   rm   rn   <module>   sB   P4