
    gB                     "   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# dId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/ ZFd0 ZGd1 ZHd2 ZId3 ZJd4 ZKd5 ZLd6 ZMd7 ZNd8 ZOd9 ZPd: ZQd; ZRd< ZSd= ZTd> ZUd? ZVd@ ZWdA ZXdB ZYdC ZZdD Z[dE Z\dF Z]dG Z^dHS )J    )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_functionfileFc                     t                      } | |||||           |                                }|                                 |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          ^/var/www/html/ai-engine/env/lib/python3.11/site-packages/sympy/utilities/tests/test_codegen.py
get_stringr*      sF     ZZFGHfffe444__F
LLNNNM    c                    	
 t          d          \  	
	
z   z  t          t          	fd           t          t          	
fd           t          dt	                    	
g          } d | j        D             	
gk    sJ d | j        D             t          t          t          t          gk    sJ t          dt	                    	
g          } d | j        D             t          t          t          gk    sJ d	d
l	m
}m} t          |ddg          \  }}t          dd          } |d|          }t          dt	          ||         ||                   |||g          } d | j        D             |j        |j        |gk    sJ t          	
z  z  	ddf
ddf          t          dt	                    	
g          } d | j        D             	
gk    sJ d S )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                  J    t          dt                     g          S r.   )r   r   )ar3   r4   yr5   s   r)   r6   z-test_Routine_argument_order.<locals>.<lambda>(   s4    \&"QC C%&1I./ ./ ./ r+   r/   r0   c                     g | ]	}|j         
S  name.0args     r)   
<listcomp>z/test_Routine_argument_order.<locals>.<listcomp>+       ...#SX...r+   c                 ,    g | ]}t          |          S r;   typer>   s     r)   rA   z/test_Routine_argument_order.<locals>.<listcomp>,       ///3T#YY///r+   c                 ,    g | ]}t          |          S r;   rD   r>   s     r)   rA   z/test_Routine_argument_order.<locals>.<listcomp>/   rF   r+   r   IndexedBaseIdxABmTintegeric                     g | ]	}|j         
S r;   r<   r>   s     r)   rA   z/test_Routine_argument_order.<locals>.<listcomp>7   rB   r+            c                     g | ]	}|j         
S r;   r<   r>   s     r)   rA   z/test_Routine_argument_order.<locals>.<listcomp>;   rB   r+   )r   r   r   r   r   	argumentsr   r   r   sympy.tensorrI   rJ   maplabelr   )rrI   rJ   rK   rL   rM   rP   r8   r3   r4   r9   r5   s          @@@@@r)   test_Routine_argument_orderr[   #   s   ##JAq!QE19D
# &% &% &% &% &% &% & & &
# &/ &/ &/ &/ &/ &/ &/ &/ 0 0 0VR4[[Q1aLIIIA.....1aA,>>>>//!+///}nm4G G G G GVR4[[Q1IFFFA//!+///}m46 6 6 6 6 .-------{S#J''DAqT"""ACAVR!ad^^1ayIIIA.....17AGQ2GGGGGAaCEAq!9q!Qi00DVR4[[Q1aLIIIA.....1aA,>>>>>>r+   c                  \    t                      } t          | j        g           }|dk    sJ d S )Nz$#include "file.h"
#include <math.h>
r   r*   dump_ccode_genr(   s     r)   test_empty_c_codera   >   s4    ||H,,F???????r+   c                      t                      } t          | j        g d          }|d d         dk    sJ |dd          dk    sJ d S )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>
r]   r_   s     r)   test_empty_c_code_with_commentrf   D   st    ||HD999F#2#;]    #$$< ["      r+   c                  \    t                      } t          | j        g           }|dk    sJ d S )Nz9#ifndef PROJECT__FILE__H
#define PROJECT__FILE__H
#endif
)r   r*   dump_hr_   s     r)   test_empty_c_headerri   V   s4    ||H,,FSSSSSSSr+   c                      t          d          \  } }}| |z   |z  }t          d|          }t                      }t          |j        |g          }d}||k    sJ d S )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*   r^   r4   r9   r5   r3   routiner`   r(   expecteds           r)   test_simple_c_coderq   \   sp    gGAq!E19D64((G||H'33F	  Xr+   c                      t          d          \  } }}| |z   |z  }t          d|          }t                      }t          |j        |g          }d}||k    sJ d S )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*   r^   rn   s           r)   test_c_code_reserved_wordsrs   n   sq    *++GAq!EQ;D64((G||H'33F	  Xr+   c                      t          dt          t          z            } t                      }t	          |j        | g          }dt          j        d          z  }||k    sJ d S )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*   r^   evalfro   r`   r(   rp   s       r)   test_numbersymbol_c_coderx      se    62w;//G||H'33F	 	b	H Xr+   c                      t          d          \  } }}| |z   }t          d||| |g          }t                      }t          |j        |g          }d}||k    sJ d S )Nrk   r/   r0   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;
}
rm   rn   s           r)   test_c_code_argument_orderrz      sw    gGAq!q5D64Aq!9EEEG||H'33F	  Xr+   c                      t          d          \  } }}| |z   |z  }t          d|          }t                      }t          |j        |g          }d}||k    sJ d S )Nrk   r/   d#ifndef PROJECT__FILE__H
#define PROJECT__FILE__H
double test(double x, double y, double z);
#endif
)r   r   r   r*   rh   rn   s           r)   test_simple_c_headerr}      sp    gGAq!E19D64((G||H'33F	  Xr+   c                      t          d          \  } }}| |z   |z  }ddg}t          d|fdddd          }||k    sJ d S )	Nrk   )file.crl   )file.hr|   r/   Cr   Fr%   r&   r   r   )r4   r9   r5   r3   rp   results         r)   test_simple_c_codegenr      sh    gGAq!E19D		H fd^S&eLLLFXr+   c                      t          d          \  } }}| |z   |z  }| |z
  |z  }t          d||g          t                      t          t          fd           d S )Nrk   r/   c                  0    t           j        g          S Nr*   rh   r`   ro   s   r)   r6   z)test_multiple_results_c.<locals>.<lambda>       HOgY!G!G r+   )r   r   r   r   r   r4   r9   r5   expr1expr2r`   ro   s        @@r)   test_multiple_results_cr      sx    gGAq!UAIEUAIE	 G ||H
