o
    §ƒðj&  ã                
   @   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    ú¤/tmp/claude-1000/-var-www-html-academy/3f42efd1-c2b7-4d08-9b05-30d86bb35479/scratchpad/piper/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s†J ‚W d   ƒ n1 s�w   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¡r•ttj ||
¡ƒ�!}| ¡ }||
 dd¡ }d |dd … ¡|ks†J ‚W d   ƒ n1 s�w   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ÍÌÌÌÌÌ@gÇK7‰A`*@Ú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