
    sgB                         d dl mZ d dlmZmZmZmZmZmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d dl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! d d
l"m#Z# dGdZ$d Z%d Z&d Z'd Z(d Z)d Z*d Z+d Z,d Z-d Z.d Z/d Z0d Z1d Z2d Z3d Z4d Z5d Z6d Z7d Z8d  Z9d! Z:d" Z;d# Z<d$ Z=d% Z>d& Z?d' Z@d( ZAd) ZBd* ZCd+ ZDd, ZEd- ZFd. ZGd/ ZHd0 ZId1 ZJd2 ZKd3 ZLd4 ZMd5 ZNd6 ZOd7 ZPd8 ZQd9 ZRd: ZSd; ZTd< ZUd= ZVd> ZWd? ZXd@ ZYdA ZZdB Z[dC Z\dD Z]dE Z^yF)H    )StringIO)symbolsEqpiCatalanLambdaDummyEquality)Symbol)erf)Integral)MatrixMatrixSymbol)codegenmake_routineCCodeGen
C89CodeGen
C99CodeGenInputArgumentCodeGenErrorFCodeGenCodeGenArgumentListErrorOutputArgumentInOutArgument)raises)implemented_functionc                 r    t               } | |||||       |j                         }|j                          |S )a5  Wrapper for dump_fn. dump_fn writes its results to a stream object and
       this wrapper returns the contents of that stream as a string. This
       auxiliary function is used by many tests below.

       The header and the empty lines are not generated to facilitate the
       testing of the output.
    )r   getvalueclose)dump_fnroutinesprefixheaderemptyoutputsources          U/var/www/html/venv/lib/python3.12/site-packages/sympy/utilities/tests/test_codegen.py
get_stringr)      s5     ZFHfffe4__F
LLNM    c                  Z  	
 t        d      \  

z   z  	t        t        	
fd       t        t        	
fd       t        dt	        	      
g      } | j
                  D cg c]  }|j                   c}
gk(  sJ | j
                  D cg c]  }t        |       c}t        t        t        t        gk(  sJ t        dt	        	      
g      } | j
                  D cg c]  }t        |       c}t        t        t        gk(  sJ ddlm}m} t        |dd	g      \  }}t        d
d      } |d|      }t        dt	        ||   ||         |||g      } | j
                  D cg c]  }|j                   c}|j                  |j                  |gk(  sJ t!        
z  z  
ddfddf      	t        dt	        	      
g      } | j
                  D cg c]  }|j                   c}