<GGGGGHHHHHr+   c                  2    t          t          d            d S )Nc                  "    t          dg           S Nr/   r2   r;   r+   r)   r6   z#test_no_results_c.<locals>.<lambda>       |FB77 r+   r   
ValueErrorr;   r+   r)   test_no_results_cr          
:778888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 d S )!Nr   Abslogcoshsinhtanh)ceilingfloorsqrtacosasinatancossintanr4   	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C89r   Fr   r   rR   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;
}
r   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   r4   	name_exprr   s                    r)   test_ansi_math1_codegenr      sA   888888::::::HHHHHHHHHHDDDDDDDD======ZZZZZZZZZZZZZZZZA	cc!ff	dd1gg	dd1gg	dd1gg	ggajj!	SSVV	dd1gg	uuQxx 	SSVV	CCFF	SSVV	dd1gg	dd1gg	SSVV	dd1ggI" Yve5II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 d S )Nr   atan2x,y
test_atan2test_powr   r   Fr   r   rR   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;
}
r   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   r4   r9   r   r   s        r)   test_ansi_math2_codegenr     s    >>>>>>5>>DAq	uuQ{{#	QTI Yve5IIIF!9Q<8####!9Q<	N   
 !9Q<8####!9Q<	     r+   c                      ddl m} m}m} t	          d          \  }}}d ||           | |          z    ||          z   dz                                  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 d S )Nr   r   r   r   rk   test1   test2r   r   Fr   r   rR   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;
}
r   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   r4   r9   r5   r   r   s           r)   test_complicated_codegenr   ,  ss   HHHHHHHHHHgGAq!	CCFFSSVVOcc!ff,q088::;	##cc##cc##cc##cc!a%!)nn*=*=&>&>"?"?@@AABBCCDI Yve5IIIF!9Q<8####!9Q<.	0 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 d S )Nr   rH   r   n mTrN   rK   r4   r9   rP   jmatrix_vectorC99r   Fr   r   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]r   z|#ifndef PROJECT__FILE__H
#define PROJECT__FILE__H
void matrix_vector(double *A, int m, int n, double *x, double *y);
#endif
rW   rI   rJ   sympy.core.symbolr   r   r   rI   rJ   r   nrM   rK   r4   r9   rP   r   f1codef2	interfacerp   s                  r)   test_loops_cr   p  s   --------))))))75$'''DAqCACACACACA")	"QqT1QT71Q4<0015&V[#] #] #]JRY >>>>	  H|qsQw'?@@@@H|q1Q3w'?@@@@H|qsQw'?@@@@H|q1Q3w'?@@@@@@>>>>	     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            d S # 1 swxY w Y   d S )Nr   rH   i mTrO   clsr4   r9   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)rW   rI   rJ   r   r	   rY   dummy_indexr   r   r   r   r*   r^   r   NotImplementedError)rI   rJ   rP   rM   r4   r9   rp   rZ   c89c99r   s              r)   test_dummy_loops_cr     s]   --------5$E222DAqCACAAq		A	 #AM::;H 	^R!ad^^44A
,,C
,,Ccj1#&&D8	#	$	$ $ $3:s###$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $s   C88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 d S )Nr   rH   r   n m o pTrN   rK   shaper4   r9   rP      r   r   r   r   Fr   r   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   r   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   rI   rJ   r   r   rM   oprK   r4   r9   rP   r   r   r   r   r   rp   s                    r)   test_partial_loops_cr     s    .-------))))))D111JAq!QC1v&&&ACACAC!QUACA")	"QqT1QT71Q4<0015&V[#] #] #]JRY >>>>	 q5++,H H|qsQw'?@@@@H|q1Q3w'?@@@@H|qsQw'?@@@@H|q1Q3w'?@@@@@@>>>>	     r+   c            	      H   ddl m}  ddlm}m} t          d          \  }}}t          d | | ||                     ||          g          }t                      }|                    |gddd          }|d         d         d	k    sJ d
}	|d         d         |	k    sJ d S )Nr   r
   r   r   rk   foor/   Fr   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;
}
rR   	sympy.core.relationalr   r   r   r   r   r   r   write
r   r   r   r4   r9   r5   rZ   cr   rp   s
             r)   test_output_arg_cr    s    ......CCCCCCCCgGAq!UXXaQ00##a&&9::AAWWaS&eW<<F!9Q<8####	  !9Q<8######r+   c            	      H   ddl m}  ddlm}m} t          d          \  }}}t          d | | ||                     ||          g          }t                      }|                    |gddd          }|d         d         d	k    sJ d
}	|d         d         |	k    sJ d S )Nr   r
   r   zif, while, zr   r/   Fr   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;
}
rR   r  r  s
             r)    test_output_arg_c_reserved_wordsr	    s    ......CCCCCCCCn%%GAq!UXXaQ00##a&&9::AAWWaS&eW<<F!9Q<8####	  !9Q<8######r+   c                  j   t          ddd          } t          ddd          }t          |           }t          |          }||z  }t          dd          }|                    d|          }d	|j        d
         _        d	|j        d
         _        t          |j        |gd          }d}||k    sJ d S )NrK   rT   brR   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   ro   rV   
result_var_namer*   r^   )	A_symb_symrK   r  r  cgenrZ   r   rp   s	            r)   test_multidim_c_argument_cser    s    a##Ea##EuAuA	!AF---DS!A!&AKO!AKOdkA3v666D	  8r+   c                  z   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 d S )Nrk   B,CrK   rR   rT   rS   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&   r1   r   r   r   r   r   r   )r4   r9   r5   rL   r   rK   r   r   expr3r   rp   r   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 d S )NrK   r   rT   rL   rR   r   Dr/   r   rS   r   Fr   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   rK   rL   r   r  r   r   r(   rp   s           r)   test_ccode_matrixsymbol_slicer   8  s    S!QAS!QAS!QAS!QA(1a111g.."1a111g.."1a1g..0 1I Yve5II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 d S )Nza b c derT   rR   r/   T)r  F)r`   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   )
r8   r  r  dr"  r   	generatorr   r(   rp   s
             r)   test_ccode_cser%  U  s    ##JAq!QS!QA(1fqseacAaCi[1Q3q57)-L&M&MNNOPIT"""IY5NNNFAYq\F	  Xr+   c                      t          ddd          } d}t                      }t          ||dd| f          }|d         d         }d}||k    sJ d S )	Nr4   rS   rR   )r/   g      ?F)r`   r%   r&   r1   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   )r4   r   r$  r   r(   rp   s         r)   test_ccode_unused_array_argr'  i  sm    S!QAI

IY5bcaeff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 d S )NXrT   rR   Yr5   TrN   testBugr   r   F)languager%   r&   r1   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*  r5   r   r   r(   rp   s          r)    test_ccode_unused_array_arg_funcr-  |  s    S1AS1Ad###AAaD1Q4K(IYU%\]_`bc[deeeFAYq\F	  Xr+   c                  \    t                      } t          | j        g           }|dk    sJ d S N r   r*   dump_f95r_   s     r)   test_empty_f_coder3    s.    zzH)2..FR<<<<<<r+   c                      t                      } t          | j        g d          }|d d         dk    sJ |dd          dk    sJ d S )NTrc   rd   zR!******************************************************************************
!*re   a  *
!*                                                                            *
!*              See http://www.sympy.org/ for more information.               *
!*                                                                            *
!*                       This file is part of 'project'                       *
!******************************************************************************
r1  r_   s     r)   test_empty_f_code_with_headerr5    sv    zzH)2d;;;F#2#;]    #$$< [`      r+   c                  \    t                      } t          | j        g           }|dk    sJ d S r/  )r   r*   rh   r_   s     r)   test_empty_f_headerr7    s-    zzH,,FR<<<<<<r+   c                      t          d          \  } }}| |z   |z  }t          d|          }t                      }t          |j        |g          }d}||k    sJ d S )Nrk   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*   r2  rn   s           r)   test_simple_f_coder;    sq    gGAq!E19D64((GzzH)G95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 d S )Nr/   zDREAL*8 function test()
implicit none
REAL*8, parameter :: Catalan = ru   zd0
REAL*8, parameter :: pi = z#d0
test = pi**Catalan
end function
)r   r   r   r   r*   r2  rv   rw   s       r)   test_numbersymbol_f_coder=    sw    62w;//GzzH)G955FF 
r				BHRLLLL*H Xr+   c                      t          d          } t          dt          |           t          d| z            z
            }t                      }t	          |j        |g          }d}||k    s
J |            d S )Nr4   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*   r2  )r4   ro   r`   r(   rp   s        r)   test_erf_f_coder@    sy    A63q66CQKK#788GzzH)G955F	  Xvr+   c                      t          d          \  } }}| |z   }t          d||| |g          }t                      }t          |j        |g          }d}||k    sJ d S )Nrk   r/   r0   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:  rn   s           r)   test_f_code_argument_orderrB    sx    gGAq!q5D64Aq!9EEEGzzH)G955F	  Xr+   c                      t          d          \  } }}| |z   |z  }t          d|          }t                      }t          |j        |g          }d}||k    sJ d S )Nrk   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*   rh   rn   s           r)   test_simple_f_headerrE    sp    gGAq!E19D64((GzzH'33F	  Xr+   c                      t          d          \  } }}| |z   |z  }t          d|fdddd          }ddg}||k    sJ d S )	Nrk   r/   F95r   Fr   )file.f90r9  )r   rD  r   )r4   r9   r5   r3   r   rp   s         r)   test_simple_f_codegenrI    sr    gGAq!E19D	ve5B B BF		H& Xr+   c                      t          d          \  } }}| |z   |z  }| |z
  |z  }t          d||g          t                      t          t          fd           d S )Nrk   r/   c                  0    t           j        g          S r   r   r   s   r)   r6   z)test_multiple_results_f.<locals>.<lambda>"  r   r+   )r   r   r   r   r   r   s        @@r)   test_multiple_results_frL    sx    gGAq!UAIEUAIE	 G zzH
<GGGGGHHHHHr+   c                  2    t          t          d            d S )Nc                  "    t          dg           S r   r2   r;   r+   r)   r6   z#test_no_results_f.<locals>.<lambda>&  r   r+   r   r;   r+   r)   test_no_results_frO  %  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 d S )Nr   r   r   r   r   r   r4   test_absr   r   r   r   r   r   r   r   r   r   r   r   rG  r   Fr   rH  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
rR   r   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   r4   r   r   rp   s                   r)   test_intrinsic_math_codegenrR  )  s   888888::::::HHHHHHHHHH======ZZZZZZZZZZZZZZZZA	SSVV	dd1gg	dd1gg	dd1gg	SSVV	dd1gg	SSVV	CCFF	SSVV	dd1gg	dd1gg	SSVV	dd1ggI Yve5IIIF!9Q<:%%%%@	 F !9Q<8####!9Q<8####M	 ` !9Q<8######r+   c                  0   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 d S )Nr   r   r   r   r   rG  r   Fr   rH  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
rR   r   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   r4   r9   r   r   rp   s         r)   test_intrinsic_math2_codegenrT    s    >>>>>>5>>DAq	uuQ{{#	QTI Yve5IIIF!9Q<:%%%%	  !9Q<8####!9Q<8####	   !9Q<8######r+   c                  (   ddl m} m}m} t	          d          \  }}}d ||           | |          z    ||          z   dz                                  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 d S )Nr   r   rk   r   r   r   rG  r   Fr   rH  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
rR   r   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   r4   r9   r5   r   r   rp   s	            r)   test_complicated_codegen_f95rV  	  sn   HHHHHHHHHHgGAq!	CCFFSSVVOcc!ff,q088::;	##cc##cc##cc##cc!a%!)nn*=*=&>&>"?"?@@AABBCCDI Yve5II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 d S )Nr   rH   r   zn,mTrN   AxyrP   r   r   rG  r   Fr   rH  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)r   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
)rW   rI   rJ   r   r   rX   r   r   r   s                  r)   
test_loopsr[  G  sL   --------))))))75$'''DAq+u%%GAq!CACA")	"QqT1QT71Q4<0015&V[#] #] #]JRY 	 * 8un5555E>222222>>>>		     r+   c                  h   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 d S )Nr   rH   r   Tr   r4   r9   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   )rW   rI   rJ   r   r	   rY   r   r   r   r   r*   r2  )
rI   rJ   rP   rM   r4   r9   rp   rZ   r  r   s
             r)   test_dummy_loops_f95r_  z  s    --------5$E222DAqCACAAq		A		 7&!-@@AH 	^R!ad^^44A

