o
    GZh&                  
   @   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)Zmin_module_versionCythonz0.15.1z
numpy.f2pyfromlistf2py)Z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   Q/var/www/auris/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   r2   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   r/   r   r	   r   randomranddotsumabs)r)   r*   r   yexprmvMr   r   r   runtest_autowrap_matrix_vectorF   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   r3   r4      r5   )r    r   Cr   r   r/   r   Br	   r   r6   r7   r8   r9   r:   )r)   r*   r<   ZmatmatZM1ZM2ZM3r   r   r   runtest_autowrap_matrix_matrixS   s   &&rC   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   Zlinspacetestingassert_allclose)	r)   r*   r%   r&   r'   ZfabcZfacbgridexpectedr   r   r   runtest_ufuncify_   s   rL   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#   Zwrapped_code_.c/r   zP/******************************************************************************
zCode generated with SymPy rD   zP *                                                                            *
zP *              See http://www.sympy.org/ for more information.               *
zP *                      This file is part of 'autowrap'                       *
zQ ******************************************************************************/
z
#include "rG   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+   fileZfillinesr   r   r   runtest_issue_10274l   sR   

ra   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, erM   g    S8Af1)argsrP   r#   rD      r"   r!   f2)r    r   r	   r   rH   rI   )
r)   r*   r%   r&   r'   der<   exp_resr+   r   r   r   runtest_issue_15337   s   "ri   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       ZF95)rc   r)   g      @g@g+=Tr   rd   r$   rD   )r    r   r   r	   floatZxreplaceZevalfr:   )r   r;   r<   r+   rh   r   r   r   test_issue_15230   s   $rk   c                   C      t d tdd d S Nr   r   r    r-   r   r   r   r   test_wrap_twice_f95_f2py      ro   c                   C   rl   rm   r    r2   r   r   r   r   test_autowrap_trace_f95_f2py   rp   rr   c                   C   rl   rm   r    r?   r   r   r   r   $test_autowrap_matrix_vector_f95_f2py   rp   rt   c                   C   rl   rm   r    rC   r   r   r   r   $test_autowrap_matrix_matrix_f95_f2py   rp   rv   c                   C   rl   rm   r    rL   r   r   r   r   test_ufuncify_f95_f2py   rp   rx   c                   C   rl   rm   r    ri   r   r   r   r   test_issue_15337_f95_f2py   rp   rz   c                   C      t d tdd d S )Nr   rA   cythonrn   r   r   r   r   test_wrap_twice_c_cython   rp   r}   c                   C   r{   Nr   C99r|   rq   r   r   r   r   test_autowrap_trace_C_Cython   rp   r   c                   C   r{   r~   rs   r   r   r   r   $test_autowrap_matrix_vector_C_cython   rp   r   c                   C   r{   r~   ru   r   r   r   r   $test_autowrap_matrix_matrix_C_cython   rp   r   c                   C   r{   r~   rw   r   r   r   r   test_ufuncify_C_Cython   rp   r   c                   C   r{   Nr   ZC89r|   )r    ra   r   r   r   r   test_issue_10274_C_cython   rp   r   c                   C   r{   r   ry   r   r   r   r   test_issue_15337_C_cython   rp   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 )NZ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*   rO   Zcode_geng@gK7A`*@Zwrapped_coderQ   z.h    )r    Zsympy.core.numbersr   Zsympy.utilities.codegenr   Zsympy.printing.cr   Zpreprocessor_statementsappendr%   rT   rU   r   rV   pathjoin
write_textr	   rW   rX   rY   rZ   r[   replace)r   r   r   r   r   genr<   rK   Ztmpdirfuncfilenamer+   r`   r   r   r   test_autowrap_custom_printer  s0   
r   c                   C   r{   )Nr   r   r   rw   r   r   r   r   test_ufuncify_numpy5  s   r   )@r\   rT   rV   pathlibr   Zsympy.core.modr   Zsympy.core.relationalr   Zsympy.core.symbolr   Zsympy.externalr   Zsympy.tensorr   r   Zsympy.utilities.autowrapr	   r
   r   Zsympy.testing.pytestr   r   r   r   r   ImportErrorOSErrorr%   r&   r'   nmrf   r/   rB   rA   r   r   r   r    r-   r2   r?   rC   rL   ra   ri   rk   ro   rr   rt   rv   rx   rz   r}   r   r   r   r   r   r   r   r   r   r   r   r   <module>   sh    


	*2