gk(  sJ y c c}w c c}w c c}w c c}w c c}w )Nza x y zc                  $    t        d g      S Ntestargument_sequencer   )exprxzs   r(   <lambda>z-test_Routine_argument_order.<locals>.<lambda>&   s    \&$V.% r*   c                  :    t        dt               g      S r-   )r   r   )ar2   r3   yr4   s   r(   r5   z-test_Routine_argument_order.<locals>.<lambda>(   s$    \&"QC%&1I./ r*   r.   r/   r   IndexedBaseIdxABmTintegeri         )r   r   r   r   r   	argumentsnametyper   r   r   sympy.tensorr:   r;   maplabelr   )rargr:   r;   r<   r=   r>   rA   r7   r2   r3   r8   r4   s           @@@@@r(   test_Routine_argument_orderrM   #   s	   #JAq!QE19D
# &% &
# &/ 0VR4[Q1aLIA!".#SXX.1aA,>>>"#++/3T#Y/}nm4G G G GVR4[Q1IFA"#++/3T#Y/}m46 6 6 6 .{S#J'DAqT"ACAVR!ad^1ayIA!".#SXX.177AGGQ2GGGGAaCEAq!9q!Qi0DVR4[Q1aLIA!".#SXX.1aA,>>>! // 0 / /s   4H!H8H?H#4H(c                  R    t               } t        | j                  g       }|dk(  sJ y )Nz$#include "file.h"
#include <math.h>
r   r)   dump_ccode_genr'   s     r(   test_empty_c_coderS   >   s(    |H,F????r*   c                  p    t               } t        | j                  g d      }|d d dk(  sJ |dd  dk(  sJ y )NTr$   R   zR/******************************************************************************
 *   a  *
 *                                                                            *
 *              See http://www.sympy.org/ for more information.               *
 *                                                                            *
 *                       This file is part of 'project'                       *
 ******************************************************************************/
#include "file.h"
#include <math.h>
rO   rQ   s     r(   test_empty_c_code_with_commentrX   D   sV    |HD9F#2;]   #$< ["   r*   c                  R    t               } t        | j                  g       }|dk(  sJ y )Nz9#ifndef PROJECT__FILE__H
#define PROJECT__FILE__H
#endif
)r   r)   dump_hrQ   s     r(   test_empty_c_headerr[   V   s(    |H,FSSSSr*   c                      t        d      \  } }}| |z   |z  }t        d|      }t               }t        |j                  |g      }d}||k(  sJ y )Nx,y,zr.   #include "file.h"
#include <math.h>
double test(double x, double y, double z) {
   double test_result;
   test_result = z*(x + y);
   return test_result;
}
r   r   r   r)   rP   r3   r8   r4   r2   routinerR   r'   expecteds           r(   test_simple_c_coderc   \   s^    gGAq!E19D64(G|H'3F	  Xr*   c                      t        d      \  } }}| |z   |z  }t        d|      }t               }t        |j                  |g      }d}||k(  sJ y )Nzif, typedef, whiler.   z#include "file.h"
#include <math.h>
double test(double if_, double typedef_, double while_) {
   double test_result;
   test_result = while_*(if_ + typedef_);
   return test_result;
}
)r   r   r   r)   rP   r`   s           r(   test_c_code_reserved_wordsre   n   s_    *+GAq!EQ;D64(G|H'3F	  Xr*   c                      t        dt        t        z        } t               }t	        |j
                  | g      }dt        j                  d      z  }||k(  sJ y )Nr.   z#include "file.h"
#include <math.h>
double test() {
   double test_result;
   double const Catalan = %s;
   test_result = pow(M_PI, Catalan);
   return test_result;
}
   )r   r   r   r   r)   rP   evalfra   rR   r'   rb   s       r(   test_numbersymbol_c_coderj      sU    62w;/G|H'3F	 	b	H Xr*   c                      t        d      \  } }}| |z   }t        d||| |g      }t               }t        |j                  |g      }d}||k(  sJ y )Nr]   r.   r/   z#include "file.h"
#include <math.h>
double test(double z, double x, double y) {
   double test_result;
   test_result = x + y;
   return test_result;
}
r_   r`   s           r(   test_c_code_argument_orderrl      sb    gGAq!q5D64Aq!9EG|H'3F	  Xr*   c                      t        d      \  } }}| |z   |z  }t        d|      }t               }t        |j                  |g      }d}||k(  sJ y )Nr]   r.   d#ifndef PROJECT__FILE__H
#define PROJECT__FILE__H
double test(double x, double y, double z);
#endif
)r   r   r   r)   rZ   r`   s           r(   test_simple_c_headerro      s^    gGAq!E19D64(G|H'3F	  Xr*   c                  l    t        d      \  } }}| |z   |z  }ddg}t        d|fdddd      }||k(  sJ y )	Nr]   )file.cr^   )file.hrn   r.   CfileFr$   r%   r   r   )r3   r8   r4   r2   rb   results         r(   test_simple_c_codegenrx      sV    gGAq!E19D		H fd^S&eLFXr*   c                      t        d      \  } }}| |z   |z  }| |z
  |z  }t        d||g      t               t        t        fd       y )Nr]   r.   c                  2    t         j                  g      S Nr)   rZ   rR   ra   s   r(   r5   z)test_multiple_results_c.<locals>.<lambda>       HOOgY!G r*   )r   r   r   r   r   r3   r8   r4   expr1expr2rR   ra   s        @@r(   test_multiple_results_cr      sU    gGAq!UAIEUAIE	G |H
<GHr*   c                  &    t        t        d        y )Nc                      t        dg       S Nr.   r1    r*   r(   r5   z#test_no_results_c.<locals>.<lambda>       |FB7 r*   r   
ValueErrorr   r*   r(   test_no_results_cr          
:78r*   c                     ddl m}  ddlm} ddlm}m}m} ddlm	}m
} ddlm} ddlm}m}	m}
m}m}m} t)        d      }d	 | |      fd
 ||      fd |	|      fd |
|      fd ||      fd ||      fd ||      fd ||      fd ||      fd ||      fd ||      fd ||      fd ||      fd ||      fd ||      fg}t+        |dddd      }|d   d   dk(  sJ |d   d   dk(  sJ |d   d   dk(  sJ |d   d   d k(  sJ y )!Nr   Abslogcoshsinhtanh)ceilingfloorsqrtacosasinatancossintanr3   	test_fabs	test_acos	test_asin	test_atan	test_ceiltest_cos	test_cosh
test_floortest_logtest_lntest_sin	test_sinh	test_sqrttest_tan	test_tanhC89rt   Fru   rq   rB   a  #include "file.h"
#include <math.h>
double test_fabs(double x) {
   double test_fabs_result;
   test_fabs_result = fabs(x);
   return test_fabs_result;
}
double test_acos(double x) {
   double test_acos_result;
   test_acos_result = acos(x);
   return test_acos_result;
}
double test_asin(double x) {
   double test_asin_result;
   test_asin_result = asin(x);
   return test_asin_result;
}
double test_atan(double x) {
   double test_atan_result;
   test_atan_result = atan(x);
   return test_atan_result;
}
double test_ceil(double x) {
   double test_ceil_result;
   test_ceil_result = ceil(x);
   return test_ceil_result;
}
double test_cos(double x) {
   double test_cos_result;
   test_cos_result = cos(x);
   return test_cos_result;
}
double test_cosh(double x) {
   double test_cosh_result;
   test_cosh_result = cosh(x);
   return test_cosh_result;
}
double test_floor(double x) {
   double test_floor_result;
   test_floor_result = floor(x);
   return test_floor_result;
}
double test_log(double x) {
   double test_log_result;
   test_log_result = log(x);
   return test_log_result;
}
double test_ln(double x) {
   double test_ln_result;
   test_ln_result = log(x);
   return test_ln_result;
}
double test_sin(double x) {
   double test_sin_result;
   test_sin_result = sin(x);
   return test_sin_result;
}
double test_sinh(double x) {
   double test_sinh_result;
   test_sinh_result = sinh(x);
   return test_sinh_result;
}
double test_sqrt(double x) {
   double test_sqrt_result;
   test_sqrt_result = sqrt(x);
   return test_sqrt_result;
}
double test_tan(double x) {
   double test_tan_result;
   test_tan_result = tan(x);
   return test_tan_result;
}
double test_tanh(double x) {
   double test_tanh_result;
   test_tanh_result = tanh(x);
   return test_tanh_result;
}
rr   a  #ifndef PROJECT__FILE__H
#define PROJECT__FILE__H
double test_fabs(double x);
double test_acos(double x);
double test_asin(double x);
double test_atan(double x);
double test_ceil(double x);
double test_cos(double x);
double test_cosh(double x);
double test_floor(double x);
double test_log(double x);
double test_ln(double x);
double test_sin(double x);
double test_sinh(double x);
double test_sqrt(double x);
double test_tan(double x);
double test_tanh(double x);
#endif
)$sympy.functions.elementary.complexesr   &sympy.functions.elementary.exponentialr   %sympy.functions.elementary.hyperbolicr   r   r   #sympy.functions.elementary.integersr   r   (sympy.functions.elementary.miscellaneousr   (sympy.functions.elementary.trigonometricr   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r3   	name_exprrw   s                    r(   test_ansi_math1_codegenr      s_   8:HHD=ZZA	c!f	d1g	d1g	d1g	gaj!	SV	d1g	uQx 	SV	CF	SV	d1g	d1g	SV	d1gI" Yve5IF!9Q<8###!9Q<	F  $ !9Q<8###!9Q<	0
 
 
r*   c                      ddl m}  t        d      \  }}d | ||      fd||z  fg}t        |dddd	      }|d   d   d
k(  sJ |d   d   dk(  sJ |d   d   dk(  sJ |d   d   dk(  sJ y )Nr   atan2x,y
test_atan2test_powr   rt   Fru   rq   rB   a*  #include "file.h"
#include <math.h>
double test_atan2(double x, double y) {
   double test_atan2_result;
   test_atan2_result = atan2(x, y);
   return test_atan2_result;
}
double test_pow(double x, double y) {
   double test_pow_result;
   test_pow_result = pow(x, y);
   return test_pow_result;
}
rr   z#ifndef PROJECT__FILE__H
#define PROJECT__FILE__H
double test_atan2(double x, double y);
double test_pow(double x, double y);
#endif
r   r   r   r   )r   r3   r8   r   rw   s        r(   test_ansi_math2_codegenr     s    >5>DAq	uQ{#	QTI Yve5IF!9Q<8###!9Q<	N  
 !9Q<8###!9Q<	  r*   c                     ddl m} m}m} t	        d      \  }}}d ||       | |      z    ||      z   dz  j                         fd |  |  |  |  |  |  |  | ||z   |z                                                   fg}t        |ddd	d	
      }|d   d   dk(  sJ |d   d   dk(  sJ |d   d   dk(  sJ |d   d   dk(  sJ y )Nr   r   r   r   r]   test1   test2r   rt   Fru   rq   rB   a-  #include "file.h"
#include <math.h>
double test1(double x, double y, double z) {
   double test1_result;
   test1_result = pow(sin(x), 7) + 7*pow(sin(x), 6)*cos(y) + 7*pow(sin(x), 6)*tan(z) + 21*pow(sin(x), 5)*pow(cos(y), 2) + 42*pow(sin(x), 5)*cos(y)*tan(z) + 21*pow(sin(x), 5)*pow(tan(z), 2) + 35*pow(sin(x), 4)*pow(cos(y), 3) + 105*pow(sin(x), 4)*pow(cos(y), 2)*tan(z) + 105*pow(sin(x), 4)*cos(y)*pow(tan(z), 2) + 35*pow(sin(x), 4)*pow(tan(z), 3) + 35*pow(sin(x), 3)*pow(cos(y), 4) + 140*pow(sin(x), 3)*pow(cos(y), 3)*tan(z) + 210*pow(sin(x), 3)*pow(cos(y), 2)*pow(tan(z), 2) + 140*pow(sin(x), 3)*cos(y)*pow(tan(z), 3) + 35*pow(sin(x), 3)*pow(tan(z), 4) + 21*pow(sin(x), 2)*pow(cos(y), 5) + 105*pow(sin(x), 2)*pow(cos(y), 4)*tan(z) + 210*pow(sin(x), 2)*pow(cos(y), 3)*pow(tan(z), 2) + 210*pow(sin(x), 2)*pow(cos(y), 2)*pow(tan(z), 3) + 105*pow(sin(x), 2)*cos(y)*pow(tan(z), 4) + 21*pow(sin(x), 2)*pow(tan(z), 5) + 7*sin(x)*pow(cos(y), 6) + 42*sin(x)*pow(cos(y), 5)*tan(z) + 105*sin(x)*pow(cos(y), 4)*pow(tan(z), 2) + 140*sin(x)*pow(cos(y), 3)*pow(tan(z), 3) + 105*sin(x)*pow(cos(y), 2)*pow(tan(z), 4) + 42*sin(x)*cos(y)*pow(tan(z), 5) + 7*sin(x)*pow(tan(z), 6) + pow(cos(y), 7) + 7*pow(cos(y), 6)*tan(z) + 21*pow(cos(y), 5)*pow(tan(z), 2) + 35*pow(cos(y), 4)*pow(tan(z), 3) + 35*pow(cos(y), 3)*pow(tan(z), 4) + 21*pow(cos(y), 2)*pow(tan(z), 5) + 7*cos(y)*pow(tan(z), 6) + pow(tan(z), 7);
   return test1_result;
}
double test2(double x, double y, double z) {
   double test2_result;
   test2_result = cos(cos(cos(cos(cos(cos(cos(cos(x + y + z))))))));
   return test2_result;
}
rr   z#ifndef PROJECT__FILE__H
#define PROJECT__FILE__H
double test1(double x, double y, double z);
double test2(double x, double y, double z);
#endif
r   r   r   r   r   expandr   )r   r   r   r3   r8   r4   r   rw   s           r(   test_complicated_codegenr   ,  s   HHgGAq!	CFSVOc!f,q088:;	#c#c#c#c!a%!)n*=&>"?@ABCDI Yve5IF!9Q<8###!9Q<.	0 0 0b !9Q<8###!9Q<	  r*   c            	         ddl m} m} ddlm}  |dd      \  }} | d      } | d      } | d	      } |d
|      } |d|      }	t        dt        ||   |||	f   ||	   z        fdddd      \  \  }
}\  }}|
dk(  sJ d}||dd||z  |	z   z  iz  k(  s;||dd|	||z  z   z  iz  k(  s(||dd||z  |	z   z  iz  k(  s||dd|	||z  z   z  iz  k(  sJ |dk(  sJ |dk(  sJ y )Nr   r9   r   n mTr?   r<   r3   r8   rA   jmatrix_vectorC99rt   Fru   rq   a  #include "file.h"
#include <math.h>
void matrix_vector(double *A, int m, int n, double *x, double *y) {
   for (int i=0; i<m; i++){
      y[i] = 0;
   }
   for (int i=0; i<m; i++){
      for (int j=0; j<n; j++){
         y[i] = %(rhs)s + y[i];
      }
   }
}
rhs
A[%s]*x[j]
x[j]*A[%s]rr   z|#ifndef PROJECT__FILE__H
#define PROJECT__FILE__H
void matrix_vector(double *A, int m, int n, double *x, double *y);
#endif
rH   r:   r;   sympy.core.symbolr   r   r   r:   r;   r   nr>   r<   r3   r8   rA   r   f1codef2	interfacerb   s                  r(   test_loops_cr   p  sW   -)5$'DAqCACACACACA")	"QqT1QT71Q4<015&V[#]JRY >>	  H|qsQw'?@@@H|q1Q3w'?@@@H|qsQw'?@@@H|q1Q3w'?@@@B A >>	  r*   c                     ddl m} m} t        ddt              \  }} | d      } | d      } |||      }d|j
                  j                  |j                  d	z  }t        d
t        ||   ||               }t               }t               }	t        |	j                  |g      }
|
|k(  sJ t        t              5  t        |j                  |g       d d d        y # 1 sw Y   y xY w)Nr   r9   i mTr@   clsr3   r8   z#include "file.h"
#include <math.h>
void test_dummies(int m_%(mno)i, double *x, double *y) {
   for (int i_%(ino)i=0; i_%(ino)i<m_%(mno)i; i_%(ino)i++){
      y[i_%(ino)i] = x[i_%(ino)i];
   }
}
)inomnotest_dummies)rH   r:   r;   r   r	   rJ   dummy_indexr   r   r   r   r)   rP   r   NotImplementedError)r:   r;   rA   r>   r3   r8   rb   rK   c89c99r   s              r(   test_dummy_loops_cr     s    -5$E2DAqCACAAq	A	 ##AMM:;H 	^R!ad^4A
,C
,Ccjj1#&D8	#	$ $3::s#$ $ $s   :CC$c            	         ddl m} m} ddlm}  |dd      \  }}}} | d||f      } | d	      } | d
      }	 |d||dz
  f      }
 |d|      }t        dt        |	|
   ||
|f   ||   z        fdddd      \  \  }}\  }}|dk(  sJ d|dz
  ddz  }||dd|
|z  |z   z  iz  k(  s;||dd||
|z  z   z  iz  k(  s(||dd|
|z  |z   z  iz  k(  s||dd||
|z  z   z  iz  k(  sJ |dk(  sJ |dk(  sJ y )Nr   r9   r   n m o pTr?   r<   shaper3   r8   rA      r   r   r   rt   Fru   rq   a#  #include "file.h"
#include <math.h>
void matrix_vector(double *A, int m, int n, int o, int p, double *x, double *y) {
   for (int i=o; i<%(upperi)s; i++){
      y[i] = 0;
   }
   for (int i=o; i<%(upperi)s; i++){
      for (int j=0; j<n; j++){
         y[i] = %(rhs)s + y[i];
      }
   }
}
   %(rhs)s)upperir   r   r   r   rr   z#ifndef PROJECT__FILE__H
#define PROJECT__FILE__H
void matrix_vector(double *A, int m, int n, int o, int p, double *x, double *y);
#endif
r   r:   r;   r   r   r>   opr<   r3   r8   rA   r   r   r   r   r   rb   s                    r(   test_partial_loops_cr     s|    .)D1JAq!QC1v&ACACAC!QUACA")	"QqT1QT71Q4<015&V[#]JRY >>	 q5+,H H|qsQw'?@@@H|q1Q3w'?@@@H|qsQw'?@@@H|q1Q3w'?@@@B A >>	  r*   c            	          ddl m}  ddlm}m} t        d      \  }}}t        d | | ||             ||      g      }t               }|j                  |gddd      }|d   d   d	k(  sJ d
}	|d   d   |	k(  sJ y )Nr   r
   r   r   r]   foor.   Fru   test.cz#include "test.h"
#include <math.h>
double foo(double x, double *y) {
   (*y) = sin(x);
   double foo_result;
   foo_result = cos(x);
   return foo_result;
}
rB   	sympy.core.relationalr   r   r   r   r   r   r   write
r   r   r   r3   r8   r4   rK   crw   rb   s
             r(   test_output_arg_cr     s    .CgGAq!UXaQ0#a&9:AAWWaS&eW<F!9Q<8###	  !9Q<8###r*   c            	          ddl m}  ddlm}m} t        d      \  }}}t        d | | ||             ||      g      }t               }|j                  |gddd      }|d   d   d	k(  sJ d
}	|d   d   |	k(  sJ y )Nr   r
   r   zif, while, zr   r.   Fru   r   z#include "test.h"
#include <math.h>
double foo(double if_, double *while_) {
   (*while_) = sin(if_);
   double foo_result;
   foo_result = cos(if_);
   return foo_result;
}
rB   r   r   s
             r(    test_output_arg_c_reserved_wordsr     s    .Cn%GAq!UXaQ0#a&9:AAWWaS&eW<F!9Q<8###	  !9Q<8###r*   c                  @   t        ddd      } t        ddd      }t        |       }t        |      }||z  }t        dd      }|j                  d|      }d	|j                  d
   _        d	|j                  d
   _        t        |j                  |gd      }d}||k(  sJ y )Nr<   rD   brB   r.   T)projectcser   out)r#   z#include "test.h"
#include <math.h>
void c(double *A, double *b, double *out) {
   out[0] = A[0]*b[0] + A[1]*b[1] + A[2]*b[2];
   out[1] = A[3]*b[0] + A[4]*b[1] + A[5]*b[2];
   out[2] = A[6]*b[0] + A[7]*b[1] + A[8]*b[2];
}
)	r   r   r   ra   rE   
result_var_namer)   rP   )	A_symb_symr<   r   r   cgenrK   r   rb   s	            r(   test_multidim_c_argument_cser	    s    a#Ea#EuAuA	!AF-DS!A!&AKKO!AKKOdkkA3v6D	  8r*   c                  *   t        d      \  } }}t        d      \  }}t        ddd      }t        |t        dd| gg            }t        || |z   |z        }t        |d| z        }d|||gf}	d}
t	        |	d	dd
d
| |||||f      }|d   d   }||
k(  sJ y )Nr]   B,Cr<   rB   rD   rC   r.   z#include "test.h"
#include <math.h>
void test(double x, double *C, double z, double y, double *A, double *B) {
   (*C) = z*(x + y);
   A[0] = 1;
   A[1] = 2;
   A[2] = x;
   (*B) = 2*x;
}
r   Fr$   r%   r0   r   r   r   r   r   r   )r3   r8   r4   r=   rs   r<   r   r   expr3r   rb   rw   r'   s                r(    test_ccode_results_named_orderedr    s    gGAq!5>DAqS!QAQAq	{+,EQQ	"EQ!E%./I	  YVE()1aAq'9;FAYq\FXr*   c            	      "   t        ddd      } t        ddd      }t        ddd      }t        ddd      }dt        || d	d d f         t        || dd d f         t        || d d d
f         gf}t        |dddd      }|d	   d   }d}||k(  sJ y )Nr<   r   rD   r=   rB   rs   Dr.   r   rC   r   Fru   a  #include "test.h"
#include <math.h>
void test(double *A, double *B, double *C, double *D) {
   B[0] = A[0];
   B[1] = A[1];
   B[2] = A[2];
   C[0] = A[3];
   C[1] = A[4];
   C[2] = A[5];
   D[0] = A[2];
   D[1] = A[5];
   D[2] = A[8];
   D[3] = A[11];
   D[4] = A[14];
}
r   r   r   r<   r=   rs   r  r   rw   r'   rb   s           r(   test_ccode_matrixsymbol_slicer  8  s    S!QAS!QAS!QAS!QA(1a1g."1a1g."1a1g.0 1I Yve5IFAYq\F	 " Xr*   c            
          t        d      \  } }}}t        ddd      }dt        |t        | |z  g| |z  ||z  z   g| |z  |z  |z  gg            gf}t	        d      }t        ||dd	      }|d
   d   }d}	||	k(  sJ y )Nza b c derD   rB   r.   T)r  F)rR   r$   r%   r   z#include "test.h"
#include <math.h>
void test(double a, double b, double c, double d, double *e) {
   const double x0 = a*b;
   const double x1 = c*d;
   e[0] = x0;
   e[1] = x0 + x1;
   e[2] = x0*x1;
}
)r   r   r   r   r   r   )
r7   r   r   dr  r   	generatorrw   r'   rb   s
             r(   test_ccode_cser  U  s    #JAq!QS!QA(1fqseacAaCi[1Q3q57)-L&MNOPIT"IY5NFAYq\F	  Xr*   c                  z    t        ddd      } d}t               }t        ||dd| f      }|d   d   }d}||k(  sJ y )	Nr3   rC   rB   )r.   g      ?F)rR   r$   r%   r0   r   z#include "test.h"
#include <math.h>
double test(double *x) {
   double test_result;
   test_result = 1.0;
   return test_result;
}
)r   r   r   )r3   r   r  rw   r'   rb   s         r(   test_ccode_unused_array_argr  i  sY    S!QAI
IY5bcaefFAYq\F	  Xr*   c            	          t        ddd      } t        ddd      }t        dd      }d| d	   | d   z   f}t        |d
dd| ||f      }|d	   d   }d}||k(  sJ y )NXrD   rB   Yr4   Tr?   testBugr   rs   F)languager$   r%   r0   z#include "testBug.h"
#include <math.h>
double testBug(double *X, double *Y, int z) {
   double testBug_result;
   testBug_result = X[0] + X[1];
   return testBug_result;
}
)r   r   r   )r  r  r4   r   rw   r'   rb   s          r(    test_ccode_unused_array_arg_funcr!  |  s    S1AS1Ad#AAaD1Q4K(IYU%\]_`bc[deFAYq\F	  Xr*   c                  R    t               } t        | j                  g       }|dk(  sJ y N r   r)   dump_f95rQ   s     r(   test_empty_f_coder'    s'    zH))2.FR<<r*   c                  p    t               } t        | j                  g d      }|d d dk(  sJ |dd  dk(  sJ y )NTrU   rV   zR!******************************************************************************
!*rW   a  *
!*                                                                            *
!*              See http://www.sympy.org/ for more information.               *
!*                                                                            *
!*                       This file is part of 'project'                       *
!******************************************************************************
r%  rQ   s     r(   test_empty_f_code_with_headerr)    sY    zH))2d;F#2;]   #$< [`   r*   c                  R    t               } t        | j                  g       }|dk(  sJ y r#  )r   r)   rZ   rQ   s     r(   test_empty_f_headerr+    s%    zH,FR<<r*   c                      t        d      \  } }}| |z   |z  }t        d|      }t               }t        |j                  |g      }d}||k(  sJ y )Nr]   r.   REAL*8 function test(x, y, z)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(in) :: y
REAL*8, intent(in) :: z
test = z*(x + y)
end function
r   r   r   r)   r&  r`   s           r(   test_simple_f_coder/    s`    gGAq!E19D64(GzH))G95F	  Xr*   c                      t        dt        t        z        } t               }t	        |j
                  | g      }dt        j                  d      dt        j                  d      d}||k(  sJ y )Nr.   zDREAL*8 function test()