Aaj1#&&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 d S )Nr   rH   r   zi,j,n,mTrN   zA,x,yr   rG  r   Fr   rH  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   rY  rZ  r   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   )rI   rJ   r   rP   r   r   rM   rK   r4   r9   r   r   r   r   rp   s                  r)   test_loops_InOutra    s   --------))))))D111JAq!QggGAq!Ass1ayy##a))+,AAss1ayy!AAss1ayy!A")	"QAaC..)5&e#U #U #UJRY 	 $ H~6666H~666666>>>>		     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 d S d S )Nr   rH   r   r   TrN   rK   r   r4   r9   rP   r   r   r   rG  r   Fr   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   rR   )r   iupilowziup-ilowr   rY  rZ  )rW   rI   rJ   r   r   r   r   strr   s                    r)   test_partial_loops_frf    s    .-------))))))D111JAq!QC1v&&&ACACAC!QUACA")	"QqT1QT71Q4<0015&V[#] #] #]JRY	* 1q5zzAE

A	NN		 	+H8 8un5555E>222222 6522r+   c            	      D   ddl m}  ddlm}m} t          d          \  }}}t          d | | ||                     ||          g          }t                      }|                    |gddd          }|d         d         d	k    sJ |d         d
         dk    sJ d S )Nr   r
   r   rk   r   r/   Fr   ztest.f90rR   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   r4   r9   r5   rZ   r  r   s	            r)   test_output_arg_frh    s    ......CCCCCCCCgGAq!UXXaQ00##a&&9::A

