U
    ZÊ¹jBÛ  ã                   @   s–  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# d„dd„Z$dd„ Z%dd„ Z&dd„ Z'dd„ Z(dd„ Z)dd„ Z*dd„ Z+dd„ Z,dd „ Z-d!d"„ Z.d#d$„ Z/d%d&„ Z0d'd(„ Z1d)d*„ Z2d+d,„ Z3d-d.„ Z4d/d0„ Z5d1d2„ Z6d3d4„ Z7d5d6„ Z8d7d8„ Z9d9d:„ Z:d;d<„ Z;d=d>„ Z<d?d@„ Z=dAdB„ Z>dCdD„ Z?dEdF„ Z@dGdH„ ZAdIdJ„ ZBdKdL„ ZCdMdN„ ZDdOdP„ ZEdQdR„ ZFdSdT„ ZGdUdV„ ZHdWdX„ ZIdYdZ„ ZJd[d\„ ZKd]d^„ ZLd_d`„ ZMdadb„ ZNdcdd„ ZOdedf„ ZPdgdh„ ZQdidj„ ZRdkdl„ ZSdmdn„ ZTdodp„ ZUdqdr„ ZVdsdt„ ZWdudv„ ZXdwdx„ ZYdydz„ ZZd{d|„ Z[d}d~„ Z\dd€„ Z]d�d‚„ Z^dƒS )…é    )Ú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                 C   s*   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)Zdump_fnZroutinesÚprefixÚheaderÚemptyÚoutputÚsource© r%   úa/var/www/html/bwave/python/venv/lib/python3.8/site-packages/sympy/utilities/tests/test_codegen.pyÚ
get_string   s
    r'   c                     sÀ  t dƒ\‰ ‰‰‰ˆˆ ˆ ‰tt‡‡‡fdd„ƒ tt‡ ‡‡‡‡fdd„ƒ tdtˆ ˆƒˆˆˆ ˆgd�} dd„ | jD ƒˆˆˆ ˆgksˆt‚d	d„ | jD ƒttttgks¨t‚tdtˆˆƒˆˆˆgd�} d
d„ | jD ƒt	ttgksàt‚ddl
m}m} t|ddgƒ\}}t ddd�}|d|ƒ}tdt|| || ƒ|||gd�} dd„ | jD ƒ|j|j|gk�s^t‚tˆˆ ˆ ˆddfˆddfƒ‰tdtˆ ˆƒˆˆˆ ˆgd�} dd„ | jD ƒˆˆˆ ˆgk�s¼t‚d S )Nza x y zc                      s   t dˆ ˆˆgd�S ©NÚtest©Úargument_sequence©r   r%   )ÚexprÚxÚzr%   r&   Ú<lambda>&   s   ÿz-test_Routine_argument_order.<locals>.<lambda>c                      s   t dtˆ ˆƒˆˆˆgd�S r(   )r   r   r%   ©Úar-   r.   Úyr/   r%   r&   r0   (   s   ÿÿr)   r*   c                 S   s   g | ]
}|j ‘qS r%   ©Úname©Ú.0Úargr%   r%   r&   Ú
<listcomp>+   s     z/test_Routine_argument_order.<locals>.<listcomp>c                 S   s   g | ]}t |ƒ‘qS r%   ©Útyper6   r%   r%   r&   r9   ,   s     c                 S   s   g | ]}t |ƒ‘qS r%   r:   r6   r%   r%   r&   r9   /   s     r   ©ÚIndexedBaseÚIdxÚAÚBÚmT©ÚintegerÚic                 S   s   g | ]
}|j ‘qS r%   r4   r6   r%   r%   r&   r9   7   s     é   é   é   c                 S   s   g | ]
}|j ‘qS r%   r4   r6   r%   r%   r&   r9   ;   s     )r   r   r   r   r   Ú	argumentsÚAssertionErrorr   r   r   Úsympy.tensorr=   r>   ÚmapÚlabelr   )Úrr=   r>   r?   r@   rA   rD   r%   r1   r&   Útest_Routine_argument_order#   s6        ÿ
  ÿ

