o
    3Ih&                  
   @   s   d dl Z d dlZd dl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 d dlmZmZ d dlmZmZmZ d d	lmZ ed
ddZedddZedddgidZdZervz
ee
ddd W n eeefys   dZY nw dZe
d\ZZZe
ddd\ZZ Z!e
ded\Z"Z#Z$ede Z%edeZ&ede!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/d0 Z0d1d2 Z1d3d4 Z2d5d6 Z3d7d8 Z4d9d: Z5d;d< Z6d=d> Z7d?d@ Z8dAdB Z9dCdD Z:dEdF Z;dGdH Z<dIdJ Z=dKdL Z>dMdN Z?dS )O    N)Path)Mod)Eq)symbols)import_module)IndexedBaseIdx)autowrapufuncifyCodeWrapError)skipnumpyz1.6.1)min_module_versionCythonz0.15.1z
numpy.f2pyfromlistf2py)import_kwargsFxf95Ta b czn m dintegerzA B Cclsijkc                 C   s<   t ttd}||  r| dkrtstd dS td|   dS )z]
    Return True if module exists, otherwise run skip().

    module should be a string.
    )r   r   r   r   zCouldn't run f2py.TzCouldn't import %s.N)r   r   r   	f2pyworksr   )modulemodnames r    b/home/air/sanwanet/gpt-api/venv/lib/python3.10/site-packages/sympy/external/tests/test_autowrap.py
has_module"   s   	r"   c                 C   sd   t tt t d  | |}t tt t d  | |}|ddddks&J |ddddks0J d S )N         g      g      ?)r	   abcexpand)languagebackendfgr    r    r!   runtest_autowrap_twice7   s   r/   c                 C   s6   t d ttttf | |}|tddksJ d S )Nr   d   )r"   r	   Ar   r   eye)r+   r,   tracer    r    r!   runtest_autowrap_trace@   s   r4   c                 C   s   t d tdtd\}}t|t tttf |t  }t|| |}tj	
dd}tj	
d}t||}tt|||| dk sEJ d S )Nr   zx yr   
      vIh%<=)r"   r   r   r   r   r1   r   r	   r   randomranddotsumabs)r+   r,   r   yexprmvMr    r    r!   runtest_autowrap_matrix_vectorF   s   &rA   c                 C   s   t d ttttf tttf tttf  }t|| |}t	j
dd}t	j
dd}t	||}t	t	|||| dk sBJ d S )Nr   r5   r6      r7   )r"   r   Cr   r   r1   r   Br	   r   r8   r9   r:   r;   r<   )r+   r,   r>   matmatM1M2M3r    r    r!   runtest_autowrap_matrix_matrixS   s   &&rI   c           	      C   s   t d td\}}}t|||g|| | |d}t|||g|| | |d}tddd}tddd}td	d
d}|| | }tj||||| tj||||| d S )Nr   r   )r,   r&      2   r$   r%   )r"   r   r
   r   linspacetestingassert_allclose)	r+   r,   r'   r(   r)   fabcfacbgridexpectedr    r    r!   runtest_ufuncify_   s   rU   c                 C   s0  t t t d }t }t|| ||dt t t t ttffd}|ddddks)J t|D ]g}|dr:|	ds;q.t
|d | J}| }|d d	ksPJ d
tj |d v s[J |dd  dddddd|d d  d d dddddddddddddddddgksJ W d    n1 sw   Y  q.d S )N   helper)tempdirhelpersr%   wrapped_code_.c/r   zP/******************************************************************************
zCode generated with SymPy rJ   zP *                                                                            *
zP *              See http://www.sympy.org/ for more information.               *
zP *                      This file is part of 'autowrap'                       *
zQ ******************************************************************************/
z
#include "rM   zh"
z#include <math.h>
z.double helper(double a, double b, double c) {
z   double helper_result;
z   helper_result = a - b + c;
z   return helper_result;
z}
z0double autofunc(double a, double b, double c) {
z   double autofunc_result;
z/   autofunc_result = pow(helper(a, b, c), 13);
z   return autofunc_result;
)r'   r(   r)   tempfilemkdtempr	   oslistdir
startswithendswithopen	readlinessympy__version__)r+   r,   r>   tmpr-   filefillinesr    r    r!   runtest_issue_10274l   sR   

rl   c           
   
   C   s   t d td\}}}}}|| | | | d }d}t|| ||||||fd|| | |||ffd}	tj|	ddd	d
