
    \h61                        S SK JrJrJr  S SKJrJr  S SKJrJ	r	J
r
  S SKrS SKrS SKrS SKrS SKJr  0 rS\S'   S\S	'   \S	   \S
'   0 rS\S	'   \S	   \S
'   S\S'   0 r/ SQ\S'   / SQ\S'   / SQ\S'   / SQ\S'   / SQrS rS#S jrS rS r/ r/ r\ HA  u  rr\\   r\" \\5      (       a  \R=                  \\45        M.  \R=                  \\45        MC     S rS r S r!S r"S r#S r$S  r%S! r&S" r'g)$    )xyz)IS_WASMskip)codegenmake_routineget_code_generatorN)Pathzy
program main
  include "codegen.h"
  integer :: result;
  result = 0

  %(statements)s

  call exit(result)
end program
F95z
#include "codegen.h"
#include <stdio.h>
#include <math.h>

int main() {
  int result = 0;

  %(statements)s

  return result;
}
C89C99z
  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
)zcc -c codegen.c -o codegen.ozcc -c main.c -o main.oz#cc main.o codegen.o -lm -o test.execc)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.exegfortran)zg95 -c codegen.f90 -o codegen.oz1g95 -ffree-line-length-huge -c main.f90 -o main.oz g95 main.o codegen.o -o test.exeg95)z!ifort -c codegen.f90 -o codegen.ozifort -c main.f90 -o main.oz"ifort main.o codegen.o -o test.exeifort)r   r   r   r   r   r   r   r   r   r   c           	          [         (       a  g[        [        R                  S5       nU  H7  n[        R
                  " X!S[        R                  S9nUS:w  d  M/    SSS5        g   SSS5        g! , (       d  f       g= f)z>Run a series of commands and only return True if all ran fine.FwT)stdoutshellstderrr   N)r   openosdevnull
