o
    8Va>                     @   s  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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# 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/m0Z0 d dl1m2Z2 d dl3m4Z4m5Z5m6Z6m7Z7m8Z8 d dl9m:Z:m;Z; d dl<m=Z=m>Z> d dl?m@Z@mAZA d d	lBmCZC d d
lDmEZEmFZF dd ZGdd ZHdd ZIdd ZJdd ZKdd ZLdd ZMdd ZNdd ZOdd ZPdd  ZQd!d" ZRd#d$ ZSd%d& ZTd'd( ZUd)d* ZVd+d, ZWd-d. ZXd/d0 ZYd1d2 ZZd3d4 Z[d5d6 Z\d7d8 Z]d9d: 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_S )`    )sincosatan2logexpgamma	conjugatesqrt	factorialIntegral	PiecewiseAdddiffsymbolsSFloatDummyEqRangeCatalan
EulerGammaEGoldenRatioIpiFunctionRationalIntegerLambdasignMod)For
Assignment
aug_assign)DeclarationVariablefloat32float64value_constrealbool_WhileFunctionPrototypeFunctionDefinitionintegerReturn)
Relational)AndOrNot
EquivalentXor)MatrixMatrixSymbol)fcodeFCodePrinter)IndexedBaseIdx)implemented_function)raiseswarns_deprecated_sympyc                  C   s0   t d} G dd dt}t|| dksJ d S )Nxc                   @   s   e Zd Zdd ZdS )ztest_printmethod.<locals>.nintc                 S   s   d| | jd  S )Nznint(%s)r   )_printargs)selfprinter rD   C/usr/lib/python3/dist-packages/sympy/printing/tests/test_fortran.py_fcode   s   z%test_printmethod.<locals>.nint._fcodeN)__name__
__module____qualname__rF   rD   rD   rD   rE   nint   s    rJ   z      nint(x))r   r   r8   )r?   rJ   rD   rD   rE   test_printmethod   s   rK   c                     s   t d t ddd} t ddd}tt ddd	d
ksJ tt| ddd	dks*J tt|ddd	dks7J tt fdd d S )Nr?   yTr.   z)complex_   freestandardsource_formatz#merge(0d0, dsign(1d0, x), x == 0d0)zmerge(0, isign(1, y), y == 0)z/merge(cmplx(0d0, 0d0), z/abs(z), abs(z) == 0d0)c                      s   t t S N)r8   r   rD   r?   rD   rE   <lambda>$   s    z!test_fcode_sign.<locals>.<lambda>)r   r8   r   r=   NotImplementedError)rL   rN   rD   rV   rE   test_fcode_sign   s   rY   c                  C   s(  t d\} }t ddd}t| d dksJ t| |d  dks"J tdt| d	 | ||     | d
 |  dks<J tt| dksFJ tt|dksPJ t| d dksZJ tt| dksdJ ttddksnJ t| d dksxJ t| d ddddksJ t| tdd dksJ d S )Nx,ynTrM      z
      x**3z      x**(y**3)   g      @   z,      (3.5d0*sin(x))**(-x + y**x)/(x**2 + y)z      sqrt(x)z      sqrt(dble(n))g      ?
   z      sqrt(10.0d0)g      z      1d0/xg       rL   rQ   rT   zy = x**(-2.0d0)   z      x**(3.0d0/7.0d0))r   r8   r   r	   r   )r?   rL   r[   rD   rD   rE   test_fcode_Pow'   s   *rb   c                  C   s   t d} ttdddksJ ttdddksJ ttddd	ks%J ttd
ddks0J t| tdd dks=J ttdd|  dksJJ d S )Nr?   r\   ra   z      3.0d0/7.0d0   	   z      2iz      -3.0d0/7.0d0z      x + 3.0d0/7.0d0z      (3.0d0/7.0d0)*x)r   r8   r   rV   rD   rD   rE   test_fcode_Rational9   s   rf   c                   C   ,   t tddks
J t tddksJ d S )NC   z      67z      -1)r8   r   rD   rD   rD   rE   test_fcode_IntegerC      rj   c                   C   rg   )Ng      E@z      42.0000000000000d0g@xz      -1.00000000000000d+20)r8   r   rD   rD   rD   rE   test_fcode_FloatH   rk   rl   c                     s   t d\ tt t dksJ tt fdd tt fdd tt fdd tt fdd dD ]} tt | d	d
ksMJ t  | d	d
ksYJ q>d S )NrZ   z      sin(x)**cos(y)c                         t t ddS NB   rS   r8   r    rD   r?   rL   rD   rE   rW   P       z&test_fcode_functions.<locals>.<lambda>c                         t   ddS rn   r8   rD   rr   rD   rE   rW   Q       c                      rm   NM   rp   rq   rD   rr   rD   rE   rW   R   rs   c                      rt   rw   ru   rD   rr   rD   rE   rW   S   rv   )Z   rP   i  i  rp   z      modulo(x, y))r   r8   r   r   r=   rX   r    rp   rD   rr   rE   test_fcode_functionsM   s   rz   c                  C   s  t  } td\}}}}}}}tt|t||  t||  dks$J tt|d| | |tdd   dks;J tt|t||  t||  dddksSJ t|t| ddd	ksaJ | j|t| | d
ddksrJ | j|t| dddksJ | j|dddksJ tddd\}}	td}
td}td}t	d|	}t	d|}t|
||f ||  || dddksJ d S )Nzx,x_,x__,y,X,X_,Yz&      exp(x_) + sin(x*y) + cos(X__*Y_)r^   ra   z(      2*X_**(7.0d0/2.0d0)*Y*x + exp(x__)F)Zname_manglingz#      exp(x_) + sin(x*y) + cos(X*Y)z      x - cos(X)me	assign_toz      me = X*sin(x_) + x__Zmuz      mu = X*sin(x_)Zadz      ad = x__n,mTrM   Ar?   rL   ir   rQ   r}   rT   zndo i = 1, m
   y(i) = 0
