K iB ddlmZddlmZmZmZmZmZmZddl m Z ddl m Z ddl mZddlmZddlmZmZddlmZmZmZmZmZmZmZmZmZmZmZdd l m!Z!dd l"m#Z#dGd Z$d Z%d Z&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2dZ3dZ4dZ5dZ6dZ7dZ8d Z9d!Z:d"Z;d#Zd&Z?d'Z@d(ZAd)ZBd*ZCd+ZDd,ZEd-ZFd.ZGd/ZHd0ZId1ZJd2ZKd3ZLd4ZMd5ZNd6ZOd7ZPd8ZQd9ZRd:ZSd;ZTd<ZUd=ZVd>ZWd?ZXd@ZYdAZZdBZ[dCZ\dDZ]dEZ^yF)H)StringIO)symbolsEqpiCatalanLambdaDummyEquality)Symbol)erf)Integral)Matrix MatrixSymbol) codegen make_routineCCodeGen C89CodeGen C99CodeGen InputArgument CodeGenErrorFCodeGenCodeGenArgumentListErrorOutputArgument InOutArgument)raises)implemented_functioncrt}|||||||j}|j|S)a5Wrapper 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. )rgetvalueclose)dump_fnroutinesprefixheaderemptyoutputsources h/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/utilities/tests/test_codegen.py get_stringr)s5ZF Hfffe4 __ F LLN McZ td\ z z tt fdtt fdtdt    g}|j Dcgc]}|j c}  gk(sJ|j Dcgc] }t|c}ttttgk(sJtdt  g}|j Dcgc] }t|c}tttgk(sJddl m }m }t|dd g\}}td d }|d |}tdt |||||||g}|j Dcgc]}|j c}|j|j|gk(sJt! z z ddf ddf tdt    g}|j Dcgc]}|j c}  gk(sJycc}wcc}wcc}wcc}wcc}w)Nza x y zc$tdgSNtestargument_sequencer)exprxzsr(z-test_Routine_argument_order..&s\&$V.%r*c:tdtgSr-)rr)ar2r3yr4sr(r5z-test_Routine_argument_order..(s$\&"Q C%&1I./r*r.r/r IndexedBaseIdxABmTintegeri)rrrrr argumentsnametyperrr sympy.tensorr:r;maplabelr) rargr:r;r<r=r>rAr7r2r3r8r4s @@@@@r(test_Routine_argument_orderrM#s #JAq!Q E19D #&%& #&/0VR4[Q1aLIA!" .#SXX .1aA, >> >"#++ /3T#Y /}nm4G GG GVR4[Q1IFA"#++ /3T#Y /}m46 66 6. {S#J 'DAqT"A C AVR!ad^1ayIA!" .#SXX .177AGGQ2G GG G AaCEAq!9q!Qi 0DVR4[Q1aLIA!" .#SXX .1aA, >> >! / / 0 / /s4H!H8H?H#4H(cRt}t|jg}|dk(sJy)Nz$#include "file.h" #include rr)dump_ccode_genr's r(test_empty_c_coderS>s(|H  ,F ? ?? ?r*cpt}t|jgd}|dddk(sJ|dddk(sJy)NTr$RzR/****************************************************************************** *a* * * * See http://www.sympy.org/ for more information. * * * * This file is part of 'project' * ******************************************************************************/ #include "file.h" #include rOrQs r(test_empty_c_code_with_commentrXDsV|H D 9F #2;]   #$<["  r*cRt}t|jg}|dk(sJy)Nz9#ifndef PROJECT__FILE__H #define PROJECT__FILE__H #endif )rr)dump_hrQs r(test_empty_c_headerr[Vs(|H  ,F S SS Sr*ctd\}}}||z|z}td|}t}t|j|g}d}||k(sJy)Nx,y,zr.#include "file.h" #include double test(double x, double y, double z) { double test_result; test_result = z*(x + y); return test_result; } rrrr)rPr3r8r4r2routinerRr'expecteds r(test_simple_c_coderc\s^gGAq! E19D64(G|H ' 3F   X  r*ctd\}}}||z|z}td|}t}t|j|g}d}||k(sJy)Nzif, typedef, whiler.z#include "file.h" #include double test(double if_, double typedef_, double while_) { double test_result; test_result = while_*(if_ + typedef_); return test_result; } )rrrr)rPr`s r(test_c_code_reserved_wordsrens_*+GAq! EQ;D64(G|H ' 3F   X  r*ctdttz}t}t |j |g}dtj dz}||k(sJy)Nr.z#include "file.h" #include double test() { double test_result; double const Catalan = %s; test_result = pow(M_PI, Catalan); return test_result; } )rrrrr)rPevalfrarRr'rbs r(test_numbersymbol_c_coderjsU62w;/G|H ' 3F   b H X  r*ctd\}}}||z}td||||g}t}t|j|g}d}||k(sJy)Nr]r.r/z#include "file.h" #include double test(double z, double x, double y) { double test_result; test_result = x + y; return test_result; } r_r`s r(test_c_code_argument_orderrlsbgGAq! q5D64Aq!9EG|H ' 3F   X  r*ctd\}}}||z|z}td|}t}t|j|g}d}||k(sJy)Nr]r.d#ifndef PROJECT__FILE__H #define PROJECT__FILE__H double test(double x, double y, double z); #endif )rrrr)rZr`s r(test_simple_c_headerros^gGAq! E19D64(G|H ' 3F  X  r*cltd\}}}||z|z}ddg}td|fdddd}||k(sJy) Nr])file.cr^)file.hrnr.CfileFr$r%rr)r3r8r4r2rbresults r(test_simple_c_codegenrxsVgGAq! E19D  Hfd^S&e LF X  r*ctd\}}}||z|z}||z |z}td||gtttfdy)Nr]r.c2tjgSNr)rZrRrasr(r5z)test_multiple_results_c..HOOgY!Gr*)rrrrrr3r8r4expr1expr2rRras @@r(test_multiple_results_crsUgGAq! UAIE UAIE G|H <GHr*c&ttdy)NctdgSNr.r1r*r(r5z#test_no_results_c.. |FB7r*r ValueErrorrr*r(test_no_results_cr  :78r*cddlm}ddlm}ddlm}m}m}ddlm }m }ddl m }ddl m}m} m} m} m} m} t)d}d ||fd ||fd | |fd | |fd ||fd| |fd||fd||fd||fd||fd| |fd||fd||fd| |fd||fg}t+|dddd}|dddk(sJ|dddk(sJ|dddk(sJ|ddd k(sJy)!NrAbslogcoshsinhtanh)ceilingfloorsqrtacosasinatancossintanr3 test_fabs test_acos test_asin test_atan test_ceiltest_cos test_cosh test_floortest_logtest_lntest_sin test_sinh test_sqrttest_tan test_tanhC89rtFrurqrBa#include "file.h" #include 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; } rra#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.hyperbolicrrr#sympy.functions.elementary.integersrr(sympy.functions.elementary.miscellaneousr(sympy.functions.elementary.trigonometricrrrrrrrr)rrrrrrrrrrrrrrr3 name_exprrws r(test_ansi_math1_codegenrs_8:HHD=ZZ A c!f d1g d1g d1g gaj! SV d1g uQx SV CF SV d1g d1g SV d1gI"Yve5 IF !9Q<8 ## # !9Q< F  $ !9Q<8 ## # !9Q< 0   r*cddlm}td\}}d|||fd||zfg}t|dddd }|ddd k(sJ|dd d k(sJ|d dd k(sJ|d d dk(sJy)Nratan2x,y test_atan2test_powrrtFrurqrBa*#include "file.h" #include 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; } rrz#ifndef PROJECT__FILE__H #define PROJECT__FILE__H double test_atan2(double x, double y); double test_pow(double x, double y); #endif rrrr)rr3r8rrws r(test_ansi_math2_codegenrs> 5>DAq uQ{# QTIYve5 IF !9Q<8 ## # !9Q< N   !9Q<8 ## # !9Q<   r*cddlm}m}m}t d\}}}d||||z||zdzj fd||||||||||z|zfg}t |ddd d }|ddd k(sJ|dd d k(sJ|d ddk(sJ|d d dk(sJy)Nrrrrr]test1test2rrtFrurqrBa-#include "file.h" #include 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; } rrz#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 rrrrrexpandr)rrrr3r8r4rrws r(test_complicated_codegenr,sHHgGAq! CFSVOc!f,q088:; #c#c#c#c!a%!)n*=&>"?@ABCDIYve5 IF !9Q<8 ## # !9Q<. 0 00 b !9Q<8 ## # !9Q<   r*c ddlm}m}ddlm}|dd\}}|d}|d}|d }|d |}|d |} t d t ||||| f|| zfd ddd\\} } \} } | dk(sJd}| |dd||z| zzizk(s;| |dd| ||zzzizk(s(| |dd||z| zzizk(s| |dd| ||zzzizk(sJ| dk(sJ| dk(sJy)Nrr9rn mTr?r<r3r8rAj matrix_vectorC99rtFrurqa#include "file.h" #include void matrix_vector(double *A, int m, int n, double *x, double *y) { for (int i=0; ir<r3r8rArf1codef2 interfacerbs r( test_loops_crpsW-) 5$ 'DAqCACACA C A C A") "QqT1QT71Q4<015&V[#]JRY >>   H|qsQw'?@@ @ H|q1Q3w'?@@ @ H|qsQw'?@@ @ H|q1Q3w'?@@ @B A >>    r*cddlm}m}tddt\}}|d}|d}|||}d|j j |j d z}td t||||}t}t} t| j|g} | |k(sJtt5t|j|gdddy#1swYyxYw) Nrr9i mTr@clsr3r8z#include "file.h" #include void test_dummies(int m_%(mno)i, double *x, double *y) { for (int i_%(ino)i=0; i_%(ino)ir3r8rbrKc89c99rs r(test_dummy_loops_crs- 5$E 2DAqCACA Aq A ##AMM:;H ^R!ad^4A ,C ,C cjj1# &D 8   # $$3::s#$$$s :CC$c ddlm}m}ddlm}|dd\}}}}|d||f}|d }|d } |d ||d z f} |d |} t dt | | || | f|| zfdddd\\} } \}}| dk(sJd|dz ddz}| |dd| |z| zzizk(s;| |dd| | |zzzizk(s(| |dd| |z| zzizk(s| |dd| | |zzzizk(sJ|dk(sJ|dk(sJy)Nrr9rn m o pTr?r<shaper3r8rArrrrtFrurqa##include "file.h" #include 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; jopr<r3r8rArrrrrrbs r(test_partial_loops_crs|.)D1JAq!QC1v&ACACA C!QUA C A") "QqT1QT71Q4<015&V[#]JRY >> q5+ ,H H|qsQw'?@@ @ H|q1Q3w'?@@ @ H|qsQw'?@@ @ H|q1Q3w'?@@ @B A >>    r*c ddlm}ddlm}m}t d\}}}t d||||||g}t}|j|gddd}|ddd k(sJd } |dd | k(sJy) Nrr rrr]foor.Frutest.cz#include "test.h" #include double foo(double x, double *y) { (*y) = sin(x); double foo_result; foo_result = cos(x); return foo_result; } rB sympy.core.relationalr rrrrrrwrite r rrr3r8r4rKcrwrbs r(test_output_arg_crs.CgGAq!UXaQ0#a&9:A A WWaS&eW double foo(double if_, double *while_) { (*while_) = sin(if_); double foo_result; foo_result = cos(if_); return foo_result; } rBrrs r( test_output_arg_c_reserved_wordsrs.Cn%GAq!UXaQ0#a&9:A A WWaS&eW 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]; } ) rrrrarE result_var_namer)rP) A_symb_symr<rrcgenrKrrbs r(test_multidim_c_argument_cser s a #E a #Eu Au A !A F -D S!A!&AKKO!AKKO dkkA3v 6D   8  r*c *td\}}}td\}}tddd}t|tdd|gg}t|||z|z}t|d|z}d|||gf} d} t | d dd d ||||||f } | d d} | | k(sJy) Nr]B,Cr<rBrDrCr.z#include "test.h" #include 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; } rFr$r%r0rrrr rr) r3r8r4r=rsr<rrexpr3rrbrwr's r( test_ccode_results_named_orderedrsgGAq! 5>DAqS!QA QAq {+ ,E QQ "E Q! E%./I  YVE()1aAq'9;F AYq\F X  r*c "tddd}tddd}tddd}tddd}dt||d ddft||dddft||ddd fgf}t|d dd d }|d d}d}||k(sJy)Nr<rrDr=rBrsDr.rrCrFrua#include "test.h" #include 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]; } rr rr<r=rsrrrwr'rbs r(test_ccode_matrixsymbol_slicer8sS!QAS!QAS!QAS!QA(1a1g."1a1g."1a1g.01IYve5 IF AYq\F  " X  r*c td\}}}}tddd}dt|t||zg||z||zzg||z|z|zgggf}t d}t ||dd }|d d}d } || k(sJy) Nza b c derDrBr.T)rF)rRr$r%rz#include "test.h" #include 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; } )rrr rrr) r7rrdrr generatorrwr'rbs r(test_ccode_cserUs#JAq!QS!QA(1fqseacAaCi[1Q3q57)-L&MNOPIT"I Y5 NF AYq\F   X  r*cztddd}d}t}t||dd|f}|dd}d}||k(sJy) Nr3rCrB)r.g?F)rRr$r%r0rz#include "test.h" #include double test(double *x) { double test_result; test_result = 1.0; return test_result; } )rrr)r3rrrwr'rbs r(test_ccode_unused_array_argrisYS!QAI I Y5bcae fF AYq\F   X  r*c tddd}tddd}tdd}d|d |dzf}t|d d d |||f }|d d}d }||k(sJy)NXrDrBYr4Tr?testBugrrsF)languager$r%r0z#include "testBug.h" #include double testBug(double *X, double *Y, int z) { double testBug_result; testBug_result = X[0] + X[1]; return testBug_result; } )rrr)rrr4rrwr'rbs r( test_ccode_unused_array_arg_funcr!|sS1AS1Ad#AAaD1Q4K(I YU%\]_`bc[d eF AYq\F   X  r*cRt}t|jg}|dk(sJyNrr)dump_f95rQs r(test_empty_f_coder's'zH ))2 .F R<."r~r*)rrrrrrs @@r(test_multiple_results_fr@sUgGAq! UAIE UAIE GzH <GHr*c&ttdy)NctdgSrr1rr*r(r5z#test_no_results_f..&rr*rrr*r(test_no_results_frC%rr*cddlm}ddlm}ddlm}m}m}ddlm }ddl m }m }m }m} m} m} t#d} d|| fd || fd || fd || fd | | fd || fd|| fd|| fd| | fd|| fd|| fd| | fd|| fg } t%| dddd}|dddk(sJd}|dd|k(sJ|dddk(sJd}|dd|k(sJy)Nrrrrrrr3test_absrrrrrrrrrrrrr;rtFrur<aREAL*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 rBrraAinterface 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 )rrrrrrrrrrrrrrrrrrr)rrrrrrrrrrrrr3rrwrbs r(test_intrinsic_math_codegenrF)sK8:HH=ZZ A SV d1g d1g d1g SV d1g SV CF SV d1g d1g SV d1gIYve5 IF !9Q<: %% %@  F !9Q<8 ## # !9Q<8 ## #M  ` !9Q<8 ## #r*cddlm}td\}}d|||fd||zfg}t|dddd }|ddd k(sJd }|dd |k(sJ|d dd k(sJd}|d d |k(sJy)Nrrrrrr;rtFrur<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 rBrrainterface 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)rr3r8rrwrbs r(test_intrinsic_math2_codegenrHs> 5>DAq uQ{# QTIYve5 IF !9Q<: %% %   !9Q<8 ## # !9Q<8 ## #  !9Q<8 ## #r*cddlm}m}m}t d\}}}d||||z||zdzj fd||||||||||z|zfg}t |ddd d }|ddd k(sJd }|dd |k(sJ|d ddk(sJd}|d d |k(sJy)Nrrr]rrrr;rtFrur<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 rBrra4interface 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) rrrr3r8r4rrwrbs r(test_complicated_codegen_f95rJ sHHgGAq! CFSVOc!f,q088:; #c#c#c#c!a%!)n*=&>"?@ABCDIYve5 IF !9Q<: %% %  < !9Q<8 ## # !9Q<8 ## #  $ !9Q<8 ## #r*c >ddlm}m}ddlm}|dd\}}t |d\}}}|d|}|d |} t d t||||| f|| zfd d d d \\} } \} } | dk(sJd}| |ddizk(s | |ddizk(sJ| dk(sJ| dk(sJy)Nrr9rzn,mTr?AxyrArrr;rtFrur<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)rrainterface 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 )rHr:r;rrrIrrrs r( test_loopsrOGs-) 5$ 'DAq+u%GAq! C A C A") "QqT1QT71Q4<015&V[#]JRY     * 8un55 5 E>2223 3 >>     r*cDddlm}m}tddt\}}|d}|d}|||}d|j j |j d z}td t||||}t}t|j|g} | |k(sJy) Nrr9rTrr3r8a>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 )icountmcountr) rHr:r;rr rJrrrrr)r&) r:r;rAr>r3r8rbrKrrs r(test_dummy_loops_f95rSzs- 5$E 2DAqCACA Aq A 77&&!--@ AH ^R!ad^4A A ajj1# &D 8  r*c ddlm}m}ddlm}|dd\}}}}|d\}}} ||||||||f}|||||}|| |||} t dt | | ||zzfd d d d \\} } \} } | d k(sJd}| |ddizk(s | |ddizk(sJ| dk(sJ| dk(sJy)Nrr9rzi,j,n,mTr?zA,x,yrr;rtFrur<aasubroutine 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 rrMrNrrainterface 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;rrArrr>r<r3r8rrrrrbs r(test_loops_InOutrUs-)D1JAq!QgGAq!As1ay#a)+,AAs1ay!AAs1ay!A") "QAaC.)5&e#UJRY     $ H~66 6 H~66 68 7 >>     r*c ddlm}m}ddlm}|dd\}}}}|d||f}|d }|d } |d ||d z f} |d |} t dt | | || | f|| zfdddd\\} } \}}ddt|dz td|zt|dz |z dz}| |ddizk(s | |ddizk(sJyy)Nrr9rrTr?r<rr3r8rArrrr;rtFruasubroutine 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 rrrB)riupilowziup-ilowrrMrN)rHr:r;rrrrstrrs r(test_partial_loops_frZs.)D1JAq!QC1v&ACACA C!QUA C A") "QqT1QT71Q4<015&V[#]JRY *1q5zAE A N  +H8 8un55 5 E>2223 32 6r*c ddlm}ddlm}m}t d\}}}t d||||||g}t}|j|gddd}|ddd k(sJ|dd d k(sJy) Nrr rr]rr.Fruztest.f90rBz~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 ) rr rrrrrrr) r rrr3r8r4rKrrws r(test_output_arg_fr\s.CgGAq!UXaQ0#a&9:A A WWaS&eW r<r3r8rArr^rarrbargss r(test_inline_functionras-) 5$ 'DAq+u%GAq! C A A q!QU)(< =D="QqT4!:*>?G ajj7) ,D   "D 8d? " 4":%%& &% #r*ctd}d}|D]}||z } td|}t}t|j|g}d}||k(sJy)Nzx:20rr.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.)r3r2symrarRr'rbs r(test_f_code_call_signature_wraprd sfA D  64(GzH ))G9 5FH8 X  r*cLtd\ttfdy)Nzx,Xc(tdzfddS)Nr.f95r#)rrr3sr(r5z!test_check_case..Js&!A#x!Hr*)rrrrhs@@r(test_check_caseriHs 5>DAq <HIr*ctd}tdd} td||zfddy#t$r3}|jdj dr t d Yd}~yd}~wwxYw) Nr3T) my_assumptionr.rgr#rzFortran ignores case.z$This exception should not be raised!)rrrr` startswithAssertionError)x1x2rs r(test_check_case_false_positiverpMsm B D )BIB1 I 66!9   7 8 !GH H 9Is- A))A$$A)ctd\}}dd|zfg}t|ddd}t|dddd}|dd|ddk(sJd||zf}t|ddd}t|dddd}|dd|ddk(sJdt||g||z||z ggf}t|d dd}t|d ddd}|dd|ddk(sJy) NrrrCr;FrurrBr)rrr)r3r8rrw expresults r( test_c_fortran_omit_routine_namers[s 5>DAq1I Ye5 AF 5%UKI !9Q<9Q<? ** *! I Ye5 AF 5%UKI !9Q<9Q<? ** *A1ac 345I Ye5 AF 5%UKI !9Q<9Q<? ** *r*ctd\}}}||z}t||g|dgg}d||ff}t|dddd}|dd}d }|jd } | j d } | d} |d | iz}||k(sJy) Nr]r.rgFrurrBa2REAL*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)rrr splitlinessplit) r3r8r4e1e2rrwr'rbr7rrs r(test_fcode_matrix_outputr|msgGAq! QB !Q!R! "B"b"I Yve5 IF AYq\F   AA  A A$C63-'H X  r*c *td\}}}td\}}tddd}t|tdd|gg}t|||z|z}t|d|z}d|||gf} t | ddd d ||||||f } | d d} d } | | k(sJy) Nr]r r<rBrDrCr.rgFr ra!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 ) r3r8r4r=rsr<rrrrrwr'rbs r( test_fcode_results_named_orderedr~sgGAq! 5>DAqS!QA QAq {+ ,E QQ "E Q! E%./I Yve5()1aAq'9;F AYq\F  X  r*c "tddd}tddd}tddd}tddd}dt||d ddft||dddft||dddfgf}t|d dd d }|d d}d }||k(sJy)Nr<rCrDr=rBrsrr.rrgFruasubroutine 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 rrs r(test_fcode_matrixsymbol_slicersS!QAS!QAS!QAS!QA(1a1g."1a1g."1a1g.01IYve5 IF AYq\F  " X  r*ctddd}d|dddff}t|dddd}|d d}d }|jd}|jd }|d}|d |iz}||k(sJy) Nr<rCrDr.rBrgFrurzsubroutine 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 rvrw)rrrxry)r<rrwr'rbr7rrs r(&test_fcode_matrixsymbol_slice_autonamersS!QA1a4!I Yve5 IF AYq\F   AA  A A$C63-'H X  r*ctd\}}}}td||zfddd|f}|dd}d}||k(sJd }td||z|zfd dd||f}|dd}||k(sJy) Nzx y z tfr;F)r$r% global_varsrrBzPREAL*8 function f(x) implicit none REAL*8, intent(in) :: x f = x*y end function z#include "f.h" #include double f(double x, double y) { double f_result; f_result = x*y + z; return f_result; } rsrv)r3r8r4trwr'rbs r(test_global_varsrs#JAq!Q c1Q3ZuE"#'F AYq\F   X    c1Q3q5\3uE"#Q)F AYq\F X  r*cZddlm}ddlm}|dddii}t d\}}|||z}t |d g }d }t d |fd d |}|dd} | |k(sJt |}|jjd d}t d |fd d |}|dd} | |k(sJy)NrC99CodePrinter)expuser_functionsrfastexp)settingszx yz#include "fastexp.h")printerpreprocessor_statementsz#include "expr.h" #include "fastexp.h" double expr(double x, double y) { double expr_result; expr_result = fastexp(x + y); return expr_result; } r2F)r$r%rRrB)rz#include "expr.h" #include #include "fastexp.h" double expr(double x, double y) { double expr_result; expr_result = fastexp(x + y); return expr_result; } ) sympy.printing.crrrrrrrappend) rrrr3r8r2genrbrwr's r(test_custom_codegenrs/:'7%9K&LMG 5>DAq q1u:D W.D-E GC  fd^E MF AYq\F X   W %C&&'=>  fd^E MF AYq\F X  r*c ddlm}Gdd|}td}|dz}ddg}td |fd d d d | }||k(sJy)NrrceZdZdZy)*test_c_with_printer..CustomPrintercdj|j|j|j|jS)Nzfastpow({}, {}))format_printbaser)selfr2s r( _print_Powz5test_c_with_printer..CustomPrinter._print_Pow+s6$++DKK ,B,0KK,AC Cr*N)__name__ __module__ __qualname__rrr*r( CustomPrinterr*s Cr*rr3rD)rqz#include "file.h" #include double test(double x) { double test_result; test_result = fastpow(x, 3); return test_result; } )rrzP#ifndef PROJECT__FILE__H #define PROJECT__FILE__H double test(double x); #endif r.rsrtF)r$r%r)rrrr)rrr3r2rbrws r(test_c_with_printerr'sd/CC  A a4D  Hfd^SUVcVe fF X  r*ctddl}d|jj_t dd}t dd}td||zfdddd }|dd }d }||k(sJt d}t dd}td||zfdddd }|dd }d }||k(sJd|jj_y) NrTr3)realr8r.rgFrurBzsREAL*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 utilitiesrCOMPLEX_ALLOWEDr )sympyr3r8rwr'rbs r(test_fcode_complexrDs".2EOO+sAsA fQqS\5&e LFQilF   X  s AsA fQqS\5&e LFQilF   8  .3EOO+r*N)rtFF)_ior sympy.corerrrrrr rr rr 'sympy.functions.special.error_functionsr sympy.integrals.integralsrsympy.matricesrrrrrrrrrrrrrrsympy.testing.pytestrsympy.utilities.lambdifyrr)rMrSrXr[rcrerjrlrorxrrrrrrrrrrr rrrrr!r'r)r+r/r1r4r6r9r=r@rCrFrHrJrOrSrUrZr\rardrirprsr|r~rrrrrrrr*r(rst>>*$7./(9 ?6@ $T $$"$ , I99x0AH'T$.)X$*$*.4:(&&   $  &$&6 I9o$d+$\;$|0f0.b,3^&&6%PJ I+$:<<.8,\:4r*