AWWaS&eW<<F!9Q<:%%%%!9Q<	     r+   c            
         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 d S d S )Nr   rH   r   r   TrN   rX  rP   funcrR   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  )rW   rI   rJ   r   r   rX   r   r   r   r   r   r*   r2  )rI   rJ   r   r   rM   rK   r4   r9   rP   r   rj  ro   r   rp   argss                  r)   test_inline_functionrm    s   --------))))))75$'''DAq+u%%GAq!CA

Aq!QU)(<(<==D="QqT44!::*>*>??Gaj7),,D		  "D8d?""4":%%%%% #"%%r+   c                      t          d          } d}| D ]}||z  }t          d|          }t                      }t          |j        |g          }d}||k    sJ d S )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:  )r4   r3   symro   r`   r(   rp   s          r)   test_f_code_call_signature_wraprp     sx    AD  64((GzzH)G955FH8 Xr+   c                  `     t          d          \   t          t           fd           d S )Nzx,Xc                  0    t          d z  fdd          S )Nr/   f95r$   )r   r)  r4   s   r)   r6   z!test_check_case.<locals>.<lambda>J  s    &!A#x!H!H r+   )r   r   r   rt  s   @@r)   test_check_caseru  H  s6    5>>DAq
<HHHHHIIIIIr+   c                     t          d          } t          dd          }	 t          d| |z  fdd           d S # t          $ r:}|j        d                             d          rt          d	          Y d }~d S d }~ww xY w)
Nr4   T)my_assumptionr/   rs  r$   r   zFortran ignores case.z$This exception should not be raised!)r   r   r   rl  
startswithAssertionError)x1x2r"  s      r)   test_check_case_false_positiver|  M  s    
 
B	D	)	)	)BIB11111 I I I6!9 788 	I !GHHH	I 	I 	I 	I 	I 	IIs   : 
A>/A99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 d S )
Nr   r   rS   rG  Fr   r   rR   r   )r   r   r   )r4   r9   r   r   	expresults        r)    test_c_fortran_omit_routine_namer  [  sG   5>>DAq1IYe5AAAF	5%UKKKI!9Q<9Q<?****!IYe5AAAF	5%UKKKI!9Q<9Q<?****A1ac
3445IYe5AAAF	5%UKKKI!9Q<9Q<?******r+   c                  @   t          d          \  } }}| |z   }t          | |g|dgg          }d||ff}t          |dddd          }|d         d         }d	}|                                d
         }	|	                    d          }
|
d         }|d|iz  }||k    sJ d S )Nrk      r/   rs  Fr   r   rR   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)r4   r9   r5   e1e2r   r   r(   rp   r8   r  r  s               r)   test_fcode_matrix_outputr  m  s    gGAq!	
QB	!Q!R!	"	"B"b"IYve5IIIFAYq\F	  	AA	A
A$C63-'HXr+   c                  z   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 d S )Nrk   r  rK   rR   rT   rS   r/   rs  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  )r4   r9   r5   rL   r   rK   r   r   r  r   r   r(   rp   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 d S )NrK   rS   rT   rL   rR   r   r  r/   r   rs  Fr   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111g.."1a111g.."1a1g..0 1I Yve5IIIFAYq\F	 " Xr+   c                     t          ddd          } d| d d df         f}t          |dddd          }|d	         d         }d
}|                                d         }|                    d          }|d         }|d|iz  }||k    sJ d S )NrK   rS   rT   r/   rR   rs  Fr   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
r  r  )r   r   r  r  )rK   r   r   r(   rp   r8   r  r  s           r)   &test_fcode_matrixsymbol_slice_autonamer    s    S!QA111a4!IYve5II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 d S )Nzx y z tfrG  F)r%   r&   global_varsr   rR   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;
}
r   r   )r4   r9   r5   tr   r(   rp   s          r)   test_global_varsr    s    ##JAq!Qc1Q3ZuE"#' ' 'FAYq\F	  X	  c1Q3q5\3uE"#Q) ) )FAYq\FXr+   c                     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                            d	           d}t          d|fdd|          }|d         d         }	|	|k    sJ d S )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;
}
r3   F)r%   r&   r`   rR   )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  r4   r9   r3   genrp   r   r(   s
             r)   test_custom_codegenr    s<   //////::::::n'7%9K&LMMMG5>>DAq3q1u::D W.D-EG G GC	  fd^EMMMFAYq\FX W
%
%
%C&&'=>>>	  fd^EMM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 d S )Nr   r  c                       e Zd Zd ZdS )*test_c_with_printer.<locals>.CustomPrinterc                     d                     |                     |j                  |                     |j                            S )Nzfastpow({}, {}))format_printbaser  )selfr3   s     r)   
_print_Powz5test_c_with_printer.<locals>.CustomPrinter._print_Pow+  s>    $++DKK	,B,B,0KK,A,AC C Cr+   N)__name__
__module____qualname__r  r;   r+   r)   CustomPrinterr  *  s(        	C 	C 	C 	C 	Cr+   r  r4   rT   )r   z#include "file.h"
#include <math.h>
double test(double x) {
   double test_result;
   test_result = fastpow(x, 3);
   return test_result;
}
)r   zP#ifndef PROJECT__FILE__H
#define PROJECT__FILE__H
double test(double x);
#endif
r/   r   r   F)r%   r&   r  )r  r  r   r   )r  r  r4   r3   rp   r   s         r)   test_c_with_printerr  '  s    //////C C C C C C C C
 	Aa4D		H fd^SUVcVcVeVefffFXr+   c                     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        _        d S )Nr   Tr4   )realr9   r/   rs  Fr   rR   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   )sympyr4   r9   r   r(   rp   s         r)   test_fcode_complexr  D  s   """".2EO+sAsAfQqS\5&eLLLFQilF	  XsAsAfQqS\5&eLLLFQilF	  8.3EO+++r+   N)r   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*   r[   ra   rf   ri   rq   rs   rx   rz   r}   r   r   r   r   r   r   r   r   r   r  r	  r  r  r   r%  r'  r-  r3  r5  r7  r;  r=  r@  rB  rE  rI  rL  rO  rR  rT  rV  r[  r_  ra  rf  rh  rm  rp  ru  r|  r  r  r  r  r  r  r  r  r  r;   r+   r)   <module>r     s         > > > > > > > > > > > > > > > > * * * * * * $ $ $ $ $ $ 7 7 7 7 7 7 . . . . . . / / / / / / / /                          ( ' ' ' ' ' 9 9 9 9 9 9   ? ? ?6@ @ @  $T T T  $  $  "  $    ,	I 	I 	I9 9 99 9 9x  0A A AH' ' 'T$ $ $.) ) )X$ $ $*$ $ $*  .  4  :  (  &  &         $  & & &  $  &  6	I 	I 	I9 9 9o$ o$ o$d+$ +$ +$\;$ ;$ ;$|0 0 0f  0. . .b,3 ,3 ,3^  && & &6% % %PJ J J
I I I+ + +$  :  <  <  .  8, , ,\  :4 4 4 4 4r+   