implicit none
REAL*8, parameter :: Catalan = rg   zd0
REAL*8, parameter :: pi = z#d0
test = pi**Catalan
end function
)r   r   r   r   r)   r&  rh   ri   s       r(   test_numbersymbol_f_coder1    s\    62w;/GzH))G95F 
r	BHHRL*H Xr*   c                      t        d      } t        dt        |       t        d| z        z
        }t               }t	        |j
                  |g      }d}||k(  sJ |       y )Nr3   r.   zhREAL*8 function test(x)
implicit none
REAL*8, intent(in) :: x
test = erf(x) + erf(2.0d0*x)
end function
)r   r   r   r   r)   r&  )r3   ra   rR   r'   rb   s        r(   test_erf_f_coder4    sb    A63q6CQK#78GzH))G95F	  X%v%r*   c                      t        d      \  } }}| |z   }t        d||| |g      }t               }t        |j                  |g      }d}||k(  sJ y )Nr]   r.   r/   zREAL*8 function test(z, x, y)
implicit none
REAL*8, intent(in) :: z
REAL*8, intent(in) :: x
REAL*8, intent(in) :: y
test = x + y
end function
r.  r`   s           r(   test_f_code_argument_orderr6    sd    gGAq!q5D64Aq!9EGzH))G95F	  Xr*   c                      t        d      \  } }}| |z   |z  }t        d|      }t               }t        |j                  |g      }d}||k(  sJ y )Nr]   r.   interface
REAL*8 function test(x, y, z)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(in) :: y
REAL*8, intent(in) :: z
end function
end interface
)r   r   r   r)   rZ   r`   s           r(   test_simple_f_headerr9    s^    gGAq!E19D64(GzH'3F	  Xr*   c                  l    t        d      \  } }}| |z   |z  }t        d|fdddd      }ddg}||k(  sJ y )	Nr]   r.   F95rt   Fru   )file.f90r-  )rr   r8  rv   )r3   r8   r4   r2   rw   rb   s         r(   test_simple_f_codegenr=    sZ    gGAq!E19D	ve5BF		H& Xr*   c                      t        d      \  } }}| |z   |z  }| |z
  |z  }t        d||g      t               t        t        fd       y )Nr]   r.   c                  2    t         j                  g      S r{   r|   r}   s   r(   r5   z)test_multiple_results_f.<locals>.<lambda>"  r~   r*   )r   r   r   r   r   r   s        @@r(   test_multiple_results_fr@    sU    gGAq!UAIEUAIE	G zH