d| t|| ||||||fd|| ||ffd|| ||fffd}	tj|	ddd	d
d| d S )Nr   za, b, c, d, erV   g    S8Af1)argsrY   r%   rJ      r$   r#   f2)r"   r   r	   r   rO   rP   )
r+   r,   r'   r(   r)   der>   exp_resr-   r    r    r!   runtest_issue_15337   s   "rt   c                  C   s   t d td\} }t| dt|d }t|| |gdd}t|| d|di }t|dd| d	k s7J tdd
d\} }t| dt|d }t|| |gdd}|dd|| d|diksbJ d S )Nr   zx, yg      @g       F95)rn   r+   g      @g@g+=Tr   ro   r&   rJ   )r"   r   r   r	   floatxreplaceevalfr<   )r   r=   r>   r-   rs   r    r    r!   test_issue_15230   s   $ry   c                   C      t d tdd d S Nr   r   r"   r/   r    r    r    r!   test_wrap_twice_f95_f2py      r}   c                   C   rz   r{   r"   r4   r    r    r    r!   test_autowrap_trace_f95_f2py   r~   r   c                   C   rz   r{   r"   rA   r    r    r    r!   $test_autowrap_matrix_vector_f95_f2py   r~   r   c                   C   rz   r{   r"   rI   r    r    r    r!   $test_autowrap_matrix_matrix_f95_f2py   r~   r   c                   C   rz   r{   r"   rU   r    r    r    r!   test_ufuncify_f95_f2py   r~   r   c                   C   rz   r{   r"   rt   r    r    r    r!   test_issue_15337_f95_f2py   r~   r   c                   C      t d tdd d S )Nr   rC   cythonr|   r    r    r    r!   test_wrap_twice_c_cython   r~   r   c                   C   r   Nr   C99r   r   r    r    r    r!   test_autowrap_trace_C_Cython   r~   r   c                   C   r   r   r   r    r    r    r!   $test_autowrap_matrix_vector_C_cython   r~   r   c                   C   r   r   r   r    r    r    r!   $test_autowrap_matrix_matrix_C_cython   r~   r   c                   C   r   r   r   r    r    r    r!   test_ufuncify_C_Cython   r~   r   c                   C   r   Nr   C89r   )r"   rl   r    r    r    r!   test_issue_10274_C_cython   r~   r   c                   C   r   r   r   r    r    r    r!   test_issue_15337_C_cython   r~   r   c               	   C   s0  t d ddlm}  ddlm} ddlm} G dd d|}| }||d}|jd	 | t	 }d
}t
 }ttj|dd t|d||d}	|	ddksRJ t|D ]>}
|
dr|
drttj||
!}| }||
dd }d|dd  |ksJ W d    n1 sw   Y  qWd S )Nr   r   )pi)
C99CodeGen)C99CodePrinterc                   @   s   e Zd Zdd ZdS )z/test_autowrap_custom_printer.<locals>.PiPrinterc                 S   s   dS )NS_PIr    )selfr>   r    r    r!   	_print_Pi  s   z9test_autowrap_custom_printer.<locals>.PiPrinter._print_PiN)__name__
__module____qualname__r   r    r    r    r!   	PiPrinter
  s    r   )printerz#include "shortpi.h"z#include "%s"
#include <math.h>
#include "shortpi.h"

double autofunc(double a) {

   double autofunc_result;
   autofunc_result = S_PI*a;
   return autofunc_result;

}
z	shortpi.hz#define S_PI 3.14r   )r,   rX   code_geng@gK7A`*@wrapped_coder[   z.h    )r"   sympy.core.numbersr   sympy.utilities.codegenr   sympy.printing.cr   preprocessor_statementsappendr'   r^   r_   r   r`   pathjoin
write_textr	   ra   rb   rc   rd   re   replace)r   r   r   r   r   genr>   rT   tmpdirfuncfilenamer-   rk   r    r    r!   test_autowrap_custom_printer  s0   
r   c                   C   r   )Nr   r   r   r   r    r    r    r!   test_ufuncify_numpy5  s   r   )@rf   r^   r`   pathlibr   sympy.core.modr   sympy.core.relationalr   sympy.core.symbolr   sympy.externalr   sympy.tensorr   r   sympy.utilities.autowrapr	   r
   r   sympy.testing.pytestr   r   r   r   r   ImportErrorOSErrorr'   r(   r)   nmrq   r1   rD   rC   r   r   r   r"   r/   r4   rA   rI   rU   rl   rt   ry   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r    r    r!   <module>   sh    


	*2