end do
do i = 1, m
   do I_ = 1, n
      y(i) = A(i, I_)*x(I_) + y(i)
   end do
end do)
r9   r   r8   r   r   r   r   doprintr:   r;   )Zobr?   Zx_Zx__rL   XZX_Yr[   mr   r   r   rD   rD   rE   	test_caseY   s0   "$&"

 r   c                  C   s   t d} tdd}d}t| td d| ksJ t| td d| ks)J t| ttd d| ks9J tttdd| ksGJ ttddtdd ksXJ t| ttd d| kshJ t| tttd d| kszJ d S )Nr?   r_      z0.8340324452479558d0z      x*%sd0z
      %sd0z
      x*%s)r   r   evalfr8   r   r   )r?   Zlog10_17Zloglog10_17rD   rD   rE   "test_fcode_functions_with_integersx   s    " (r   c                  C   s  d} t  }ttdt|  ksJ ttdt|  ksJ ttdt|  ks,J ttdt|  ks9J ttdt|  ksFJ ttdddtd ksUJ ttd	d
t|t| fht	 dfkslJ ttd	d
t|t| fht	 dfksJ ttd	d
t|t| fht	 dfksJ ttd	d
t|t| fht	 dfksJ ttd	d
t|t| fht	 dfksJ ttdd	dt|tdfht	 dfksJ d S )Nr   z.      parameter (Catalan = %sd0)
      Catalanz4      parameter (EulerGamma = %sd0)
      EulerGammaz"      parameter (E = %sd0)
      Ez6      parameter (GoldenRatio = %sd0)
      GoldenRatioz$      parameter (pi = %sd0)
      pi   )	precisionF)humanz      Catalanz      EulerGammaz      Ez      GoldenRatioz      pi)r   r   )
r9   r8   r   r   r   r   r   r   r@   set)ZprecprD   rD   rE   test_fcode_NumberSymbol   sH   