<GHr*   c                  &    t        t        d        y )Nc                      t        dg       S r   r1   r   r*   r(   r5   z#test_no_results_f.<locals>.<lambda>&  r   r*   r   r   r*   r(   test_no_results_frC  %  r   r*   c                     ddl m}  ddlm} ddlm}m}m} ddlm	} ddl
m}m}m}m}	m}
m} t#        d      }d | |      fd	 ||      fd
 ||      fd ||      fd |	|      fd ||      fd ||      fd ||      fd |
|      fd ||      fd ||      fd ||      fd ||      fg}t%        |dddd      }|d   d   dk(  sJ d}|d   d   |k(  sJ |d   d   dk(  sJ d}|d   d   |k(  sJ y )Nr   r   r   r   r   r   r3   test_absr   r   r   r   r   r   r   r   r   r   r   r   r;  rt   Fru   r<  a   REAL*8 function test_abs(x)
implicit none
REAL*8, intent(in) :: x
test_abs = abs(x)
end function
REAL*8 function test_acos(x)
implicit none
REAL*8, intent(in) :: x
test_acos = acos(x)
end function
REAL*8 function test_asin(x)
implicit none
REAL*8, intent(in) :: x
test_asin = asin(x)
end function
REAL*8 function test_atan(x)
implicit none
REAL*8, intent(in) :: x
test_atan = atan(x)
end function
REAL*8 function test_cos(x)
implicit none
REAL*8, intent(in) :: x
test_cos = cos(x)
end function
REAL*8 function test_cosh(x)
implicit none
REAL*8, intent(in) :: x
test_cosh = cosh(x)
end function
REAL*8 function test_log(x)
implicit none
REAL*8, intent(in) :: x
test_log = log(x)
end function
REAL*8 function test_ln(x)
implicit none
REAL*8, intent(in) :: x
test_ln = log(x)
end function
REAL*8 function test_sin(x)
implicit none
REAL*8, intent(in) :: x
test_sin = sin(x)
end function
REAL*8 function test_sinh(x)
implicit none
REAL*8, intent(in) :: x
test_sinh = sinh(x)
end function
REAL*8 function test_sqrt(x)
implicit none
REAL*8, intent(in) :: x
test_sqrt = sqrt(x)
end function
REAL*8 function test_tan(x)
implicit none
REAL*8, intent(in) :: x
test_tan = tan(x)
end function
REAL*8 function test_tanh(x)
implicit none
REAL*8, intent(in) :: x
test_tanh = tanh(x)
end function
rB   rr   aA  interface
REAL*8 function test_abs(x)
implicit none
REAL*8, intent(in) :: x
end function
end interface
interface
REAL*8 function test_acos(x)
implicit none
REAL*8, intent(in) :: x
end function
end interface
interface
REAL*8 function test_asin(x)
implicit none
REAL*8, intent(in) :: x
end function
end interface
interface
REAL*8 function test_atan(x)
implicit none
REAL*8, intent(in) :: x
end function
end interface
interface
REAL*8 function test_cos(x)
implicit none
REAL*8, intent(in) :: x
end function
end interface
interface
REAL*8 function test_cosh(x)
implicit none
REAL*8, intent(in) :: x
end function
end interface
interface
REAL*8 function test_log(x)
implicit none
REAL*8, intent(in) :: x
end function
end interface
interface
REAL*8 function test_ln(x)
implicit none
REAL*8, intent(in) :: x
end function
end interface
interface
REAL*8 function test_sin(x)
implicit none
REAL*8, intent(in) :: x
end function
end interface
interface
REAL*8 function test_sinh(x)
implicit none
REAL*8, intent(in) :: x
end function
end interface
interface
REAL*8 function test_sqrt(x)
implicit none
REAL*8, intent(in) :: x
end function
end interface
interface
REAL*8 function test_tan(x)
implicit none
REAL*8, intent(in) :: x
end function
end interface
interface
REAL*8 function test_tanh(x)
implicit none
REAL*8, intent(in) :: x
end function
end interface
)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   r3   r   rw   rb   s                   r(   test_intrinsic_math_codegenrF  )  sK   8:HH=ZZA	SV	d1g	d1g	d1g	SV	d1g	SV	CF	SV	d1g	d1g	SV	d1gI Yve5IF!9Q<:%%%@	 F !9Q<8###!9Q<8###M	 ` !9Q<8###r*   c                      ddl m}  t        d      \  }}d | ||      fd||z  fg}t        |dddd	      }|d   d   d
k(  sJ d}|d   d   |k(  sJ |d   d   dk(  sJ d}|d   d   |k(  sJ y )Nr   r   r   r   r   r;  rt   Fru   r<  zREAL*8 function test_atan2(x, y)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(in) :: y
test_atan2 = atan2(x, y)
end function
REAL*8 function test_pow(x, y)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(in) :: y
test_pow = x**y
end function
rB   rr   a  interface
REAL*8 function test_atan2(x, y)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(in) :: y
end function
end interface
interface
REAL*8 function test_pow(x, y)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(in) :: y
end function
end interface
r   )r   r3   r8   r   rw   rb   s         r(   test_intrinsic_math2_codegenrH    s    >5>DAq	uQ{#	QTI Yve5IF!9Q<:%%%	  !9Q<8###!9Q<8###	   !9Q<8###r*   c                     ddl m} m}m} t	        d      \  }}}d ||       | |      z    ||      z   dz  j                         fd |  |  |  |  |  |  |  | ||z   |z                                                   fg}t        |ddd	d	
      }|d   d   dk(  sJ d}|d   d   |k(  sJ |d   d   dk(  sJ d}|d   d   |k(  sJ y )Nr   r   r]   r   r   r   r;  rt   Fru   r<  a{  REAL*8 function test1(x, y, z)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(in) :: y
REAL*8, intent(in) :: z
test1 = sin(x)**7 + 7*sin(x)**6*cos(y) + 7*sin(x)**6*tan(z) + 21*sin(x) &
      **5*cos(y)**2 + 42*sin(x)**5*cos(y)*tan(z) + 21*sin(x)**5*tan(z) &
      **2 + 35*sin(x)**4*cos(y)**3 + 105*sin(x)**4*cos(y)**2*tan(z) + &
      105*sin(x)**4*cos(y)*tan(z)**2 + 35*sin(x)**4*tan(z)**3 + 35*sin( &
      x)**3*cos(y)**4 + 140*sin(x)**3*cos(y)**3*tan(z) + 210*sin(x)**3* &
      cos(y)**2*tan(z)**2 + 140*sin(x)**3*cos(y)*tan(z)**3 + 35*sin(x) &
      **3*tan(z)**4 + 21*sin(x)**2*cos(y)**5 + 105*sin(x)**2*cos(y)**4* &
      tan(z) + 210*sin(x)**2*cos(y)**3*tan(z)**2 + 210*sin(x)**2*cos(y) &
      **2*tan(z)**3 + 105*sin(x)**2*cos(y)*tan(z)**4 + 21*sin(x)**2*tan &
      (z)**5 + 7*sin(x)*cos(y)**6 + 42*sin(x)*cos(y)**5*tan(z) + 105* &
      sin(x)*cos(y)**4*tan(z)**2 + 140*sin(x)*cos(y)**3*tan(z)**3 + 105 &
      *sin(x)*cos(y)**2*tan(z)**4 + 42*sin(x)*cos(y)*tan(z)**5 + 7*sin( &
      x)*tan(z)**6 + cos(y)**7 + 7*cos(y)**6*tan(z) + 21*cos(y)**5*tan( &
      z)**2 + 35*cos(y)**4*tan(z)**3 + 35*cos(y)**3*tan(z)**4 + 21*cos( &
      y)**2*tan(z)**5 + 7*cos(y)*tan(z)**6 + tan(z)**7
end function
REAL*8 function test2(x, y, z)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(in) :: y
REAL*8, intent(in) :: z
test2 = cos(cos(cos(cos(cos(cos(cos(cos(x + y + z))))))))
end function
rB   rr   a4  interface
REAL*8 function test1(x, y, z)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(in) :: y
REAL*8, intent(in) :: z
end function
end interface
interface
REAL*8 function test2(x, y, z)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(in) :: y
REAL*8, intent(in) :: z
end function
end interface
r   )	r   r   r   r3   r8   r4   r   rw   rb   s	            r(   test_complicated_codegen_f95rJ  	  s   HHgGAq!	CFSVOc!f,q088:;	#c#c#c#c!a%!)n*=&>"?@ABCDI Yve5IF!9Q<:%%%	 < !9Q<8###!9Q<8###	 $ !9Q<8###r*   c            	      >   ddl m} m} ddlm}  |dd      \  }}t        | d      \  }}} |d|      } |d	|      }	t        d
t        ||   |||	f   ||	   z        fdddd      \  \  }
}\  }}|
dk(  sJ d}||ddiz  k(  s||ddiz  k(  sJ |dk(  sJ |dk(  sJ y )Nr   r9   r   zn,mTr?   AxyrA   r   r   r;  rt   Fru   r<  a~  subroutine matrix_vector(A, m, n, x, y)
implicit none
INTEGER*4, intent(in) :: m
INTEGER*4, intent(in) :: n
REAL*8, intent(in), dimension(1:m, 1:n) :: A
REAL*8, intent(in), dimension(1:n) :: x
REAL*8, intent(out), dimension(1:m) :: y
INTEGER*4 :: i
INTEGER*4 :: j
do i = 1, m
   y(i) = 0
end do
do i = 1, m
   do j = 1, n
      y(i) = %(rhs)s + y(i)
   end do
end do
end subroutine
r   A(i, j)*x(j)x(j)*A(i, j)rr   a  interface
subroutine matrix_vector(A, m, n, x, y)
implicit none
INTEGER*4, intent(in) :: m
INTEGER*4, intent(in) :: n
REAL*8, intent(in), dimension(1:m, 1:n) :: A
REAL*8, intent(in), dimension(1:n) :: x
REAL*8, intent(out), dimension(1:m) :: y
end subroutine
end interface
)rH   r:   r;   r   r   rI   r   r   r   s                  r(   
test_loopsrO  G  s    -)5$'DAq+u%GAq!CACA")	"QqT1QT71Q4<015&V[#]JRY 	 * 8un555E>2223 3>>		  r*   c                  D   ddl m} m} t        ddt              \  }} | d      } | d      } |||      }d|j
                  j                  |j                  d	z  }t        d
t        ||   ||               }t               }t        |j                  |g      }	|	|k(  sJ y )Nr   r9   r   Tr   r3   r8   a>  subroutine test_dummies(m_%(mcount)i, x, y)
implicit none
INTEGER*4, intent(in) :: m_%(mcount)i
REAL*8, intent(in), dimension(1:m_%(mcount)i) :: x
REAL*8, intent(out), dimension(1:m_%(mcount)i) :: y
INTEGER*4 :: i_%(icount)i
do i_%(icount)i = 1, m_%(mcount)i
   y(i_%(icount)i) = x(i_%(icount)i)