"$ rN   c                  C   s"   t ƒ } t| jg ƒ}|dkst‚d S )Nz$#include "file.h"
#include <math.h>
©r   r'   Údump_crI   ©Úcode_genr$   r%   r%   r&   Útest_empty_c_code>   s    rS   c                  C   sB   t ƒ } t| jg dd�}|d d… dks*t‚|dd … dks>t‚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>
rO   rQ   r%   r%   r&   Útest_empty_c_code_with_commentD   s    
ÿrW   c                  C   s"   t ƒ } t| jg ƒ}|dkst‚d S )Nz9#ifndef PROJECT__FILE__H
#define PROJECT__FILE__H
#endif
)r   r'   Údump_hrI   rQ   r%   r%   r&   Útest_empty_c_headerV   s    rY   c                  C   sL   t dƒ\} }}| | | }td|ƒ}tƒ }t|j|gƒ}d}||ksHt‚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'   rP   rI   ©r.   r3   r/   r-   ÚroutinerR   r$   Úexpectedr%   r%   r&   Útest_simple_c_code\   s    
ÿ	r`   c                  C   sL   t dƒ\} }}| | | }td|ƒ}tƒ }t|j|gƒ}d}||ksHt‚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'   rP   rI   r]   r%   r%   r&   Útest_c_code_reserved_wordsn   s    
ÿ	ra   c                  C   s@   t dtt ƒ} tƒ }t|j| gƒ}dt d¡ }||ks<t‚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'   rP   ÚevalfrI   ©r^   rR   r$   r_   r%   r%   r&   Útest_numbersymbol_c_code€   s    ÷
re   c                  C   sR   t dƒ\} }}| | }td||| |gd�}tƒ }t|j|gƒ}d}||ksNt‚d S )NrZ   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]   r%   r%   r&   Útest_c_code_argument_order‘   s    ÿ	rf   c                  C   sL   t dƒ\} }}| | | }td|ƒ}tƒ }t|j|gƒ}d}||ksHt‚d S )NrZ   r)   úd#ifndef PROJECT__FILE__H
#define PROJECT__FILE__H
double test(double x, double y, double z);
#endif
)r   r   r   r'   rX   rI   r]   r%   r%   r&   Útest_simple_c_header£   s    
ÿrh   c                  C   sH   t dƒ\} }}| | | }ddg}td|fddddd�}||ksDt‚d S )	NrZ   )úfile.cr[   )úfile.hrg   r)   ÚCr   F©r!   r"   ©r   r   rI   )r.   r3   r/   r-   r_   Úresultr%   r%   r&   Útest_simple_c_codegen²   s    ÷ro   c                     sR   t dƒ\} }}| | | }| | | }td||gƒ‰tƒ ‰ tt‡ ‡fdd„ƒ d S )NrZ   r)   c                      s   t ˆ jˆgƒS ©N©r'   rX   r%   ©rR   r^   r%   r&   r0   Ñ   ó    z)test_multiple_results_c.<locals>.<lambda>)r   r   r   r   r   ©r.   r3   r/   Úexpr1Úexpr2r%   rr   r&   Útest_multiple_results_cÈ   s    þrw   c                   C   s   t tdd„ ƒ d S )Nc                   S   s
   t dg ƒS ©Nr)   r,   r%   r%   r%   r&   r0   Õ   rs   z#test_no_results_c.<locals>.<lambda>©r   Ú
ValueErrorr%   r%   r%   r&   Útest_no_results_cÔ   s    r{   c                  C   sx  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 dk�s2t‚|d d dk�sHt‚|d d dk�s^t‚|d d d k�stt‚d S )!Nr   ©ÚAbs©Úlog©ÚcoshÚsinhÚtanh)ÚceilingÚfloor©Úsqrt©ÚacosÚasinÚatanÚcosÚsinÚtanr.   Z	test_fabsÚ	test_acosÚ	test_asinÚ	test_atanZ	test_ceilÚtest_cosÚ	test_coshZ
test_floorÚtest_logÚtest_lnÚtest_sinÚ	test_sinhÚ	test_sqrtÚtest_tanÚ	test_tanhÚC89r   Frl   ri   rE   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;
}
rj   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ƒ   Z#sympy.functions.elementary.integersr„   r…   Ú(sympy.functions.elementary.miscellaneousr‡   Ú(sympy.functions.elementary.trigonometricr‰   rŠ   r‹   rŒ   r�   rŽ   r   r   rI   )r}   r   r�   r‚   rƒ   r„   r…   r‡   r‰   rŠ   r‹   rŒ   r�   rŽ   r.   Ú	name_exprrn   r%   r%   r&   Útest_ansi_math1_codegenØ   s@     














ñ
ÿ

ÿr¢   c                  C   s˜   ddl m}  tdƒ\}}d| ||ƒfd|| fg}t|ddddd	�}|d d d
ksXt‚|d d dkslt‚|d d dks€t‚|d d dks”t‚d S )Nr   ©Úatan2úx,yÚ
test_atan2Útest_powr›   r   Frl   ri   rE   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;
}
rj   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   rI   )r¤   r.   r3   r¡   rn   r%   r%   r&   Útest_ansi_math2_codegen  s    
þ
ÿ
ÿr©   c                  C   sÜ   ddl m} m}m} tdƒ\}}}d||ƒ| |ƒ ||ƒ d  ¡ fd| | | | | | | | || | ƒƒƒƒƒƒƒƒfg}t|ddd	d	d
�}|d d dksœt‚|d d dks°t‚|d d dksÄt‚|d d dksØt‚d S )Nr   ©rŒ   r�   rŽ   rZ   Útest1é   Útest2r›   r   Frl   ri   rE   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;
}
rj   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   rI   )rŒ   r�   rŽ   r.   r3   r/   r¡   rn   r%   r%   r&   Útest_complicated_codegen,  s    ".þ
ÿ1
ÿr°   c                  C   s@  ddl m} m} ddlm} |ddd�\}}| dƒ}| dƒ}| d	ƒ}|d
|ƒ}|d|ƒ}	tdt|| |||	f ||	  ƒfddddd�\\}
}\}}|
dks t‚d}||dd|| |	  i k�s ||dd|	||   i k�s ||dd|| |	  i k�s ||dd|	||   i k�s t‚|dk�s.t‚|dk�s<t‚d S )Nr   r<   ©r   ún mTrB   r?   r.   r3   rD   ÚjÚmatrix_vectorÚC99r   Frl   ri   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]rj   z|#ifndef PROJECT__FILE__H
#define PROJECT__FILE__H
void matrix_vector(double *A, int m, int n, double *x, double *y);
#endif
©rJ   r=   r>   Úsympy.core.symbolr   r   r   rI   ©r=   r>   r   ÚnrA   r?   r.   r3   rD   r³   Úf1ÚcodeÚf2Ú	interfacer_   r%   r%   r&   Útest_loops_cp  s:    

     ÿÿÿþýÿrÁ   c               	   C   s´   ddl m} m} tddtd�\}}| dƒ}| dƒ}|||ƒ}d|jj|jd	œ }td
t|| || ƒƒ}t	ƒ }t
ƒ }	t|	j|gƒ}
|
|ksŽt‚ttƒ� t|j|gƒ W 5 Q R X d S )Nr   r<   úi mT©rC   Úclsr.   r3   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];
   }
}
)ÚinoZmnoÚtest_dummies)rJ   r=   r>   r   r   rL   Údummy_indexr   r   r   r   r'   rP   rI   r   ÚNotImplementedError)r=   r>   rD   rA   r.   r3   r_   rM   Zc89Úc99r¾   r%   r%   r&   Útest_dummy_loops_cš  s    
ø	
rÊ   c                  C   sb  ddl m} m} ddlm} |ddd�\}}}}| d||fd�}| d	ƒ}| d
ƒ}	|d||d fƒ}
|d|ƒ}tdt|	|
 ||
|f ||  ƒfddddd�\\}}\}}|dks´t‚d|d ddœ }||dd|
| |  i k�sB||dd||
|   i k�sB||dd|
| |  i k�sB||dd||
|   i k�sBt‚|dk�sPt‚|dk�s^t‚d S )Nr   r<   r±   ún m o pTrB   r?   ©Úshaper.   r3   rD   é   r³   r´   rµ   r   Frl   ri   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)Zupperir¶   r¶   r·   r¸   rj   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¼   rA   ÚoÚpr?   r.   r3   rD   r³   r½   r¾   r¿   rÀ   r_   r%   r%   r&   Útest_partial_loops_c±  s<    
     ÿóÿþýÿrÔ   c            
      C   s�   ddl m}  ddlm}m} tdƒ\}}}td| |||ƒƒ||ƒgƒ}tƒ }|j|gdddd�}|d d d	kstt	‚d
}	|d d |	ksŒt	‚d S )Nr   r	   ©rŒ   r�   rZ   Úfoor)   Frl   ú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;
}
rE   ©
Úsympy.core.relationalr
   r    rŒ   r�   r   r   r   ÚwriterI   ©
r
   rŒ   r�   r.   r3   r/   rM   Úcrn   r_   r%   r%   r&   Útest_output_arg_cÝ  s    ÿ
rÝ   c            
      C   s�   ddl m}  ddlm}m} tdƒ\}}}td| |||ƒƒ||ƒgƒ}tƒ }|j|gdddd�}|d d d	kstt	‚d
}	|d d |	ksŒt	‚d S )Nr   r	   rÕ   zif, while, zrÖ   r)   Frl   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;
}
rE   rØ   rÛ   r%   r%   r&   Ú test_output_arg_c_reserved_wordsò  s    ÿ
rÞ   c            	      C   s†   t dddƒ} t dddƒ}t| ƒ}t|ƒ}|| }tddd�}| d|¡}d	|jd
 _d	|jd
 _t|j|gdd�}d}||ks‚t	‚d S )Nr?   rG   ÚbrE   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   r^   rH   Z
result_varÚ_namer'   rP   rI   )	ZA_symZb_symr?   rß   rÜ   ZcgenrM   r¾   r_   r%   r%   r&   Útest_multidim_c_argument_cse  s    ÿ	rå   c                  C   sª   t dƒ\} }}t dƒ\}}tdddƒ}t|tdd| ggƒƒ}t|| | | ƒ}t|d|  ƒ}d|||gf}	d}
t|	d	dd
d
| |||||fd�}|d d }||
ks¦t‚d S )NrZ   úB,Cr?   rE   rG   rF   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"   r+   r   ©r   r   r
   r   r   rI   )r.   r3   r/   r@   rk   r?   ru   rv   Úexpr3r¡   r_   rn   r$   r%   r%   r&   Ú test_ccode_results_named_ordered  s    ÿÿrê   c                  C   s¦   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 }d}||ks¢t‚d S )Nr?   rÎ   rG   r@   rE   rk   ÚDr)   r   rF   rÉ   Frl   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   rI   ©r?   r@   rk   rë   r¡   rn   r$   r_   r%   r%   r&   Útest_ccode_matrixsymbol_slice8  s    þÿrî   c            
      C   s’   t dƒ\} }}}tdddƒ}dt|t| | g| | ||  g| | | | ggƒƒgf}tdd�}t||ddd	�}|d
 d }d}	||	ksŽt‚d S )Nza b c dÚerG   rE   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   rI   )
r2   rß   rÜ   Údrï   r¡   Ú	generatorrn   r$   r_   r%   r%   r&   Útest_ccode_cseU  s    <
ÿrò   c                  C   sJ   t dddƒ} d}tƒ }t||dd| fd�}|d d }d}||ksFt‚d S )	Nr.   rF   rE   )r)   g      ð?F)rR   r!   r"   r+   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   rI   )r.   r¡   rñ   rn   r$   r_   r%   r%   r&   Útest_ccode_unused_array_argi  s    ÿ	ró   c                  C   sp   t dddƒ} t dddƒ}tddd�}d| d	 | d  f}t|d
dd| ||fd�}|d	 d }d}||kslt‚d S )NÚXrG   rE   ÚYr/   TrB   ZtestBugr   rk   F)Úlanguager!   r"   r+   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   rI   )rô   rõ   r/   r¡   rn   r$   r_   r%   r%   r&   Ú test_ccode_unused_array_arg_func|  s    ÿ	r÷   c                  C   s"   t ƒ } t| jg ƒ}|dkst‚d S ©NÚ ©r   r'   Údump_f95rI   rQ   r%   r%   r&   Útest_empty_f_code�  s    rü   c                  C   sB   t ƒ } t| jg dd�}|d d… dks*t‚|dd … dks>t‚d S )NTrT   rU   zR!******************************************************************************
!*rV   a’  *
!*                                                                            *
!*              See http://www.sympy.org/ for more information.               *
!*                                                                            *
!*                       This file is part of 'project'                       *
!******************************************************************************
rú   rQ   r%   r%   r&   Útest_empty_f_code_with_header•  s    
ÿrý   c                  C   s"   t ƒ } t| jg ƒ}|dkst‚d S rø   )r   r'   rX   rI   rQ   r%   r%   r&   Útest_empty_f_header¥  s    rþ   c                  C   sL   t dƒ\} }}| | | }td|ƒ}tƒ }t|j|gƒ}d}||ksHt‚d S )NrZ   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û   rI   r]   r%   r%   r&   Útest_simple_f_code«  s    
ÿ	r  c                  C   sJ   t dtt ƒ} tƒ }t|j| gƒ}dt d¡t d¡f }||ksFt‚d S )Nr)   zˆREAL*8 function test()
implicit none
REAL*8, parameter :: Catalan = %sd0
REAL*8, parameter :: pi = %sd0
test = pi**Catalan
end function
rb   )r   r   r   r   r'   rû   rc   rI   rd   r%   r%   r&   Útest_numbersymbol_f_code½  s    ùr  c                  C   sN   t dƒ} tdt| ƒtd|  ƒ ƒ}tƒ }t|j|gƒ}d}||ksJt|ƒ‚d S )Nr.   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û   rI   )r.   r^   rR   r$   r_   r%   r%   r&   Útest_erf_f_codeË  s    ÿr  c                  C   sR   t dƒ\} }}| | }td||| |gd�}tƒ }t|j|gƒ}d}||ksNt‚d S )NrZ   r)   r*   zŽREAL*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]   r%   r%   r&   Útest_f_code_argument_orderÙ  s    ÿ	r  c                  C   sL   t dƒ\} }}| | | }td|ƒ}tƒ }t|j|gƒ}d}||ksHt‚d S )NrZ   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'   rX   rI   r]   r%   r%   r&   Útest_simple_f_headerë  s    
ÿ
r  c                  C   sH   t dƒ\} }}| | | }td|fddddd�}ddg}||ksDt‚d S )	NrZ   r)   ÚF95r   Frl   )úfile.f90rÿ   )rj   r  rm   )r.   r3   r/   r-   rn   r_   r%   r%   r&   Útest_simple_f_codegenþ  s        ÿ÷r
  c                     sR   t dƒ\} }}| | | }| | | }td||gƒ‰tƒ ‰ tt‡ ‡fdd„ƒ d S )NrZ   r)   c                      s   t ˆ jˆgƒS rp   rq   r%   rr   r%   r&   r0   "  rs   z)test_multiple_results_f.<locals>.<lambda>)r   r   r   r   r   rt   r%   rr   r&   Útest_multiple_results_f  s    þr  c                   C   s   t tdd„ ƒ d S )Nc                   S   s
   t dg ƒS rx   r,   r%   r%   r%   r&   r0   &  rs   z#test_no_results_f.<locals>.<lambda>ry   r%   r%   r%   r&   Útest_no_results_f%  s    r  c                  C   s\  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 dk�st‚d}|d d |k�s(t‚|d d dk�s>t‚d}|d d |k�sXt‚d S )Nr   r|   r~   r€   r†   rˆ   r.   Ztest_absr�   r�   r‘   r’   r“   r”   r•   r–   r—   r˜   r™   rš   r  r   Frl   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
rE   rj   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   rI   )r}   r   r�   r‚   rƒ   r‡   r‰   rŠ   r‹   rŒ   r�   rŽ   r.   r¡   rn   r_   r%   r%   r&   Útest_intrinsic_math_codegen)  s:     












óÿCÿPr  c                  C   s    ddl m}  tdƒ\}}d| ||ƒfd|| fg}t|ddddd	�}|d d d
ksXt‚d}|d d |kspt‚|d d dks„t‚d}|d d |ksœt‚d S )Nr   r£   r¥   r¦   r§   r  r   Frl   r	  zÿREAL*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
rE   rj   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¤   r.   r3   r¡   rn   r_   r%   r%   r&   Útest_intrinsic_math2_codegenÛ  s    
þÿÿr  c            	      C   sä   ddl m} m}m} tdƒ\}}}d||ƒ| |ƒ ||ƒ d  ¡ fd| | | | | | | | || | ƒƒƒƒƒƒƒƒfg}t|ddd	d	d
�}|d d dksœt‚d}|d d |ks´t‚|d d dksÈt‚d}|d d |ksàt‚d S )Nr   rª   rZ   r«   r¬   r­   r  r   Frl   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
rE   rj   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Ž   r.   r3   r/   r¡   rn   r_   r%   r%   r&   Útest_complicated_codegen_f95	  s    ".þÿÿr  c                  C   sÜ   ddl m} m} ddlm} |ddd�\}}t| dƒ\}}}|d|ƒ}|d	|ƒ}	td
t|| |||	f ||	  ƒfddddd�\\}
}\}}|
dks˜t‚d}||ddi ksÀ||ddi ksÀt‚|dksÌt‚|dksØt‚d S )Nr   r<   r±   zn,mTrB   ÚAxyrD   r³   r´   r  r   Frl   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)rj   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
)	rJ   r=   r>   rº   r   rK   r   r   rI   r»   r%   r%   r&   Ú
test_loopsG  s.    

     ÿÿÿÿr  c            
      C   sŒ   ddl m} m} tddtd�\}}| dƒ}| dƒ}|||ƒ}d|jj|jd	œ }td
t|| || ƒƒ}t	ƒ }t
|j|gƒ}	|	|ksˆt‚d S )Nr   r<   rÂ   TrÃ   r.   r3   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
)ZicountZmcountrÆ   )rJ   r=   r>   r   r   rL   rÇ   r   r   r   r'   rû   rI   )
r=   r>   rD   rA   r.   r3   r_   rM   rÜ   r¾   r%   r%   r&   Útest_dummy_loops_f95z  s    

õr  c                  C   sþ   ddl m} m} ddlm} |ddd�\}}}}|dƒ\}}}	| |ƒ|||ƒ|||ƒf }| |ƒ|||ƒ }| |	ƒ|||ƒ }	tdt|	|	||  ƒfd	d
ddd�\\}
}\}}|
dksºt‚d}||ddi ksâ||ddi ksât‚|dksît‚|dksút‚d S )Nr   r<   r±   zi,j,n,mTrB   zA,x,yr´   r  r   Frl   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¶   r  r  rj   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   rD   r³   r¼   rA   r?   r.   r3   r½   r¾   r¿   rÀ   r_   r%   r%   r&   Útest_loops_InOut’  s0        ÿÿÿÿr  c                  C   sþ   ddl m} m} ddlm} |ddd�\}}}}| d||fd�}| d	ƒ}| d
ƒ}	|d||d fƒ}
|d|ƒ}tdt|	|
 ||
|f ||  ƒfddddd�\\}}\}}ddt|d ƒtd| ƒt|d | ƒdœ }||ddi ksú||ddi ksút‚d S )Nr   r<   r±   rË   TrB   r?   rÌ   r.   r3   rD   rÎ   r³   r´   r  r   Frl   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Ï   rE   )r¶   ZiupZilowziup-ilowr¶   r  r  )	rJ   r=   r>   rº   r   r   r   ÚstrrI   rÑ   r%   r%   r&   Útest_partial_loops_fÃ  s2    
     ÿ

üëÿr  c            	      C   sŒ   ddl m}  ddlm}m} tdƒ\}}}td| |||ƒƒ||ƒgƒ}tƒ }|j|gdddd�}|d d d	kstt	‚|d d
 dksˆt	‚d S )Nr   r	   rÕ   rZ   rÖ   r)   Frl   ztest.f90rE   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Ú   rI   )	r
   rŒ   r�   r.   r3   r/   rM   rÜ   rn   r%   r%   r&   Útest_output_arg_fò  s    
ÿr  c                  C   sÀ   ddl m} m} ddlm} |ddd�\}}t| dƒ\}}}|d|ƒ}tƒ }	td	t|||d
  ƒƒ}
t	dt
|| |
|| ƒƒƒ}t|	j|gƒ}d}d}||| ks¼|||d d d…  ks¼t‚d S )Nr   r<   r±   r²   TrB   r  rD   ÚfuncrE   Ztest_inlinezÛsubroutine 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ã   )rJ   r=   r>   rº   r   rK   r   r   r   r   r   r'   rû   rI   )r=   r>   r   r¼   rA   r?   r.   r3   rD   rÓ   r  r^   r¾   r_   Úargsr%   r%   r&   Útest_inline_function  s    
ÿÿr  c                  C   sP   t dƒ} d}| D ]}||7 }qtd|ƒ}tƒ }t|j|gƒ}d}||ksLt‚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   )r.   r-   Úsymr^   rR   r$   r_   r%   r%   r&   Útest_f_code_call_signature_wrap   s    

r  c                      s$   t dƒ\‰‰ tt‡ ‡fdd„ƒ d S )Nzx,Xc                      s   t dˆˆ  fddƒS )Nr)   Úf95r    )r   r%   ©rô   r.   r%   r&   r0   J  rs   z!test_check_case.<locals>.<lambda>)r   r   r   r%   r%   r  r&   Útest_check_caseH  s    r   c               
   C   sl   t dƒ} t ddd�}ztd| | fddƒ W n: tk
rf } z|jd  d¡rVtd	ƒ‚W 5 d }~X Y nX d S )
Nr.   T)Zmy_assumptionr)   r  r    r   zFortran ignores case.z$This exception should not be raised!)r   r   r   r  Ú
startswithrI   )Úx1Zx2rï   r%   r%   r&   Útest_check_case_false_positiveM  s    r#  c                  C   s  t dƒ\} }dd|  fg}t|dddd�}t|ddddd�}|d d |d d ksXt‚d| | f}t|dddd�}t|ddddd�}|d d |d d ks¢t‚dt| |g| | | | ggƒf}t|d	ddd�}t|d	dddd�}|d d |d d k�st‚d S )
Nr¥   rÖ   rF   r  Frl   r   rE   r›   )r   r   rI   r   )r.   r3   r¡   rn   Z	expresultr%   r%   r&   Ú test_c_fortran_omit_routine_name[  s     r$  c                  C   s’   t dƒ\} }}| | }t| |g|dggƒ}d||ff}t|ddddd�}|d d }d	}| ¡ d
 }	|	 d¡}
|
d }|d|i }||ksŽt‚d S )NrZ   é   r)   r  Frl   r   rE   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ÚsplitrI   )r.   r3   r/   Úe1Úe2r¡   rn   r$   r_   r2   rß   râ   r%   r%   r&   Útest_fcode_matrix_outputm  s    ÿ
r,  c                  C   sª   t dƒ\} }}t dƒ\}}tdddƒ}t|tdd| ggƒƒ}t|| | | ƒ}t|d|  ƒ}d|||gf}	t|	ddd	d	| |||||fd
�}
|
d d }d}||ks¦t‚d S )NrZ   ræ   r?   rE   rG   rF   r)   r  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è   )r.   r3   r/   r@   rk   r?   ru   rv   ré   r¡   rn   r$   r_   r%   r%   r&   Ú test_fcode_results_named_orderedŠ  s    ÿÿr-  c                  C   s¦   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 }d}||ks¢t‚d S )Nr?   rF   rG   r@   rE   rk   rë   r)   r   r  Frl   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í   r%   r%   r&   Útest_fcode_matrixsymbol_slice¨  s    þÿr.  c                  C   s|   t dddƒ} d| d d …df f}t|ddddd�}|d	 d }d
}| ¡ d }| d¡}|d }|d|i }||ksxt‚d S )Nr?   rF   rG   r)   rE   r  Frl   r   zÞsubroutine 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)  rI   )r?   r¡   rn   r$   r_   r2   rß   râ   r%   r%   r&   Ú&test_fcode_matrixsymbol_slice_autonameÆ  s    ÿ

r/  c                  C   sŠ   t dƒ\} }}}td| | fddd|fd�}|d d }d}||ksHt‚d	}td| | | fd
dd||fd�}|d d }||ks†t‚d S )Nzx y z tÚfr  F)r!   r"   Úglobal_varsr   rE   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;
}
rk   rm   )r.   r3   r/   Útrn   r$   r_   r%   r%   r&   Útest_global_varsÝ  s    ÿÿÿ	ÿr3  c            
      C   sÊ   ddl m}  ddlm} | dddiid�}tdƒ\}}||| ƒ}t|d	gd
�}d}td|fdd|d�}|d d }	|	|ks€t‚t|d�}|j 	d	¡ d}td|fdd|d�}|d d }	|	|ksÆt‚d S )Nr   ©ÚC99CodePrinter)ÚexpZuser_functionsr6  Z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;
}
r-   F)r!   r"   rR   rE   )r8  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.cr5  r�   r6  r   r   r   rI   r9  Úappend)
r5  r6  r8  r.   r3   r-   Úgenr_   rn   r$   r%   r%   r&   Útest_custom_codegenù  s(    ÿÿ

ÿr=  c                  C   s^   ddl m}  G dd„ d| ƒ}tdƒ}|d }ddg}td	|fd
ddd|ƒ d�}||ksZt‚d S )Nr   r4  c                   @   s   e Zd Zdd„ ZdS )z*test_c_with_printer.<locals>.CustomPrinterc                 S   s   d  |  |j¡|  |j¡¡S )Nzfastpow({}, {}))ÚformatZ_printÚbaser6  )Úselfr-   r%   r%   r&   Ú
_print_Pow+  s    
ÿz5test_c_with_printer.<locals>.CustomPrinter._print_PowN)Ú__name__Ú
__module__Ú__qualname__rA  r%   r%   r%   r&   ÚCustomPrinter*  s   rE  r.   rG   )ri   zŒ#include "file.h"
#include <math.h>
double test(double x) {
   double test_result;
   test_result = fastpow(x, 3);
   return test_result;
}
)rj   zP#ifndef PROJECT__FILE__H
#define PROJECT__FILE__H
double test(double x);
#endif
r)   rk   r   F)r!   r"   r8  )r:  r5  r   r   rI   )r5  rE  r.   r-   r_   rn   r%   r%   r&   Útest_c_with_printer'  s    ÷rF  c                  C   s¸   dd l } d| jj_tddd�}tddd�}td|| fddddd	�}|d d
 }d}||ks`t‚tdƒ}tddd�}td|| fddddd	�}|d d
 }d}||ksªt‚d| jj_d S )Nr   Tr.   )Úrealr3   r)   r  Frl   rE   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.codegenZ	utilitiesr   ZCOMPLEX_ALLOWEDr   rI   )Zsympyr.   r3   rn   r$   r_   r%   r%   r&   Útest_fcode_complexD  s"    
ÿÿrI  N)r   FF)_Úior   Z
sympy.corer   r   r   r   r   r   rÙ   r
   rº   r   Z'sympy.functions.special.error_functionsr   Zsympy.integrals.integralsr   Zsympy.matricesr   r   rH  r   r   r   r   r   r   r   r   r   r   r   Zsympy.testing.pytestr   Zsympy.utilities.lambdifyr   r'   rN   rS   rW   rY   r`   ra   re   rf   rh   ro   rw   r{   r¢   r©   r°   rÁ   rÊ   rÔ   rÝ   rÞ   rå   rê   rî   rò   ró   r÷   rü   rý   rþ   r  r  r  r  r  r
  r  r  r  r  r  r  r  r  r  r  r  r  r   r#  r$  r,  r-  r.  r/  r3  r=  rF  rI  r%   r%   r%   r&   Ú<module>   sŠ    4
<D*, 3.>31/(.