K i61ddlmZmZmZddlmZmZddlmZm Z m Z ddl Z ddl Z ddl Z ddlZddlmZiZded<ded <ed ed <iZd ed <ed ed <d ed<iZgd ed<gded<gded<gded<gdZdZd#dZdZdZgZgZeD]:\ZZeeZeeerej=eef(ej=eef<dZdZ dZ!dZ"dZ#dZ$d Z%d!Z&d"Z'y)$)xyz)IS_WASMskip)codegen make_routineget_code_generatorN)Pathzy program main include "codegen.h" integer :: result; result = 0 %(statements)s call exit(result) end program F95z #include "codegen.h" #include #include int main() { int result = 0; %(statements)s return result; } C89C99z if (fabs(%(call)s)>%(threshold)s) { printf("Numerical validation failed: %(call)s=%%e threshold=%(threshold)s\n", %(call)s); result = -1; } z if (abs(%(call)s)>%(threshold)s) then write(6,"('Numerical validation failed:')") write(6,"('%(call)s=',e15.5,'threshold=',e15.5)") %(call)s, %(threshold)s result = -1; end if )zcc -c codegen.c -o codegen.ozcc -c main.c -o main.oz#cc main.o codegen.o -lm -o test.execc)z$gfortran -c codegen.f90 -o codegen.oz6gfortran -ffree-line-length-none -c main.f90 -o main.oz%gfortran main.o codegen.o -o test.exegfortran)zg95 -c codegen.f90 -o codegen.oz1g95 -ffree-line-length-huge -c main.f90 -o main.oz g95 main.o codegen.o -o test.exeg95)z!ifort -c codegen.f90 -o codegen.ozifort -c main.f90 -o main.oz"ifort main.o codegen.o -o test.exeifort)r rrrr rr rr rctryttjd5}|D]8}t j ||dtj }|dk7s0dddy dddy#1swYyxYw)z>Run a series of commands and only return True if all ran fine.FwT)stdoutshellstderrrN)ropenosdevnull subprocesscallSTDOUT)commandsnullcommandretcodes g/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/external/tests/test_codegen.pytry_runr(tsr bjj# $ G oogd$%,,.G!|     s2A*A*A**A3cN|j}|tvsJ|tvsJtjddj }|dvr t dtjd|zd|z}tj}tj||rt||dd n t|d} | j|dd g} |D]j\} } } }| d d jd | Dd | d}|dk(rt|}tt!|}| j#t|||dzl|dk(rd}n"|j%drd}nt'd|zt)|j+t|ddj| izt-|}|r t-dg}nd}|dk(s |dk(rr|rp|rnd}|d|d|d|d|d|d|d|d tj|tj.|n3t1d!|zt2j4"tj||sJd#|d$d%j||sJd&|d'd%j|y())a|A driver for the codegen tests. This driver assumes that a compiler ifort is present in the PATH and that ifort is (at least) a Fortran 90 compiler. The generated code is written in a temporary directory, together with a main program that validates the generated code. The test passes when the compilation and the validation run correctly. SYMPY_TEST_CLEAN_TEMPalways)r+successneverzSSYMPY_TEST_CLEAN_TEMP must be one of the following: 'always', 'success' or 'never'.z_sympy_%s_testz%s_rT)to_files(,c32K|]}t|ywN)str).0args r' zrun_test..s73c#h7sz)-()r )r! thresholdzmain.f90Czmain.cz2FIXME: filename extension unknown for language: %s statementsz ./test.exeFr,cntjj|rtj|yyr2)rpathisfileremove)filenames r' safe_removezrun_test..safe_removes#ww~~h' (#(z codegen.f90z codegen.cz codegen.hz codegen.ozmain.oztest.exezTEST NOT REMOVED: %s)filezfailed to compile z code with:  zfailed to execute z code from: N)upper main_templatenumerical_test_templatergetenvlower ValueErrortempfilemkdtempgetcwdchdirrr writejoinfortranize_double_constantsr3append startswithNotImplementedErrorr write_textr(rmdirprintsysr)labelroutinesnumerical_testslanguager#friendlycleanworkoldworkcode_gen test_stringsfn_nameargsexpectedr8 call_stringf_namecompiledexecutedrAs r'run_testrjs~~H } $$ $ . .. . II-x 8 > > @E 22noo   ,x7 GDiikGHHTN (I=%h :xT:L.=  *x SXX7$77C u 5kBK3C NCI3H="A    5   S !! @8 KM M Lh<1F"GGIx HL>* Ui/H $ M"K K K JHHJ   $t+#**=  '$))H%''8 '$))H%''8rBcddljd}jd}fd}d}|j||}|j||}|S)z; Replaces every literal float with literal doubles rNz\d+(\.)?\d*[eE]-?\d+z\d+\.\d*(?!\d*d)cHjdd|jdS)Nz[eE]dr)subgroup)matchobjres r'subs_expz-fortranize_double_constants..subs_expsvvfc8>>!#455rBc*d|jdzS)Nz%sd0r)ro)rps r' subs_floatz/fortranize_double_constants..subs_floatsq)))rB)rqcompilern) code_string pattern_exp pattern_floatrrrtrqs @r'rQrQsZ**45KJJ23M6*//(K8K##J \}}dD]4}||j1t.|}|j3||f|df6@t4D]G\}}|j7drd|t.fd|t.fg}ng}t9d||z|||Iy)NrN)ln)log)coshsinhtanh)ceilingfloor)sqrt)acosasinatancossintan test_fabs test_acos test_asin test_atantest_cos test_coshtest_logtest_lntest_sin test_sinh test_sqrttest_tan test_tanh)皙??皙?+=r9 test_floor test_ceilintrinsic_math1)sympy.core.evalfrsympy.functionsr&sympy.functions.elementary.exponentialr%sympy.functions.elementary.hyperbolicrrr#sympy.functions.elementary.integersrr(sympy.functions.elementary.miscellaneousr(sympy.functions.elementary.trigonometricrrrrrrabsrsubsrRrrSrj)rrrrrrrrrrrrrrrrr[nameexprxvalrerr# name_expr_Cs r'test_intrinsic_math1_codegenr2sv"":HHD=ZZ c!f d1g d1g d1g SV d1g SV BqE SV d1g d1g SV d1gIOE d! ED1d+,H  " "D4'8U#C D EE.2h ??3 (%(3k71:5NOKK"I $; $ 2 2rBcTddlm}ddlm}d|tt fdtt zfg}g}|D]V\}}dD]L\}}||j t|j t |}|j|||f|dfNXtD]\} } td||| | y) Nrr)atan2 test_atan2test_pow))r?)r皙ɿ)rrrintrinsic_math2) rrrrrrrrRrrj) rrrr[rrryvalrerr#s r'test_instrinsic_math2_codegenrXs"> uQ{# QTIOJ d= JJD$1d+00D9:H  " "D4,%#H I JJ.Ph"IhOPrBcBddlm}ddlm}m}m}d|t |tz|tzdzjfd||||||||t tztzfg}g}|D]l\}}dD]b\}} } ||jt |jt| jt| } |j||| | f| dfdntD]\} } td ||| | y) Nrr)rrrtest1test2))rrg333333ӿ)rrg)rg@rg-q=complicated_codegen)rrrrrrrrrexpandrrRrrj)rrrrrr[rrrrzvalrerr#s r'test_complicated_codegenris "HH CFSVOc!f,q088:; #c#c#c#c!a%!)n*=&>"?@ABCDIOP d S P D$1d+00D9>>q$GHH  " "D4t*rso0.MM     e  e%U+ e" "9!?"      \'~( 08ND()H4"""D(#34%%tX&67 8; ; 8 ; 6N#2LP"OrB