end do
end subroutine
)icountmcountr   )rH   r:   r;   r   r	   rJ   r   r   r   r   r)   r&  )
r:   r;   rA   r>   r3   r8   rb   rK   r   r   s
             r(   test_dummy_loops_f95rS  z  s    -5$E2DAqCACAAq	A		 77&&!--@AH 	^R!ad^4A
Aajj1#&D8r*   c            	         ddl m} m} ddlm}  |dd      \  }}}} |d      \  }}}	 | |       |||       |||      f   } | |       |||         } | |	       |||         }	t        dt        |	|	||z  z         fd	d
dd      \  \  }
}\  }}|
dk(  sJ d}||ddiz  k(  s||ddiz  k(  sJ |dk(  sJ |dk(  sJ y )Nr   r9   r   zi,j,n,mTr?   zA,x,yr   r;  rt   Fru   r<  aa  subroutine matrix_vector(A, m, n, x, y)
implicit none
INTEGER*4, intent(in) :: m
INTEGER*4, intent(in) :: n
REAL*8, intent(in), dimension(1:m, 1:n) :: A
REAL*8, intent(in), dimension(1:n) :: x
REAL*8, intent(inout), dimension(1:m) :: y
INTEGER*4 :: i
INTEGER*4 :: j
do i = 1, m
   do j = 1, n
      y(i) = %(rhs)s + y(i)
   end do
end do
end subroutine
r   rM  rN  rr   a  interface
subroutine matrix_vector(A, m, n, x, y)
implicit none
INTEGER*4, intent(in) :: m
INTEGER*4, intent(in) :: n
REAL*8, intent(in), dimension(1:m, 1:n) :: A
REAL*8, intent(in), dimension(1:n) :: x
REAL*8, intent(inout), dimension(1:m) :: y
end subroutine
end interface
r   )r:   r;   r   rA   r   r   r>   r<   r3   r8   r   r   r   r   rb   s                  r(   test_loops_InOutrU    s   -)D1JAq!QgGAq!As1ay#a)+,AAs1ay!AAs1ay!A")	"QAaC.)5&e#UJRY 	 $ H~666H~6668 7>>		  r*   c            	         ddl m} m} ddlm}  |dd      \  }}}} | d||f      } | d	      } | d
      }	 |d||dz
  f      }
 |d|      }t        dt        |	|
   ||
