o
    jg&                  
   @   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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rpz
eeddd W n eeefym   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.d/ Z.d0d1 Z/d2d3 Z0d4d5 Z1d6d7 Z2d8d9 Z3d:d; Z4d<d= Z5d>d? Z6d@dA Z7dBdC Z8dDdE Z9dFdG Z:dHdI Z;dJdK Z<dLdM Z=dS )N    N)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   Z/var/www/html/zoom/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_twice6   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   r3   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   r0   r   r   r   randomranddotsumabs)r*   r+   r   yexprmvMr   r   r    runtest_autowrap_matrix_vectorE   s   &r@   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   r4   r5      r6   )r!   r   Cr   r   r0   r   Br   r   r7   r8   r9   r:   r;   )r*   r+   r=   matmatM1M2M3r   r   r    runtest_autowrap_matrix_matrixR   s   &&rH   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   rT   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 rI   zP *                                                                            *
zP *              See http://www.sympy.org/ for more information.               *
zP *                      This file is part of 'autowrap'                       *
zQ ******************************************************************************/
z
#include "rL   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_10274k   sR   

rk   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, erU   g    S8Af1)argsrX   r$   rI      r#   r"   f2)r!   r   r   r   rN   rO   )
r*   r+   r&   r'   r(   der=   exp_resr,   r   r   r    runtest_issue_15337   s   "rs   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)rm   r*   g      @g@g+=Tr   rn   r%   rI   )r!   r   r   r   floatxreplaceevalfr;   )r   r<   r=   r,   rr   r   r   r    test_issue_15230   s   $rx   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   ry   rz   r!   r3   r   r   r   r    test_autowrap_trace_f95_f2py   r}   r   c                   C   ry   rz   r!   r@   r   r   r   r    $test_autowrap_matrix_vector_f95_f2py   r}   r   c                   C   ry   rz   r!   rH   r   r   r   r    $test_autowrap_matrix_matrix_f95_f2py   r}   r   c                   C   ry   rz   r!   rT   r   r   r   r    test_ufuncify_f95_f2py   r}   r   c                   C   ry   rz   r!   rs   r   r   r   r    test_issue_15337_f95_f2py   r}   r   c                   C      t d tdd d S )Nr   rB   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!   rk   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   sV  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}	|	d W d    n1 sPw   Y  t|d||d}
|
ddkseJ t|D ]>}|dr|drttj||!}	|	 }||dd }d|dd  |ksJ W d    n1 sw   Y  qjd 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.hwz#define S_PI 3.14r   )r+   rW   code_geng@gK7A`*@wrapped_coderZ   z.h    )r!   sympy.core.numbersr   sympy.utilities.codegenr   sympy.printing.cr   preprocessor_statementsappendr&   r]   r^   rc   r_   pathjoinwriter   r`   ra   rb   rd   replace)r   r   r   r   r   genr=   rS   tmpdirr,   funcfilenamerj   r   r   r    test_autowrap_custom_printer  s4   
r   c                   C   r   )Nr   r   r   r   r   r   r   r    test_ufuncify_numpy5  s   r   )>re   r]   r_   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mrp   r0   rC   rB   r   r   r   r!   r.   r3   r@   rH   rT   rk   rs   rx   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    <module>   sf    


	*3