subprocesscallSTDOUT)commandsnullcommandretcodes       Y/var/www/auris/envauris/lib/python3.13/site-packages/sympy/external/tests/test_codegen.pytry_runr(   t   sg    w	bjj#	$G oog$%,,.G!| 
	 
  
	 s   .A.A.#A..
A<c                    UR                  5       nU[        ;   d   eU[        ;   d   e[        R                  " SS5      R                  5       nUS;  a  [        S5      e[        R                  " SU-  SU -  5      n[        R                  " 5       n[        R                  " U5        U(       a  [        XSSS	9  O[        US5      n	U	R                  USSS	9  / n
U Hm  u  ppU< S
SR                  S U 5       5      < SU< S3nUS:X  a  [        U5      n[        [!        U5      5      nU
R#                  [        U   UUS.-  5        Mo     US:X  a  SnO'UR%                  S5      (       a  SnO['        SU-  5      e[)        U5      R+                  [        U   SSR                  U
5      0-  5        [-        U5      nU(       a  [-        S/5      nOSnUS:X  d  US:X  a~  U(       aw  U(       ap  S nU" S5        U" S5        U" S5        U" S5        U" S5        U" S5        U" S5        U" S 5        [        R                  " U5        [        R.                  " U5        O1[1        S!U-  [2        R4                  S"9  [        R                  " U5        U(       d   S#U< S$S%R                  U5      < 35       eU(       d   S&U< S'S%R                  U5      < 35       eg())aU  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_TEMPalways)r+   successneverzSSYMPY_TEST_CLEAN_TEMP must be one of the following: 'always', 'success' or 'never'.z_sympy_%s_testz%s_r   T)to_files(,c              3   8   #    U  H  n[        U5      v   M     g 7fN)str).0args     r'   	<genexpr>run_test.<locals>.<genexpr>   s     7$3c#hh$s   z)-()r   )r!   	thresholdzmain.f90Czmain.cz2FIXME: filename extension unknown for language: %s
statements z
./test.exeFr,   c                 z    [         R                  R                  U 5      (       a  [         R                  " U 5        g g r2   )r   pathisfileremove)filenames    r'   safe_removerun_test.<locals>.safe_remove   s&    ww~~h''		(# (    zcodegen.f90z	codegen.cz	codegen.hz	codegen.ozmain.oztest.exezTEST NOT REMOVED: %s)filezfailed to compile z code with:

zfailed to execute z code from:
N)uppermain_templatenumerical_test_templater   getenvlower
ValueErrortempfilemkdtempgetcwdchdirr   r
   writejoinfortranize_double_constantsr3   append
startswithNotImplementedErrorr   
write_textr(   rmdirprintsysr   )labelroutinesnumerical_testslanguager#   friendlycleanworkoldworkcode_gentest_stringsfn_nameargsexpectedr9   call_stringf_namecompiledexecutedrB   s                       r'   run_testrl      s    ~~H}$$$.... II-x8>>@E22noo ,x7GDiikGHHTN  	I=%h	:xT: L.=*xSXX7$77Cu5kBK3C	NCI3H="A
 
 	 /> 5			S	!	!!@8KM 	M 	Lh<1F"GGI x H L>* Ui/H	$ 	M"K K K JHHJ

$t+#**=
  '$))H%' '8 '$))H%' '8rD   c                    ^ SSK mTR                  S5      nTR                  S5      nU4S jnS nUR                  X05      n UR                  X@5      n U $ )z3
Replaces every literal float with literal doubles
r   Nz\d+(\.)?\d*[eE]-?\d+z\d+\.\d*(?!\d*d)c                 H   > TR                  SSU R                  S5      5      $ )Nz[eE]dr   )subgroup)matchobjres    r'   subs_exp-fortranize_double_constants.<locals>.subs_exp   s    vvfc8>>!#455rD   c                 *    SU R                  S5      -  $ )Nz%sd0r   )rq   )rr   s    r'   
subs_float/fortranize_double_constants.<locals>.subs_float   s    q)))rD   )rs   compilerp   )code_stringpattern_exppattern_floatrt   rw   rs   s        @r'   rS   rS      sV     **45KJJ23M6* //(8K##J<KrD   c           	      j    [        S[        5      nSS/n [        SU/X0USS9  g! [         a     gf = f)Ntest)r~   )      ?r   V瞯<)r~   )      r   r   is_feasibleF)r_   T)r	   r   rl   AssertionError)r^   r#   routiner]   s       r'   r   r      sJ    61%G%&O	?h	! s   % 
22c                  0    S[         ;   a  [        S5        g g )Nr   z*`cc' command didn't work as expected (C89)invalid_lang_compilersr    rD   r'   test_C89_ccr         ..9: /rD   c                  0    S[         ;   a  [        S5        g g )Nr   z*`cc' command didn't work as expected (C99)r   r   rD   r'   test_C99_ccr     r   rD   c                  0    S[         ;   a  [        S5        g g )Nr   z'`ifort' command didn't work as expectedr   r   rD   r'   test_F95_ifortr     s    1167 2rD   c                  0    S[         ;   a  [        S5        g g )Nr   z*`gfortran' command didn't work as expectedr   r   rD   r'   test_F95_gfortranr     s    449: 5rD   c                  0    S[         ;   a  [        S5        g g )Nr   z%`g95' command didn't work as expectedr   r   rD   r'   test_F95_g95r   !  s    //45 0rD   c                  r    SS/n S[         [        -   [        -  4/n[         H  u  p#[	        SXX#5        M     g )N)r~   )r   g      @g      @g      5@r   )r~   )r   g       @      r   r   r~   basic_codegen)r   r   r   valid_lang_commandsrl   )r]   	name_exprlangr#   s       r'   test_basic_codegenr   (  s>    .0O 1q5!)$%I-)dM .rD   c                     SSK Jn   SSKJn  SSKJn  SSKJnJnJ	n  SSK
JnJn  SSKJn  SSKJn	Jn
JnJnJnJn  S	[-        [.        5      4S
U	" [.        5      4SU
" [.        5      4SU" [.        5      4SU" [.        5      4SU" [.        5      4SU" [.        5      4SU" [.        5      4SU" [.        5      4SU" [.        5      4SU" [.        5      4SU" [.        5      4SU" [.        5      4/n/ nU HA  u  nnS H5  nU " UR1                  [.        U5      5      nUR3                  UU4US45        M7     MC     [4         HM  u  nnUR7                  S5      (       a  SU" [.        5      4SU" [.        5      4/nO/ n[9        SUU-   UUU5        MO     g )Nr   N)ln)log)coshsinhtanh)ceilingfloor)sqrt)acosasinatancossintan	test_fabs	test_acos	test_asin	test_atantest_cos	test_coshtest_logtest_lntest_sin	test_sinh	test_sqrttest_tan	test_tanh)皙?      ?皙?+=r:   
test_floor	test_ceilintrinsic_math1)sympy.core.evalfr   sympy.functionsr   &sympy.functions.elementary.exponentialr   %sympy.functions.elementary.hyperbolicr   r   r   #sympy.functions.elementary.integersr   r   (sympy.functions.elementary.miscellaneousr   (sympy.functions.elementary.trigonometricr   r   r   r   r   r   absr   subsrT   r   rU   rl   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r]   nameexprxvalrg   r   r#   name_expr_Cs                           r'   test_intrinsic_math1_codegenr   2  sf   "":HHD=ZZ	c!f	d1g	d1g	d1g	SV	d1g	SV	BqE	SV	d1g	d1g	SV	d1gI O
d!D1d+,H""D4'8U#CD "   .h??3(%(3k71:5NOKK"I$; $	2 .rD   c                  T   SSK Jn   SSKJn  SU" [        [
        5      4S[        [
        -  4/n/ nU HV  u  pES HK  u  pgU " UR                  [        U5      R                  [
        U5      5      nUR                  XFU4US45        MM     MX     [         H  u  p[        SX#X5        M     g )	Nr   r   )atan2
test_atan2test_pow))r   ?)r   皙ɿ)r   r   r   intrinsic_math2)
r   r   r   r   r   r   r   rT   r   rl   )r   r   r   r]   r   r   r   yvalrg   r   r#   s              r'   test_instrinsic_math2_codegenr   X  s    ">	uQ{#	QTI O
=JD1d+00D9:H""D,%#HI >   ."IO .rD   c                  @   SSK Jn   SSKJnJnJn  SU" [        5      U" [        5      -   U" [        5      -   S-  R                  5       4SU" U" U" U" U" U" U" U" [        [        -   [        -   5      5      5      5      5      5      5      5      4/n/ nU Hk  u  pgS H`  u  pn
U " UR                  [        U5      R                  [        U	5      R                  [        U
5      5      nUR                  XhX4US45        Mb     Mm     [         H  u  p[        S	XEX5        M     g )
Nr   r   )r   r   r   test1   test2))r   r   g333333ӿ)r   r   g        )r   g @r   g-q=complicated_codegen)r   r   r   r   r   r   r   r   r   expandr   rT   r   rl   )r   r   r   r   r   r]   r   r   r   r   zvalrg   r   r#   s                 r'   test_complicated_codegenr   i  s    "HH	CFSVOc!f,q088:;	#c#c#c#c!a%!)n*=&>"?@ABCDI O
 SD1d+00D9>>q$GHH""D*<h#NO !T   .!9t	O .rD   )T)(	sympy.abcr   r   r   sympy.testing.pytestr   r   sympy.utilities.codegenr   r	   r
   rZ   r   rM   r    pathlibr   rH   rI   compile_commandscombinations_lang_compilerr(   rl   rS   r   r   r   r   compilerr#   rT   r   r   r   r   r   r   r   r   r   r   rD   r'   <module>r      sm  0   . M M 
 	   
 
e e  %U+e   "   "9!?  "              
\'~(   0ND()H4""""D(#34%%tX&67 1;
;
8
;
6N#2LP"OrD   