|f   ||   z        fdddd      \  \  }}\  }}ddt        |dz
        t        d|z         t        |dz
  |z
        dz  }||ddiz  k(  s||ddiz  k(  sJ y y )Nr   r9   r   r   Tr?   r<   r   r3   r8   rA   r   r   r   r;  rt   Fru   a  subroutine matrix_vector(A, m, n, o, p, x, y)
implicit none
INTEGER*4, intent(in) :: m
INTEGER*4, intent(in) :: n
INTEGER*4, intent(in) :: o
INTEGER*4, intent(in) :: p
REAL*8, intent(in), dimension(1:m, 1:p) :: A
REAL*8, intent(in), dimension(1:n) :: x
REAL*8, intent(out), dimension(1:%(iup-ilow)s) :: y
INTEGER*4 :: i
INTEGER*4 :: j
do i = %(ilow)s, %(iup)s
   y(i) = 0
end do
do i = %(ilow)s, %(iup)s
   do j = 1, n
      y(i) = %(rhs)s + y(i)
   end do
end do
end subroutine
r   r   rB   )r   iupilowziup-ilowr   rM  rN  )rH   r:   r;   r   r   r   r   strr   s                    r(   test_partial_loops_frZ    s    .)D1JAq!QC1v&ACACAC!QUACA")	"QqT1QT71Q4<015&V[#]JRY	* 1q5zAE
A	N		+H8 8un555E>2223 32 6r*   c            	          ddl m}  ddlm}m} t        d      \  }}}t        d | | ||             ||      g      }t               }|j                  |gddd      }|d   d   d	k(  sJ |d   d
   dk(  sJ y )Nr   r
   r   r]   r   r.   Fru   ztest.f90rB   z~REAL*8 function foo(x, y)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(out) :: y
