U
    0e                     @   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# dd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]dS )    )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)dump_fnZroutinesprefixheaderemptyoutputsource r&   F/tmp/pip-unpacked-wheel-_6tpq7m6/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std	d | jD ttttgksttdtgd} d
d | jD t	ttgkst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st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/   yr0   r&   r'   r1   (   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&   typer7   r&   r&   r'   r:   ,   s     c                 S   s   g | ]}t |qS r&   r;   r7   r&   r&   r'   r:   /   s     r   IndexedBaseIdxABmTintegeric                 S   s   g | ]
}|j qS r&   r5   r7   r&   r&   r'   r:   7   s              c                 S   s   g | ]
}|j qS r&   r5   r7   r&   r&   r'   r:   ;   s     )r   r   r   r   r   	argumentsAssertionErrorr   r   r   sympy.tensorr>   r?   maplabelr   )rr>   r?   r@   rA   rB   rE   r&   r2   r'   test_Routine_argument_order#   s6        
  

"$ rO   c                  C   s"   t  } t| jg }|dkstd S )Nz$#include "file.h"
#include <math.h>
r   r(   dump_crJ   code_genr%   r&   r&   r'   test_empty_c_code>   s    rT   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>
rP   rR   r&   r&   r'   test_empty_c_code_with_commentD   s    
rX   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_hrJ   rR   r&   r&   r'   test_empty_c_headerV   s    rZ   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(   rQ   rJ   r/   r4   r0   r.   routinerS   r%   expectedr&   r&   r'   test_simple_c_code\   s    
	ra   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(   rQ   rJ   r^   r&   r&   r'   test_c_code_reserved_wordsn   s    
	rb   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(   rQ   evalfrJ   r_   rS   r%   r`   r&   r&   r'   test_numbersymbol_c_code   s    
rf   c                  C   sR   t d\} }}| | }td||| |gd}t }t|j|g}d}||ksNtd S )Nr[   r*   r+   z#include "file.h"
#include <math.h>
double test(double z, double x, double y) {
   double test_result;
   test_result = x + y;
   return test_result;
}
r]   r^   r&   r&   r'   test_c_code_argument_order   s    	rg   c                  C   sL   t d\} }}| | | }td|}t }t|j|g}d}||ksHtd S )Nr[   r*   d#ifndef PROJECT__FILE__H
#define PROJECT__FILE__H
double test(double x, double y, double z);
#endif
)r   r   r   r(   rY   rJ   r^   r&   r&   r'   test_simple_c_header   s    
ri   c                  C   sH   t d\} }}| | | }ddg}td|fddddd}||ksDtd S )	Nr[   )file.cr\   )file.hrh   r*   Cr   Fr"   r#   r   r   rJ   )r/   r4   r0   r.   r`   resultr&   r&   r'   test_simple_c_codegen   s    rp   c                     sR   t d\} }}| | | }| | | }td||gt  tt fdd d S )Nr[   r*   c                      s   t  jgS Nr(   rY   r&   rS   r_   r&   r'   r1          z)test_multiple_results_c.<locals>.<lambda>)r   r   r   r   r   r/   r4   r0   expr1expr2r&   rs   r'   test_multiple_results_c   s    rx   c                   C   s   t tdd  d S )Nc                   S   s
   t dg S Nr*   r-   r&   r&   r&   r'   r1      rt   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   Frm   rj   rF   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;
}
rk   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   rJ   )r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r/   	name_exprro   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st|d d dkstd S )Nr   atan2x,y
test_atan2test_powr   r   Frm   rj   rF   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;
}
rk   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   rJ   )r   r/   r4   r   ro   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st|d d dkst|d d dkst|d d dkstd S )Nr   r   r   r   r[   test1   test2r   r   Frm   rj   rF   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;
}
rk   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   rJ   )r   r   r   r/   r4   r0   r   ro   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st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 mTrC   r@   r/   r4   rE   jmatrix_vectorC99r   Frm   rj   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]rk   z|#ifndef PROJECT__FILE__H
#define PROJECT__FILE__H
void matrix_vector(double *A, int m, int n, double *x, double *y);
#endif
rK   r>   r?   sympy.core.symbolr   r   r   rJ   r>   r?   r   nrB   r@   r/   r4   rE   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sttt t|j|g W 5 Q R X d S )Nr   r=   i mTrD   clsr/   r4   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)rK   r>   r?   r   r   rM   dummy_indexr   r   r   r   r(   rQ   rJ   r   NotImplementedError)r>   r?   rE   rB   r/   r4   r`   rN   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st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 pTrC   r@   shaper/   r4   rE      r   r   r   r   Frm   rj   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   rk   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   rB   opr@   r/   r4   rE   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st	d S )Nr   r	   r   r   r[   foor*   Frm   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;
}
rF   
sympy.core.relationalr
   r   r   r   r   r   r   writerJ   
r
   r   r   r/   r4   r0   rN   cro   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st	d S )Nr   r	   r   zif, while, zr   r*   Frm   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;
}
rF   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st	d S )Nr@   rH   brF   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_   rI   Z
result_var_namer(   rQ   rJ   )	ZA_symZb_symr@   r   r   ZcgenrN   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std S )Nr[   B,Cr@   rF   rH   rG   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   rJ   )r/   r4   r0   rA   rl   r@   rv   rw   expr3r   r`   ro   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std S )Nr@   r   rH   rA   rF   rl   Dr*   r   rG   r   Frm   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   rJ   r@   rA   rl   r   r   ro   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std S )Nza b c derH   rF   r*   T)r   F)rS   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   rJ   )
r3   r   r   dr   r   	generatorro   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/   rG   rF   )r*   g      ?F)rS   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   rJ   )r/   r   r   ro   r%   r`   r&   r&   r'   test_ccode_unused_array_argi  s    	r   c                  C   s"   t  } t| jg }|dkstd S N r   r(   dump_f95rJ   rR   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 )NTrU   rV   zR!******************************************************************************
!*rW   a  *
!*                                                                            *
!*              See http://www.sympy.org/ for more information.               *
!*                                                                            *
!*                       This file is part of 'project'                       *
!******************************************************************************
r   rR   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(   rY   rJ   rR   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 )Nr[   r*   REAL*8 function test(x, y, z)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(in) :: y
REAL*8, intent(in) :: z
test = z*(x + y)
end function
r   r   r   r(   r   rJ   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*   zREAL*8 function test()
implicit none
REAL*8, parameter :: Catalan = %sd0
REAL*8, parameter :: pi = %sd0
test = pi**Catalan
end function
rc   )r   r   r   r   r(   r   rd   rJ   re   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   rJ   )r/   r_   rS   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 )Nr[   r*   r+   zREAL*8 function test(z, x, y)
implicit none
REAL*8, intent(in) :: z
REAL*8, intent(in) :: x
REAL*8, intent(in) :: y
test = x + y
end function
r   r^   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 )Nr[   r*   interface
REAL*8 function test(x, y, z)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(in) :: y
REAL*8, intent(in) :: z
end function
end interface
)r   r   r   r(   rY   rJ   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 )	Nr[   r*   F95r   Frm   )file.f90r   )rk   r  rn   )r/   r4   r0   r.   ro   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 )Nr[   r*   c                      s   t  jgS rq   rr   r&   rs   r&   r'   r1     rt   z)test_multiple_results_f.<locals>.<lambda>)r   r   r   r   r   ru   r&   rs   r'   test_multiple_results_f  s    r  c                   C   s   t tdd  d S )Nc                   S   s
   t dg S ry   r-   r&   r&   r&   r'   r1     rt   z#test_no_results_f.<locals>.<lambda>rz   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   Frm   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
rF   rk   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   rJ   )r~   r   r   r   r   r   r   r   r   r   r   r   r/   r   ro   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std}|d d |kstd S )Nr   r   r   r   r   r  r   Frm   r  zREAL*8 function test_atan2(x, y)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(in) :: y
test_atan2 = atan2(x, y)
end function
REAL*8 function test_pow(x, y)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(in) :: y
test_pow = x**y
end function
rF   rk   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/   r4   r   ro   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std}|d d |kst|d d dkstd}|d d |kstd S )Nr   r   r[   r   r   r   r  r   Frm   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
rF   rk   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/   r4   r0   r   ro   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std}||ddi ks||ddi kst|dkst|dkstd S )Nr   r=   r   zn,mTrC   AxyrE   r   r   r  r   Frm   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)rk   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
)	rK   r>   r?   r   r   rL   r   r   rJ   r   r&   r&   r'   
test_loops4  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std S )Nr   r=   r   Tr   r/   r4   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   )rK   r>   r?   r   r   rM   r   r   r   r   r(   r   rJ   )
r>   r?   rE   rB   r/   r4   r`   rN   r   r   r&   r&   r'   test_dummy_loops_f95g  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std}||ddi ks||ddi kst|dkst|dkstd S )Nr   r=   r   zi,j,n,mTrC   zA,x,yr   r  r   Frm   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  rk   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   rE   r   r   rB   r@   r/   r4   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std S )Nr   r=   r   r   TrC   r@   r   r/   r4   rE   r   r   r   r  r   Frm   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   rF   )r   ZiupZilowziup-ilowr   r  r  )	rK   r>   r?   r   r   r   r   strrJ   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st	d S )Nr   r	   r   r[   r   r*   Frm   ztest.f90rF   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   rJ   )	r
   r   r   r/   r4   r0   rN   r   ro   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std S )Nr   r=   r   r   TrC   r  rE   funcrF   Z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   )rK   r>   r?   r   r   rL   r   r   r   r   r   r(   r   rJ   )r>   r?   r   r   rB   r@   r/   r4   rE   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_   rS   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&   Xr/   r&   r'   r1   7  rt   z!test_check_case.<locals>.<lambda>)r   r   r   r&   r&   r  r'   test_check_case5  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  