r   c                  C   s   t tdksJ td} t dt dksJ t ddt  dks"J t ddt  |  dks0J t t|  dks:J t ddt  |  d	ksHJ tdd
d} t d|  dksXJ t t|  dksbJ t d|  dkslJ d S )Nz      cmplx(0,1)r?      z      cmplx(0,4)r\   z      cmplx(3,4)z      cmplx(3,4) + xz      cmplx(0,1)*xz      cmplx(3,4) - xT)Z	imaginaryr   z	      5*xz      x + 3)r8   r   r   rV   rD   rD   rE   test_fcode_complex   s   r   c                  C   sN   t d\} }tt| dksJ tt| |dksJ tt| dks%J d S )NrZ   z      sin(x)z      atan2(x, y)z      conjg(x))r   r8   r   r   r   rr   rD   rD   rE   test_implicit   s   r   c                  C   sX   t d} td}tt| }|dksJ ttt| dks J t|| dks*J d S )Nr?   gz:C     Not supported in Fortran:
C     gamma
      gamma(x)zHC     Not supported in Fortran:
C     Integral
      Integral(sin(x), x)z2C     Not supported in Fortran:
C     g
      g(x))r   r   r8   r   r   r   )r?   r   Zgamma_frD   rD   rE   test_not_fortran   s   r   c                  C   s   t d} tt| ddiddksJ t d} tt| ddiddks$J td	}t|| d	d
iddks6J t ddd}tt|ddiddksJJ d S )Nr?   r   Zzsin)Zuser_functionsz      zsin(x)r   Zmygammaz      mygamma(x)r   Zgreatz      great(x)r[   TrM   r
   Zfctz      fct(n))r   r8   r   r   r   r
   )r?   r   r[   rD   rD   rE   test_user_functions   s    r   c                  C   s   t d} tdt| d|  }t|| dksJ tdt| dt |  }t|| dtd ks3J td}tdt d	d
d}tdt| | d|   d|   }t||| || ddks`J d S )Nr?   r   r^   z	      2*xz(      parameter (pi = %sd0)
      2*pi/xr   r   r   r[   TrM   r]   r|   zI      do i = 1, n
         A(i) = (A(i) + 1)*(A(i) + 2)*A(i)
      end do)r   r<   r   r8   r   r   r:   r;   )r?   r   r   r   rD   rD   rE   test_inline_function   s   

 r   c                  C   s$   t d} tt| dddksJ d S )Nr?   sr|   z      s = sin(x))r   r8   r   rV   rD   rD   rE   test_assign_to   s   r   c                     sZ   t d\ } t |  d  dddksJ  fddtdD }tt| d	ks+J d S )
NrZ   r_   varr|   z      var = x**10 + 10*x**9*y + 45*x**8*y**2 + 120*x**7*y**3 + 210*x**6*
     @ y**4 + 252*x**5*y**5 + 210*x**4*y**6 + 120*x**3*y**7 + 45*x**2*y
     @ **8 + 10*x*y**9 + y**10c                    s   g | ]} | qS rD   rD   ).0r   rV   rD   rE   
<listcomp>   s    z&test_line_wrapping.<locals>.<listcomp>   zR      x**10 + x**9 + x**8 + x**7 + x**6 + x**5 + x**4 + x**3 + x**2 + x
     @ + 1)r   r8   expandranger   )rL   erD   rV   rE   test_line_wrapping   s   
r   c                  C   s   t d\} }tt| |k || d k dddksJ tt| |k || d k dddks,J tt| |k || d k ddddd	ksAJ tt| |k || d k ddd
ksTJ d S )Nx yr]   rQ   r`   zx < y .and. y < x + 1zx < y .or. y < x + 1FZevaluatezx < y .neqv. y < x + 1zx < y .eqv. y < x + 1)r   r8   r1   r2   r5   r4   rr   rD   rD   rE   test_fcode_precedence   s   r   c                  C   st  t d\} }}tt| dddksJ tt| |dddks J tt| t|dddks/J ttt| |dddks>J ttt| t|dddksOJ ttt| |d	d
dddks`J tt| |dddksmJ tt| t|dddks|J ttt| |dddksJ ttt| t|dddksJ ttt| |d	d
dddksJ ttt||| dddksJ ttt|| |dddksJ ttt| ||dddksJ ttt||| dddksJ ttt|| |dddksJ ttt| ||dddksJ tt| ||dddksJ tt| |t|dddks.J tt| t||dddks?J ttt| ||dddksPJ ttt| ||d	d
dddkscJ tt| ||dddksrJ tt| |t|dddksJ tt| t||dddksJ ttt| ||dddksJ ttt| ||d	d
ddd ksJ d S )!Nx y zrQ   r`   z.not. xz	x .and. yzx .and. .not. yzy .and. .not. xz.not. x .and. .not. yFr   z.not. (x .and. y)zx .or. yzx .or. .not. yzy .or. .not. xz.not. x .or. .not. yz.not. (x .or. y)zx .and. (y .or. z)zy .and. (x .or. z)zz .and. (x .or. y)zx .or. y .and. zzy .or. x .and. zzz .or. x .and. yzx .and. y .and. zzx .and. y .and. .not. zzx .and. z .and. .not. yzy .and. z .and. .not. xz.not. (x .and. y .and. z)zx .or. y .or. zzx .or. y .or. .not. zzx .or. z .or. .not. yzy .or. z .or. .not. xz.not. (x .or. y .or. z))r   r8   r3   r1   r2   r?   rL   rN   rD   rD   rE   test_fcode_Logical   sh        "