y = sin(x)
foo = cos(x)
end function
)	r   r   r   r   r   r   r   r   r   )	r   r   r   r3   r8   r4   rK   r   rw   s	            r(   test_output_arg_fr\    s    .CgGAq!UXaQ0#a&9:A
AWWaS&eW<F!9Q<:%%%!9Q<	  r*   c            
      d   ddl m} m} ddlm}  |dd      \  }}t        | d      \  }}} |d|      }t               }	t        d	t        |||d
z   z              }
t        dt        ||    |
||                     }t        |	j                  |g      }d}d}|||z  k(  s|||d d d   z  k(  sJ y y )Nr   r9   r   r   Tr?   rL  rA   funcrB   test_inlinezsubroutine test_inline(m, x, y)
implicit none
INTEGER*4, intent(in) :: m
REAL*8, intent(in), dimension(1:m) :: x
REAL*8, intent(out), dimension(1:m) :: y
INTEGER*4 :: i
do i = 1, m
   y(i) = %s*%s
end do
end subroutine
)zx(i)z
(x(i) + 1)r  )rH   r:   r;   r   r   rI   r   r   r   r   r   r)   r&  )r:   r;   r   r   r>   r<   r3   r8   rA   r   r^  ra   r   rb   argss                  r(   test_inline_functionra    s    -)5$'DAq+u%GAq!CA
Aq!QU)(<=D="QqT4!:*>?Gajj7),D		  "D8d?"4":%%& &% #r*   c                      t        d      } d}| D ]  }||z  }	 t        d|      }t               }t        |j                  |g      }d}||k(  sJ y )Nzx:20r   r.   a  REAL*8 function test(x0, x1, x10, x11, x12, x13, x14, x15, x16, x17, x18, &
      x19, x2, x3, x4, x5, x6, x7, x8, x9)
implicit none
REAL*8, intent(in) :: x0
REAL*8, intent(in) :: x1
REAL*8, intent(in) :: x10
REAL*8, intent(in) :: x11
REAL*8, intent(in) :: x12
REAL*8, intent(in) :: x13
REAL*8, intent(in) :: x14
REAL*8, intent(in) :: x15
REAL*8, intent(in) :: x16
REAL*8, intent(in) :: x17
REAL*8, intent(in) :: x18
REAL*8, intent(in) :: x19
REAL*8, intent(in) :: x2
REAL*8, intent(in) :: x3
REAL*8, intent(in) :: x4
REAL*8, intent(in) :: x5
REAL*8, intent(in) :: x6
REAL*8, intent(in) :: x7
REAL*8, intent(in) :: x8
REAL*8, intent(in) :: x9
test = x0 + x1 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + &
      x19 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9
end function
r.  )r3   r2   symra   rR   r'   rb   s          r(   test_f_code_call_signature_wraprd     sf    AD 64(GzH))G95FH8 Xr*   c                  L     t        d      \   t        t         fd       y )Nzx,Xc                  (    t        d z  fdd      S )Nr.   f95r#   )r   r  r3   s   r(   r5   z!test_check_case.<locals>.<lambda>J  s    &!A#x!H r*   )r   r   r   rh  s   @@r(   test_check_caseri  H  s    5>DAq
<HIr*   c                      t        d      } t        dd      }	 t        d| |z  fdd       y # t        $ r3}|j                  d   j	                  d      rt        d	      Y d }~y d }~ww xY w)
Nr3   T)my_assumptionr.   rg  r#   r   zFortran ignores case.z$This exception should not be raised!)r   r   r   r`  
startswithAssertionError)x1x2r  s      r(   test_check_case_false_positiverp  M  sm    
 
B	D	)BIB1 I66!9 78 !GHH 9Is   - 	A))A$$A)c                     t        d      \  } }dd| z  fg}t        |ddd      }t        |dddd      }|d   d   |d   d   k(  sJ d| |z  f}t        |ddd      }t        |dddd      }|d   d   |d   d   k(  sJ dt        | |g| |z   | |z
  gg      f}t        |d	dd      }t        |d	ddd      }|d   d   |d   d   k(  sJ y )
Nr   r   rC   r;  Fru   r   rB   r   )r   r   r   )r3   r8   r   rw   	expresults        r(    test_c_fortran_omit_routine_namers  [  s   5>DAq1IYe5AF	5%UKI!9Q<9Q<?***!IYe5AF	5%UKI!9Q<9Q<?***A1ac
345IYe5AF	5%UKI!9Q<9Q<?***r*   c                      t        d      \  } }}| |z   }t        | |g|dgg      }d||ff}t        |dddd      }|d   d   }d	}|j                         d
   }	|	j	                  d      }
|
d   }|d|iz  }||k(  sJ y )Nr]      r.   rg  Fru   r   rB   a2  REAL*8 function test(x, y, z, out_%(hash)s)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(in) :: y
REAL*8, intent(in) :: z
REAL*8, intent(out), dimension(1:2, 1:2) :: out_%(hash)s
out_%(hash)s(1, 1) = x
out_%(hash)s(2, 1) = z
out_%(hash)s(1, 2) = y
out_%(hash)s(2, 2) = 16
test = x + y
end function
r   _hash)r   r   r   
splitlinessplit)r3   r8   r4   e1e2r   rw   r'   rb   r7   r   r  s               r(   test_fcode_matrix_outputr|  m  s    gGAq!	
QB	!Q!R!	"B"b"IYve5IFAYq\F	  	AA	A
A$C63-'HXr*   c                  *   t        d      \  } }}t        d      \  }}t        ddd      }t        |t        dd| gg            }t        || |z   |z        }t        |d| z        }d|||gf}	t	        |	ddd	d	| |||||f
      }