startswithrJ   )x1Zx2r   r&   r&   r'   test_check_case_false_positive:  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st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   rG   r  Frm   r   rF   r   )r   r   rJ   r   )r/   r4   r   ro   Z	expresultr&   r&   r'    test_c_fortran_omit_routine_nameH  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std S )Nr[      r*   r  Frm   r   rF   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splitrJ   )r/   r4   r0   e1e2r   ro   r%   r`   r3   r   r   r&   r&   r'   test_fcode_matrix_outputZ  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std S )Nr[   r   r@   rF   rH   rG   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/   r4   r0   rA   rl   r@   rv   rw   r   r   ro   r%   r`   r&   r&   r'    test_fcode_results_named_orderedw  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std S )Nr@   rG   rH   rA   rF   rl   r   r*   r   r  Frm   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@   rG   rH   r*   rF   r  Frm   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'  rJ   )r@   r   ro   r%   r`   r3   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std S )Nzx y z tfr  F)r"   r#   global_varsr   rF   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;
}
rl   rn   )r/   r4   r0   tro   r%   r`   r&   r&   r'   test_global_vars  s    	r1  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stt|d}|j	d	 d}td|fdd|d}|d d }	|	|kstd S )Nr   C99CodePrinter)expZuser_functionsr4  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#   rS   rF   )r6  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.cr3  r   r4  r   r   r   rJ   r7  append)
r3  r4  r6  r/   r4   r.   genr`   ro   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   r2  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baser4  )selfr.   r&   r&   r'   
_print_Pow  s    
z5test_c_with_printer.<locals>.CustomPrinter._print_PowN)__name__
__module____qualname__r?  r&   r&   r&   r'   CustomPrinter  s   rC  r/   rH   )rj   z#include "file.h"
#include <math.h>
double test(double x) {
   double test_result;
   test_result = fastpow(x, 3);
   return test_result;
}
)rk   zP#ifndef PROJECT__FILE__H
#define PROJECT__FILE__H
double test(double x);
#endif
r*   rl   r   F)r"   r#   r6  )r8  r3  r   r   rJ   )r3  rC  r/   r.   r`   ro   r&   r&   r'   test_c_with_printer  s    rD  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std| jj_d S )Nr   Tr/   )realr4   r*   r  Frm   rF   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   rJ   )Zsympyr/   r4   ro   r%   r`   r&   r&   r'   test_fcode_complex1  s"    
rG  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   rF  r   r   r   r   r   r   r   r   r   r   r   Zsympy.testing.pytestr   Zsympy.utilities.lambdifyr   r(   rO   rT   rX   rZ   ra   rb   rf   rg   ri   rp   rx   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-  r1  r;  rD  rG  r&   r&   r&   r'   <module>   s    4
<D*, 3.>31/(.