r   c                  C   s(  t d\} }}tt| |dddddksJ tt| t|dddddks'J ttt| |dddddks8J ttt| t|ddddd	ksKJ ttt| |ddddddd
ks^J tt| |dddkskJ tt| t|dddkszJ ttt| |dddksJ ttt| t|dddksJ ttt| |dddddksJ ttt||| dddksJ ttt|| |dddksJ ttt| ||dddksJ ttt||| dddksJ ttt|| |dddksJ ttt| ||dddksJ ttt||| dddksJ ttt|| |dddks.J ttt| ||dddks?J ttt||| dddksPJ ttt|| |dddksaJ ttt| ||dddksrJ ttt||dd| dddksJ ttt|| dd|dddksJ ttt| |dd|dddksJ ttt||| dddddksJ ttt|| |ddddd ksJ ttt| ||ddddd!ksJ ttt||| ddddd"ksJ ttt|| |ddddd#ks
J ttt| ||ddddd$ksJ ttt||dd| ddd%ks0J ttt|| dd|ddd&ksCJ ttt| |dd|ddd'ksVJ ttt||| ddddd(ksiJ ttt|| |ddddd)ks|J ttt| ||ddddd*ksJ ttt||dd| ddd+ksJ ttt|| dd|ddd,ksJ ttt| |dd|ddd-ksJ tt| ||ddddd.ksJ tt| |t|ddddd/ksJ tt| t||ddddd0ksJ ttt| ||ddddd1ksJ d S )2Nr   Fr   rQ   r`   z
x .neqv. yzx .neqv. .not. yzy .neqv. .not. xz.not. x .neqv. .not. yz.not. (x .neqv. y)z	x .eqv. yzx .eqv. .not. yzy .eqv. .not. xz.not. x .eqv. .not. yz.not. (x .eqv. y)zx .eqv. y .and. zzy .eqv. x .and. zzz .eqv. x .and. yzx .and. (y .eqv. z)zy .and. (x .eqv. z)zz .and. (x .eqv. y)zx .eqv. y .or. zzy .eqv. x .or. zzz .eqv. x .or. yzx .or. (y .eqv. z)zy .or. (x .eqv. z)zz .or. (x .eqv. y)zx .eqv. (y .neqv. z)zy .eqv. (x .neqv. z)zz .eqv. (x .neqv. y)zx .neqv. (y .eqv. z)zy .neqv. (x .eqv. z)zz .neqv. (x .eqv. y)zx .neqv. y .and. zzy .neqv. x .and. zzz .neqv. x .and. yzx .and. (y .neqv. z)zy .and. (x .neqv. z)zz .and. (x .neqv. y)zx .neqv. y .or. zzy .neqv. x .or. zzz .neqv. x .or. yzx .or. (y .neqv. z)zy .or. (x .neqv. z)zz .or. (x .neqv. y)zx .neqv. y .neqv. zzx .neqv. y .neqv. .not. zzx .neqv. z .neqv. .not. yzy .neqv. z .neqv. .not. x)r   r8   r5   r3   r4   r1   r2   r   rD   rD   rE   test_fcode_Xlogical+  s*  



