|
d   d   }d}||k(  sJ y )Nr]   r  r<   rB   rD   rC   r.   rg  Fr  r   a!  subroutine test(x, z, y, C, A, B)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(in) :: z
REAL*8, intent(in) :: y
REAL*8, intent(out) :: C
REAL*8, intent(out) :: B
REAL*8, intent(out), dimension(1:1, 1:3) :: A
C = z*(x + y)
A(1, 1) = 1
A(1, 2) = 2
A(1, 3) = x
B = 2*x
end subroutine
r  )r3   r8   r4   r=   rs   r<   r   r   r  r   rw   r'   rb   s                r(    test_fcode_results_named_orderedr~    s    gGAq!5>DAqS!QAQAq	{+,EQQ	"EQ!E%./IYve5()1aAq'9;FAYq\F	   Xr*   c            	      "   t        ddd      } t        ddd      }t        ddd      }t        ddd      }dt        || d	d d f         t        || dd d f         t        || d d df         gf}t        |d
ddd      }|d	   d   }d}||k(  sJ y )Nr<   rC   rD   r=   rB   rs   r  r.   r   rg  Fru   a  subroutine test(A, B, C, D)
implicit none
REAL*8, intent(in), dimension(1:2, 1:3) :: A
REAL*8, intent(out), dimension(1:1, 1:3) :: B
REAL*8, intent(out), dimension(1:1, 1:3) :: C
REAL*8, intent(out), dimension(1:2, 1:1) :: D
B(1, 1) = A(1, 1)
B(1, 2) = A(1, 2)
B(1, 3) = A(1, 3)
C(1, 1) = A(2, 1)
C(1, 2) = A(2, 2)
C(1, 3) = A(2, 3)
D(1, 1) = A(1, 3)
D(2, 1) = A(2, 3)
end subroutine
r  r  s           r(   test_fcode_matrixsymbol_slicer    s    S!QAS!QAS!QAS!QA(1a1g."1a1g."1a1g.0 1I Yve5IFAYq\F	 " Xr*   c                      t        ddd      } d| d d df   f}t        |dddd      }|d	   d   }d
}|j                         d   }|j                  d      }|d   }|d|iz  }||k(  sJ y )Nr<   rC   rD   r.   rB   rg  Fru   r   zsubroutine test(A, out_%(hash)s)
implicit none
REAL*8, intent(in), dimension(1:2, 1:3) :: A
REAL*8, intent(out), dimension(1:2, 1:1) :: out_%(hash)s
out_%(hash)s(1, 1) = A(1, 2)
out_%(hash)s(2, 1) = A(2, 2)
end subroutine
rv  rw  )r   r   rx  ry  )r<   r   rw   r'   rb   r7   r   r  s           r(   &test_fcode_matrixsymbol_slice_autonamer    s    S!QA1a4!IYve5IFAYq\F	  	AA	A
A$C63-'HXr*   c                      t        d      \  } }}}t        d| |z  fddd|f      }|d   d   }d}||k(  sJ d	}t        d| |z  |z   fd
dd||f      }|d   d   }||k(  sJ y )Nzx y z tfr;  F)r$   r%   global_varsr   rB   zPREAL*8 function f(x)
implicit none
REAL*8, intent(in) :: x
f = x*y
end function
z#include "f.h"
#include <math.h>
double f(double x, double y) {
   double f_result;
   f_result = x*y + z;
   return f_result;
}
rs   rv   )r3   r8   r4   trw   r'   rb   s          r(   test_global_varsr    s    #JAq!Qc1Q3ZuE"#'FAYq\F	  X	  c1Q3q5\3uE"#Q)FAYq\FXr*   c                  Z   ddl m}  ddlm}  | dddii      }t	        d      \  }} |||z         }t        |d	g
      }d}t        d|fdd|      }|d   d   }	|	|k(  sJ t        |      }|j                  j                  d	       d}t        d|fdd|      }|d   d   }	|	|k(  sJ y )Nr   C99CodePrinter)expuser_functionsr  fastexp)settingszx yz#include "fastexp.h")printerpreprocessor_statementsz#include "expr.h"
#include "fastexp.h"
double expr(double x, double y) {
   double expr_result;
   expr_result = fastexp(x + y);
   return expr_result;
}
r2   F)r$   r%   rR   rB   )r  z#include "expr.h"
#include <math.h>
#include "fastexp.h"
double expr(double x, double y) {
   double expr_result;
   expr_result = fastexp(x + y);
   return expr_result;
}
)	sympy.printing.cr  r   r  r   r   r   r  append)
r  r  r  r3   r8   r2   genrb   rw   r'   s
             r(   test_custom_codegenr    s    /:'7%9K&LMG5>DAqq1u:D W.D-EGC	  fd^EMFAYq\FX W
%C&&'=>	  fd^EMFAYq\FXr*   c            	          ddl m}   G d d|       }t        d      }|dz  }ddg}t        d	|fd
ddd |             }||k(  sJ y )Nr   r  c                       e Zd Zd Zy)*test_c_with_printer.<locals>.CustomPrinterc                     dj                  | j                  |j                        | j                  |j                              S )Nzfastpow({}, {}))format_printbaser  )selfr2   s     r(   
_print_Powz5test_c_with_printer.<locals>.CustomPrinter._print_Pow+  s6    $++DKK		,B,0KK,AC Cr*   N)__name__
__module____qualname__r  r   r*   r(   CustomPrinterr  *  s    	Cr*   r  r3   rD   )rq   z#include "file.h"
#include <math.h>
double test(double x) {
   double test_result;
   test_result = fastpow(x, 3);
   return test_result;
}
)rr   zP#ifndef PROJECT__FILE__H
#define PROJECT__FILE__H
double test(double x);
#endif
r.   rs   rt   F)r$   r%   r  )r  r  r   r   )r  r  r3   r2   rb   rw   s         r(   test_c_with_printerr  '  sd    /C C
 	Aa4D		H fd^SUVcVefFXr*   c                  t   dd l } d| j                  j                  _        t	        dd      }t	        dd      }t        d||z   fdddd	      }|d   d
   }d}||k(  sJ t	        d      }t	        dd      }t        d||z   fdddd	      }|d   d
   }d}||k(  sJ d| j                  j                  _        y )Nr   Tr3   )realr8   r.   rg  Fru   rB   zsREAL*8 function test(x, y)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(in) :: y
test = x + y
end function
z{COMPLEX*16 function test(x, y)
implicit none
COMPLEX*16, intent(in) :: x
REAL*8, intent(in) :: y
test = x + y
end function
)sympy.utilities.codegen	utilitiesr   COMPLEX_ALLOWEDr   )sympyr3   r8   rw   r'   rb   s         r(   test_fcode_complexr  D  s    ".2EOO+sAsAfQqS\5&eLFQilF	  XsAsAfQqS\5&eLFQilF	  8.3EOO+r*   N)rt   FF)_ior   
sympy.corer   r   r   r   r   r	   r   r   r   r   'sympy.functions.special.error_functionsr   sympy.integrals.integralsr   sympy.matricesr   r   r  r   r   r   r   r   r   r   r   r   r   r   sympy.testing.pytestr   sympy.utilities.lambdifyr   r)   rM   rS   rX   r[   rc   re   rj   rl   ro   rx   r   r   r   r   r   r   r   r   r   r   r	  r  r  r  r  r!  r'  r)  r+  r/  r1  r4  r6  r9  r=  r@  rC  rF  rH  rJ  rO  rS  rU  rZ  r\  ra  rd  ri  rp  rs  r|  r~  r  r  r  r  r  r  r   r*   r(   <module>r     st    > > * $ 7 . /    ( 9?6@$T$$"$,	I99x0AH'T$.)X$*$*.4:(&& $&$&6	I9o$d+$\;$|0f0.b,3^&&6%PJ
I+$:<<.8,\:4r*   