r   c                  C   s   t d\} }tt| |ddddksJ tt| |ddddks"J tt| |dddd	ks0J tt| |d
dddks>J tt| |ddddksLJ tt| |ddddksZJ d S )Nr   z==rQ   r`   zx == yz!=zx /= yz>=zx >= yz<=zx <= y>zx > y<zx < y)r   r8   r0   rr   rD   rD   rE   test_fcode_Relational  s    r   c                     sd  t d} t| | dk f| d df tt fdd t dd}d	}||ks(J tt| | dk f| d dfd
ddks=J t| |  }t| |  }tdD ]}t|| }t|| }qMd}tt|| dk f|dfdd}||ksqJ tt| | dk f| d | dkft| dfdd}d}||ksJ t| | dk f| d | dkft| | dkf tt	 fdd d S )Nr?   r]   r^   Tc                         t  S rU   ru   rD   exprrD   rE   rW         z&test_fcode_Piecewise.<locals>.<lambda>rP   rp   z      merge(x, x**2, x < 1)r   r|   zR      if (x < 1) then
         var = x
      else
         var = x**2
      end ifr_   a/        if (x < 0) then
         weird_name = -cos(x)/x + 10*sin(x)/x**2 + 90*cos(x)/x**3 - 720*
     @ sin(x)/x**4 - 5040*cos(x)/x**5 + 30240*sin(x)/x**6 + 151200*cos(x
     @ )/x**7 - 604800*sin(x)/x**8 - 1814400*cos(x)/x**9 + 3628800*sin(x
     @ )/x**10 + 3628800*cos(x)/x**11
      else
         weird_name = -sin(x)/x - 10*cos(x)/x**2 + 90*sin(x)/x**3 + 720*
     @ cos(x)/x**4 - 5040*sin(x)/x**5 - 30240*cos(x)/x**6 + 151200*sin(x
     @ )/x**7 + 604800*cos(x)/x**8 - 1814400*sin(x)/x**9 - 3628800*cos(x
     @ )/x**10 + 3628800*sin(x)/x**11
      end ifr   Z
weird_namez1      merge(x, merge(x**2, sin(x), x > 1), x < 1)c                      r   rU   ru   rD   r   rD   rE   rW     r   )
r   r   r=   rX   r8   r   r   r   r   
ValueError)r?   codeexpectedabr   rD   r   rE   test_fcode_Piecewise  s.    
0,r   c                  C   sr   t  } g d}| |}g d}|D ]
}t|dksJ qt||D ]
\}}||ks,J q"t|t|ks7J d S )N)zbC     This is a long comment on a single line that must be wrapped properly to produce nice outputzf      this = is + a + long + and + nasty + fortran + statement + that * must + be + wrapped + properlyzg      this = is + a + long + and + nasty + fortran + statement +  that * must + be + wrapped + properlyzh      this = is + a + long + and + nasty + fortran + statement +   that * must + be + wrapped + properlyzd      this = is + a + long + and + nasty + fortran + statement + that*must + be + wrapped + properlyzf      this = is + a + long + and + nasty + fortran + statement +   that*must + be + wrapped + properlyzg      this = is + a + long + and + nasty + fortran + statement +    that*must + be + wrapped + properlyzh      this = is + a + long + and + nasty + fortran + statement +     that*must + be + wrapped + properlyze      this = is + a + long + and + nasty + fortran + statement + that**must + be + wrapped + properlyzf      this = is + a + long + and + nasty + fortran + statement +  that**must + be + wrapped + properlyzg      this = is + a + long + and + nasty + fortran + statement +   that**must + be + wrapped + properlyzh      this = is + a + long + and + nasty + fortran + statement +    that**must + be + wrapped + properlyzi      this = is + a + long + and + nasty + fortran + statement +     that**must + be + wrapped + properlyzc      this = is + a + long + and + nasty + fortran + statement(that)/must + be + wrapped + properlyzg      this = is + a + long + and + nasty + fortran +     statement(that)/must + be + wrapped + properly)zBC     This is a long comment on a single line that must be wrappedz%C     properly to produce nice outputzG      this = is + a + long + and + nasty + fortran + statement + that *%     @ must + be + wrapped + properlyzH      this = is + a + long + and + nasty + fortran + statement +  that *r   G      this = is + a + long + and + nasty + fortran + statement +   thatz'     @ * must + be + wrapped + properlyzF      this = is + a + long + and + nasty + fortran + statement + that*r   zH      this = is + a + long + and + nasty + fortran + statement +   that*r   H      this = is + a + long + and + nasty + fortran + statement +    thatz&     @ *must + be + wrapped + properly@      this = is + a + long + and + nasty + fortran + statement +z*     @ that*must + be + wrapped + properlyzG      this = is + a + long + and + nasty + fortran + statement + that**r   zH      this = is + a + long + and + nasty + fortran + statement +  that**r   r   '     @ **must + be + wrapped + properlyr   r   r   z+     @ that**must + be + wrapped + properlyzE      this = is + a + long + and + nasty + fortran + statement(that)/r   zH      this = is + a + long + and + nasty + fortran +     statement(that)z&     @ /must + be + wrapped + properlyH   )r9   _wrap_fortranlenzip)rC   linesZwrapped_linesZexpected_lineslinewr   rD   rD   rE   test_wrap_fortran  s   
 r   c                  C   s,   t  } g d}g d}| ||ksJ d S )N)H      this_variable_is_very_long_because_we_try_to_test_line_break=1.0d0zI      this_variable_is_very_long_because_we_try_to_test_line_break =1.0d0zK      this_variable_is_very_long_because_we_try_to_test_line_break  = 1.0d0zL      this_variable_is_very_long_because_we_try_to_test_line_break   = 1.0d0zM      this_variable_is_very_long_because_we_try_to_test_line_break    = 1.0d0zK      this_variable_is_very_long_because_we_try_to_test_line_break = 10.0d0)r   D      this_variable_is_very_long_because_we_try_to_test_line_break =     @ 1.0d0zE      this_variable_is_very_long_because_we_try_to_test_line_break  =r   zF      this_variable_is_very_long_because_we_try_to_test_line_break   =r   zG      this_variable_is_very_long_because_we_try_to_test_line_break    =r   r   z     @ 10.0d0r9   r   rC   r   r   rD   rD   rE   test_wrap_fortran_keep_d0  s   r   c                   C   s   t tdd  d S )Nc                   S   s   t tdddS )Nr   Zgarbage)method)r8   r   rD   rD   rD   rE   rW     rv   ztest_settings.<locals>.<lambda>)r=   	TypeErrorrD   rD   rD   rE   test_settings  s   r   c                  C   s0   t d\} }tt| t| dddksJ d S )NrZ   rQ   r`   zsin(y) + cos(x))r   r8   r   r   rr   rD   rD   rE   test_free_form_code_line  s   $r   c                  C   s@   t d\} }tt| t| d  dd}d}||ksJ d S )NrZ   ra   rQ   r`   zsin(y)**7 + 7*sin(y)**6*cos(x) + 21*sin(y)**5*cos(x)**2 + 35*sin(y)**4* &
      cos(x)**3 + 35*sin(y)**3*cos(x)**4 + 21*sin(y)**2*cos(x)**5 + 7* &
      sin(y)*cos(x)**6 + cos(x)**7)r   r8   r   r   r   )r?   rL   resultr   rD   rD   rE    test_free_form_continuation_line"  s
    r   c                  C   s0   t ddi} dg}ddg}| ||ksJ d S )NrT   rQ   z^! This is a long comment on a single line that must be wrapped properly to produce nice outputzG! This is a long comment on a single line that must be wrapped properlyz! to produce nice outputr   r   rD   rD   rE   test_free_form_comment_line-  s   r   c            	      C   s   t ddd\} }td}td}td}td|}td| }d	}t|||f ||  || d
d}||ddi ksS||ddi ksU||ddi ksW||ddi ksYJ d S d S d S d S )Nr~   TrM   r   r?   rL   r   jz_do i = 1, m
   y(i) = 0
end do
do i = 1, m
   do j = 1, n
      y(i) = %(rhs)s
   end do
end dorQ   r   rhszy(i) + A(i, j)*x(j)zy(i) + x(j)*A(i, j)zx(j)*A(i, j) + y(i)zA(i, j)*x(j) + y(i))r   r:   r;   r8   )	r[   r   r   r?   rL   r   r   r   r   rD   rD   rE   
test_loops6  s    

"r   c                  C   sf   t ddtd\} }td}td}t| |} d| jj|jd }t||  ||  dd	}||ks1J d S )
Nzi mT)r.   clsr?   rL   zMdo i_%(icount)i = 1, m_%(mcount)i
   y(i_%(icount)i) = x(i_%(icount)i)
end do)ZicountZmcountrQ   r   )r   r   r:   r;   ZlabelZdummy_indexr8   )r   r   r?   rL   r   r   rD   rD   rE   test_dummy_loopsP  s   
r   c                  C   s   d} t d| fd}t d| fd}t d| d fd}td| d }t|| ||d  ||  ||d  ||   }t|j|jdd	}|d
sIJ d S )Nr   rL   )shaper?   Dyr]   r   F)r}   Zcontractz+Dy(i) = (y(i + 1) - y(i))/(x(i + 1) - x(i)))r:   r;   r   r8   r   Zlhsendswith)Zlen_yrL   r?   r   r   r   Zcode0rD   rD   rE   2test_fcode_Indexed_without_looking_for_contraction^  s   2r   c                  C   s:   G dd dt } |  }td}|t|ddksJ d S )Nc                   @   s   e Zd Zej ZdS )z1test_derived_classes.<locals>.MyFancyFCodePrinterN)rG   rH   rI   r9   Z_default_settingscopyrD   rD   rD   rE   MyFancyFCodePrinterj  s    r   r?   Zborkz      bork = sin(x))r9   r   r   r   )r   rC   r?   rD   rD   rE   test_derived_classesi  s   r   c                  C   s.   d} d}t ddi}|| }||ksJ d S )Nau  subroutine test(a)
integer :: a, i, j

do
do 
do j = 1, 5
if (a>b) then
if(b>0) then
a = 3
donot_indent_me = 2
do_not_indent_me_either = 2
ifIam_indented_something_went_wrong = 2
if_I_am_indented_something_went_wrong = 2
end should not be unindented here
end if
endif
end do
end do
enddo
end subroutine

subroutine test2(a)
integer :: a
do
a = a + 1
end do 
end subroutine
a  subroutine test(a)
integer :: a, i, j

do
   do 
      do j = 1, 5
         if (a>b) then
            if(b>0) then
               a = 3
               donot_indent_me = 2
               do_not_indent_me_either = 2
               ifIam_indented_something_went_wrong = 2
               if_I_am_indented_something_went_wrong = 2
               end should not be unindented here
            end if
         endif
      end do
   end do
enddo
end subroutine

subroutine test2(a)
integer :: a
do
   a = a + 1
end do 
end subroutine
rT   rQ   )r9   Zindent_code)Z	codelinesr   r   r   rD   rD   rE   test_indentr  s   
r   c            	      C   s,  t d\} }}t| | td|  |dkf|dft|g}tddd}t||dks,J td|d	  | dkf|d	 dft|d
  |d  }t|dddksQJ tddd}tddd}tt|d
 dt|d	 g|d
 |d	  |d dgd|d  |d
  t|d d dgg}t||dksJ d S )Nzx,y,zr^   r   Tr   r\   r]   z      A(1, 1) = x*y
      if (y > 0) then
         A(2, 1) = x + 2
      else
         A(2, 1) = y
      end if
      A(3, 1) = sin(z))r^   r   )r]   r   r   r   rP   rp   z?      merge(2*A(3, 1), A(3, 1), x > 0) + sin(A(2, 1)) + A(1, 1)qr   M)r\   r   )r   r   r   z      M(1, 1) = sin(q(2, 1))
      M(2, 1) = q(2, 1) + q(3, 1)
      M(3, 1) = 2*q(5, 1)/q(2, 1)
      M(1, 2) = 0
      M(2, 2) = q(4, 1)
      M(3, 2) = sqrt(q(1, 1)) + 4
      M(1, 3) = cos(q(3, 1))
      M(2, 3) = 5
      M(3, 3) = 0)r   r6   r   r   r7   r8   r   r	   )	r?   rL   rN   Zmatr   r   r   r   r   rD   rD   rE   test_Matrix_printing  s&   ,6	
$r   c                  C   sD   t d\} }t| tdddt|| | g}t|}|dks J d S )Nr   r   r_   r^   z3      do x = 0, 10, 2
         y = x*y
      end do)r   r!   r   r"   r8   )r?   rL   fZsolrD   rD   rE   test_fcode_For  s    r   c            
      C   s   dd } t ddd}t|}t|}| |d t d\}}t|tdthd	}t|}| |d
 t|td}t|}	| |	d | td | td | tdttid | tdttid d S )Nc                 [   s"   t | fddd||ksJ d S )NrP   rQ   rR   ru   )r   refkwargsrD   rD   rE   check  s   "z%test_fcode_Declaration.<locals>.checkr   TrM   zinteger*4 :: ir   *   )valueZattrszreal*4, parameter :: x = 42typezlogical :: yzreal*4zreal*8)Ztype_aliases)	r   r%   Zdeducedr$   r&   r(   r*   r'   r)   )
r   r   Zvar1Zdcl1r?   rL   Zvar2Zdcl2bZvar3Zdcl3rD   rD   rE   test_fcode_Declaration  s    





r   c                  C   sx   t ddd} t ddd}t ddd}t| d dksJ td| d  dks(J |d || | }t|d	ks:J d S )
Nr   r]   r\   BCr   z      A(1, 1)z      3*A(1, 1)z      (A - B)(1, 1))r7   r8   Zsubs)r   r   r   FrD   rD   rE   test_MatrixElement_printing  s   r   c                  C   s(   t d} tt| dddddksJ d S )Nr?   +r]   rQ   r`   z	x = x + 1)r   r8   r#   rV   rD   rD   rE   test_aug_assign  s    r   c                  C   s8   t d} ttt| dkt| ddgdddksJ d S )Nr?   r]   -rQ   r`   z)do while (abs(x) > 1)
   x = x - 1
end do)r   r8   r+   absr#   rV   rD   rD   rE   
test_While	  s   "r   c                     sR   t d} t ddd}t| td}t|td}ttd||g tt fdd d S )	Nr?   r[   TrM   r   powerc                      r   rU   ru   rD   fp1rD   rE   rW     r   z.test_FunctionPrototype_print.<locals>.<lambda>)r   r%   r)   r.   r,   r=   rX   )r?   r[   vxvnrD   r   rE   test_FunctionPrototype_print  s   r   c                     sj   t d} t ddd}t| td}t|td}t| | | t| g}ttd||g| tt fdd d S )	Nr?   r[   TrM   r   r   c                      r   rU   ru   rD   Zfd1rD   rE   rW   &  r   z/test_FunctionDefinition_print.<locals>.<lambda>)	r   r%   r)   r.   r"   r/   r-   r=   rX   )r?   r[   r   r   bodyrD   r   rE   test_FunctionDefinition_print  s   r   c                  C   s4   t   dd l} W d    d S 1 sw   Y  d S )Nr   )r>   Zsympy.printing.fcode)sympyrD   rD   rE   test_fcode_submodule(  s   
"r   N)qr   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    Zsympy.codegenr!   r"   r#   Zsympy.codegen.astr$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   Zsympy.core.relationalr0   Zsympy.logic.boolalgr1   r2   r3   r4   r5   Zsympy.matricesr6   r7   Zsympy.printing.fortranr8   r9   Zsympy.tensorr:   r;   Zsympy.utilities.lambdifyr<   Zsympy.testing.pytestr=   r>   rK   rY   rb   rf   rj   rl   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   rD   rD   rD   rE   <module>   sh    8	

	1c
+<		?#
	