
    Цi(:                         S SK r S SKrS SKrS SKJr  S SKJrJr  S SKJ	r	J
r
JrJrJr  S SKJrJrJrJr  S SKJr  S SKJr  SS jrS	 rS
 rS rS rS rS rS rS rS r S r!S r"S r#g)    N)StringIO)symbolsEq)autowrapbinary_functionCythonCodeWrapperUfuncifyCodeWrapperCodeWrapper)CCodeGen
C99CodeGenCodeGenArgumentListErrormake_routine)raises)TmpFileManagerc                 n    [        5       nU " XU40 UD6  UR                  5       nUR                  5         U$ )a  Wrapper for dump_fn. dump_fn writes its results to a stream object and
this wrapper returns the contents of that stream as a string. This
auxiliary function is used by many tests below.

The header and the empty lines are not generator to facilitate the
testing of the output.
)r   getvalueclose)dump_fnroutinesprefixkwargsoutputsources         b/var/www/html/ai-image-ml/venv/lib/python3.13/site-packages/sympy/utilities/tests/test_autowrap.py
get_stringr      s4     ZFHf//__F
LLNM    c                      [        S5      u  pnX-   U-  n[        SU5      n[        [        5       5      n[	        UR
                  U/5      nSnXg:X  d   eg )Nx,y,ztestzcdef extern from 'file.h':
    double test(double x, double y, double z)

def test_c(double x, double y, double z):

    return test(x, y, z))r   r   r   r   r   dump_pyx)xyzexprroutinecode_genr   expecteds           r   #test_cython_wrapper_scalar_functionr(   "   s_    gGA!E19D64(G ,H))G95F	#  r   c                      SSK Jn   [        S5      u  pn[        [	        5       5      n[        SU " X1U-   5      5      n[        UR                  U/5      nSnXg:X  d   eg )Nr   Equalityr   r   zcdef extern from 'file.h':
    void test(double x, double y, double *z)

def test_c(double x, double y):

    cdef double z = 0
    test(x, y, &z)
    return zsympy.core.relationalr+   r   r   r   r   r   r    r+   r!   r"   r#   r&   r%   r   r'   s           r   test_cython_wrapper_outargr/   3   s`    .gGA! .H68A1u#56G))G95F	  r   c                      SSK Jn   [        S5      u  pn[        [	        5       5      n[        SU " X1U-   U-   5      5      n[        UR                  U/5      nSnXg:X  d   eg )Nr   r*   r   r   zcdef extern from 'file.h':
    void test(double x, double y, double *z)

def test_c(double x, double y, double z):

    test(x, y, &z)
    return zr,   r.   s           r   test_cython_wrapper_inoutargr1   F   sd    .gGA! .H68A1uqy#9:G))G95F	  r   c                     SSK Jn   [        S5      u  pn[        SU " X1U-   5      5      n[	        [        5       5      nSS[        R                  0-  n[        R                  " 5       n[        R                  " U5        [        R                  R                  US5      nUR                  XGS9  [!        U5       n	U	R#                  5       n
S S S 5        W
U:X  d   e[	        [        5       S	S
/S/SS/S/SS/SSS00S9nSS[        R                  0-  nUR                  XGS9  [!        U5       n	U	R#                  5       n
S S S 5        X:X  d   eSS[        R                  0-  nSUl        UR                  XGS9  [!        U5       n	U	R#                  5       n
S S S 5        X:X  d   e[        R&                  " 5         g ! , (       d  f       N= f! , (       d  f       N= f! , (       d  f       NM= f)Nr   r*   r   r   a  from setuptools import setup
from setuptools import Extension
from Cython.Build import cythonize
cy_opts = {'compiler_directives': {'language_level': '3'}}

ext_mods = [Extension(
    'wrapper_module_%(num)s', ['wrapper_module_%(num)s.pyx', 'wrapped_code_%(num)s.c'],
    include_dirs=[],
    library_dirs=[],
    libraries=[],
    extra_compile_args=['-std=c99'],
    extra_link_args=[]
)]
setup(ext_modules=cythonize(ext_mods, **cy_opts))
numzsetup.py)	build_dirz/usr/local/includez/opt/booger/includez/user/local/libthelibnilibz
-slow-mathz-lswampz	-ltridentcompiler_directivesboundscheckF)include_dirslibrary_dirs	librariesextra_compile_argsextra_link_argscythonize_optionsa)  from setuptools import setup
from setuptools import Extension
from Cython.Build import cythonize
cy_opts = {'compiler_directives': {'boundscheck': False}}

ext_mods = [Extension(
    'wrapper_module_%(num)s', ['wrapper_module_%(num)s.pyx', 'wrapped_code_%(num)s.c'],
    include_dirs=['/usr/local/include', '/opt/booger/include'],
    library_dirs=['/user/local/lib'],
    libraries=['thelib', 'nilib'],
    extra_compile_args=['-slow-math', '-std=c99'],
    extra_link_args=['-lswamp', '-ltrident']
)]
setup(ext_modules=cythonize(ext_mods, **cy_opts))
aN  from setuptools import setup
from setuptools import Extension
from Cython.Build import cythonize
cy_opts = {'compiler_directives': {'boundscheck': False}}
import numpy as np

ext_mods = [Extension(
    'wrapper_module_%(num)s', ['wrapper_module_%(num)s.pyx', 'wrapped_code_%(num)s.c'],
    include_dirs=['/usr/local/include', '/opt/booger/include', np.get_include()],
    library_dirs=['/user/local/lib'],
    libraries=['thelib', 'nilib'],
    extra_compile_args=['-slow-math', '-std=c99'],
    extra_link_args=['-lswamp', '-ltrident']
)]
setup(ext_modules=cythonize(ext_mods, **cy_opts))
T)r-   r+   r   r   r   r   r
   _module_countertempfilemkdtempr   
tmp_folderospathjoin_prepare_filesopenread_need_numpycleanup)r+   r!   r"   r#   r%   r&   r'   temp_dirsetup_file_pathf
setup_texts              r   !test_cython_wrapper_compile_flagsrO   W   s   .gGA!68A1u#56G ,H k))*+H" !Hh'ggll8Z8OG8	o	!VVX
 
!!! /CEZ.[/@.A,4g+>5AN2;[1I4IM[`Ka3b#H k))*+H" G8	o	!VVX
 
!!!  k))*!+H$  HG8	o	!VVX
 
!!!u 
	< 
	0 
	s$   7F6*G G6
G
G
G&c                  ^   SSK Jn   SSKJn  U" S5      U" S5      U" S5      pCnX#U4 Vs/ s H  n[	        UR
                  5      PM     snu  pgnU " XBU-   5      n	[        SU	5      n
[        [        5       5      n[        UR                  U
/5      nSnUR                  XgUS	9nX:X  d   eg s  snf )
Nr   r*   )Dummyr!   r"   r#   r   zcdef extern from 'file.h':
    void test(double x_{x_id}, double y_{y_id}, double *z_{z_id})

def test_c(double x_{x_id}, double y_{y_id}):

    cdef double z_{z_id} = 0
    test(x_{x_id}, y_{y_id}, &z_{z_id})
    return z_{z_id})x_idy_idz_id)r-   r+   sympy.core.symbolrQ   strdummy_indexr   r   r   r   r    format)r+   rQ   r!   r"   r#   drR   rS   rT   r$   r%   r&   r   expected_templater'   s                  r   $test_cython_wrapper_unique_dummyvarsr[      s    .'Cj%*eCj!A561I>IqAMM*I>DA1uD64(G ,H))G95F	  !''T4'HH ?s   B*c                     [        S5      u  pn[        X-   SS9nU" 5       [        X-   5      :X  d   eUR                  S:X  d   eUR                  S:X  d   e[        [        X U-   5      SS9nU" 5       [        X-   5      :X  d   eUR                  S:X  d   eUR                  S:X  d   e[        [        X U-   U-   5      SS9nU" 5       [        X-   U-   5      :X  d   eUR                  S:X  d   eUR                  S:X  d   eg )Nx y zdummybackendzx, ynamelessr#   zx, y, z)r   r   rV   argsreturnsr   )r!   r"   r#   rM   s       r   test_autowrap_dummyrd      s    gGA! 	(A3#ae*66V99
"""A1uw/A3#ae*66V99A1uqy!73A3#aeai.   66Y99r   c                    ^^^ [        S5      u  mmm[        [        UUU4S j5        [        [	        TTT-   5      STT/S9n U " 5       [        TT-   5      :X  d   eU R                  S:X  d   eU R                  S:X  d   e[        [        UUU4S j5        [        [	        TTT-   T-   5      STTT/S9n U " 5       [        TT-   T-   5      :X  d   eU R                  S:X  d   eU R                  S:X  d   e[        [	        TTT-   T-   5      STTT4S9n U " 5       [        TT-   T-   5      :X  d   eU R                  S:X  d   eU R                  S:X  d   eg )	Nr]   c                  6   > [        [        TT T-   5      ST /S9$ Nr^   r`   rb   r   r   r!   r"   r#   s   r   <lambda>$test_autowrap_args.<locals>.<lambda>   s    XbAEl!.&r   r^   rh   zy, xr#   c                  >   > [        [        TT T-   T-   5      ST T/S9$ rg   ri   rj   s   r   rk   rl      s$    XbAEAI6F!Q.)r   zy, x, z)r   r   r   r   r   rV   rb   rc   )rM   r!   r"   r#   s    @@@r   test_autowrap_argsrn      sQ   gGAq!
# && 'Aq1uwaV<A3#a!e*66V99
# &) *Aq1uqy!7!QCA3#a!eai.   66Y99Aq1uqy!7!QCA3#a!eai.   66Y99r   c                  @   [        S5      u  p[        R                  " 5       n[        R                  " U5        [        X-   SUS9nU" 5       [        X-   5      :X  d   e[        R                  " U[        R                  5      (       d   e[        R                  " 5         g )Nx yr^   r`   tempdir)r   r@   rA   r   rB   r   rV   rC   accessF_OKrJ   )r!   r"   tmprM   s       r   test_autowrap_store_filesrv      sv    5>DA



Cc"5A3#ae*99S"''""""r   c                     [        S5      u  pSn[        R                  " 5       n[        R                  " 5       n [        R
                  " U5        [        X-   SUS9nU" 5       [        X-   5      :X  d   e[        R                  " U[        R                  5      (       d   e [        R
                  " U5        [        R                  " U5        g ! [        R
                  " U5        [        R                  " U5        f = f)Nrp   z./tmpr^   rq   )r   rC   getcwdr@   rA   chdirr   rV   rs   rt   shutilrmtree)r!   r"   ru   	saved_cwdtemp_cwdrM   s         r   'test_autowrap_store_files_issue_gh12939r~      s    5>DA
C		I!H 
QUGS9sc!%j   yybgg&&&&
h 	hs   A'C .C>c                  z    [        S5      u  p[        SX-   SS9nUR                  5       [        X-   5      :X  d   eg )Nrp   rM   r^   r_   )r   r   _imp_rV   )r!   r"   rM   s      r   test_binary_functionr     s7    5>DAQUG4A779AE
"""r   c                      [        S5      u  pn[        [        S5      5      n[        SX-   U-   5      n[	        UR
                  U/5      nSS[        R                  0-  nXV:X  d   eg )Nr   ufuncifyr   af	  #include "Python.h"
#include "math.h"
#include "numpy/ndarraytypes.h"
#include "numpy/ufuncobject.h"
#include "numpy/halffloat.h"
#include "file.h"

static PyMethodDef wrapper_module_%(num)sMethods[] = {
        {NULL, NULL, 0, NULL}
};

#ifdef NPY_1_19_API_VERSION
static void test_ufunc(char **args, const npy_intp *dimensions, const npy_intp* steps, void* data)
#else
static void test_ufunc(char **args, npy_intp *dimensions, npy_intp* steps, void* data)
#endif
{
    npy_intp i;
    npy_intp n = dimensions[0];
    char *in0 = args[0];
    char *in1 = args[1];
    char *in2 = args[2];
    char *out0 = args[3];
    npy_intp in0_step = steps[0];
    npy_intp in1_step = steps[1];
    npy_intp in2_step = steps[2];
    npy_intp out0_step = steps[3];
    for (i = 0; i < n; i++) {
        *((double *)out0) = test(*(double *)in0, *(double *)in1, *(double *)in2);
        in0 += in0_step;
        in1 += in1_step;
        in2 += in2_step;
        out0 += out0_step;
    }
}
PyUFuncGenericFunction test_funcs[1] = {&test_ufunc};
static char test_types[4] = {NPY_DOUBLE, NPY_DOUBLE, NPY_DOUBLE, NPY_DOUBLE};
static void *test_data[1] = {NULL};

#if PY_VERSION_HEX >= 0x03000000
static struct PyModuleDef moduledef = {
    PyModuleDef_HEAD_INIT,
    "wrapper_module_%(num)s",
    NULL,
    -1,
    wrapper_module_%(num)sMethods,
    NULL,
    NULL,
    NULL,
    NULL
};

PyMODINIT_FUNC PyInit_wrapper_module_%(num)s(void)
{
    PyObject *m, *d;
    PyObject *ufunc0;
    m = PyModule_Create(&moduledef);
    if (!m) {
        return NULL;
    }
    import_array();
    import_umath();
    d = PyModule_GetDict(m);
    ufunc0 = PyUFunc_FromFuncAndData(test_funcs, test_data, test_types, 1, 3, 1,
            PyUFunc_None, "wrapper_module_%(num)s", "Created in SymPy with Ufuncify", 0);
    PyDict_SetItemString(d, "test", ufunc0);
    Py_DECREF(ufunc0);
    return m;
}
#else
PyMODINIT_FUNC initwrapper_module_%(num)s(void)
{
    PyObject *m, *d;
    PyObject *ufunc0;
    m = Py_InitModule("wrapper_module_%(num)s", wrapper_module_%(num)sMethods);
    if (m == NULL) {
        return;
    }
    import_array();
    import_umath();
    d = PyModule_GetDict(m);
    ufunc0 = PyUFunc_FromFuncAndData(test_funcs, test_data, test_types, 1, 3, 1,
            PyUFunc_None, "wrapper_module_%(num)s", "Created in SymPy with Ufuncify", 0);
    PyDict_SetItemString(d, "test", ufunc0);
    Py_DECREF(ufunc0);
}
#endifr3   )r   r	   r   r   r   dump_cr
   r?   )r!   r"   r#   code_wrapperr%   r   r'   s          r   test_ufuncify_sourcer     st    gGA!&z*'=>L61519-G++gY7FW
n K//0oW1Hp r   c            
      z   [        S5      u  pnXU4nXS-  -   SUS-  -  -   n[        [        S5      5      n[        [	        U5      5       Vs/ s H0  n[        SR                  U5      UR                  X6   5      U5      PM2     nn[        UR                  USS9nS	S
[        R                  0-  n	X:X  d   eg s  snf )Nr      
      r   zfunc{}	multitest)funcnamea  #include "Python.h"
#include "math.h"
#include "numpy/ndarraytypes.h"
#include "numpy/ufuncobject.h"
#include "numpy/halffloat.h"
#include "file.h"

static PyMethodDef wrapper_module_%(num)sMethods[] = {
        {NULL, NULL, 0, NULL}
};

#ifdef NPY_1_19_API_VERSION
static void multitest_ufunc(char **args, const npy_intp *dimensions, const npy_intp* steps, void* data)
#else
static void multitest_ufunc(char **args, npy_intp *dimensions, npy_intp* steps, void* data)
#endif
{
    npy_intp i;
    npy_intp n = dimensions[0];
    char *in0 = args[0];
    char *in1 = args[1];
    char *in2 = args[2];
    char *out0 = args[3];
    char *out1 = args[4];
    char *out2 = args[5];
    npy_intp in0_step = steps[0];
    npy_intp in1_step = steps[1];
    npy_intp in2_step = steps[2];
    npy_intp out0_step = steps[3];
    npy_intp out1_step = steps[4];
    npy_intp out2_step = steps[5];
    for (i = 0; i < n; i++) {
        *((double *)out0) = func0(*(double *)in0, *(double *)in1, *(double *)in2);
        *((double *)out1) = func1(*(double *)in0, *(double *)in1, *(double *)in2);
        *((double *)out2) = func2(*(double *)in0, *(double *)in1, *(double *)in2);
        in0 += in0_step;
        in1 += in1_step;
        in2 += in2_step;
        out0 += out0_step;
        out1 += out1_step;
        out2 += out2_step;
    }
}
PyUFuncGenericFunction multitest_funcs[1] = {&multitest_ufunc};
static char multitest_types[6] = {NPY_DOUBLE, NPY_DOUBLE, NPY_DOUBLE, NPY_DOUBLE, NPY_DOUBLE, NPY_DOUBLE};
static void *multitest_data[1] = {NULL};

#if PY_VERSION_HEX >= 0x03000000
static struct PyModuleDef moduledef = {
    PyModuleDef_HEAD_INIT,
    "wrapper_module_%(num)s",
    NULL,
    -1,
    wrapper_module_%(num)sMethods,
    NULL,
    NULL,
    NULL,
    NULL
};

PyMODINIT_FUNC PyInit_wrapper_module_%(num)s(void)
{
    PyObject *m, *d;
    PyObject *ufunc0;
    m = PyModule_Create(&moduledef);
    if (!m) {
        return NULL;
    }
    import_array();
    import_umath();
    d = PyModule_GetDict(m);
    ufunc0 = PyUFunc_FromFuncAndData(multitest_funcs, multitest_data, multitest_types, 1, 3, 3,
            PyUFunc_None, "wrapper_module_%(num)s", "Created in SymPy with Ufuncify", 0);
    PyDict_SetItemString(d, "multitest", ufunc0);
    Py_DECREF(ufunc0);
    return m;
}
#else
PyMODINIT_FUNC initwrapper_module_%(num)s(void)
{
    PyObject *m, *d;
    PyObject *ufunc0;
    m = Py_InitModule("wrapper_module_%(num)s", wrapper_module_%(num)sMethods);
    if (m == NULL) {
        return;
    }
    import_array();
    import_umath();
    d = PyModule_GetDict(m);
    ufunc0 = PyUFunc_FromFuncAndData(multitest_funcs, multitest_data, multitest_types, 1, 3, 3,
            PyUFunc_None, "wrapper_module_%(num)s", "Created in SymPy with Ufuncify", 0);
    PyDict_SetItemString(d, "multitest", ufunc0);
    Py_DECREF(ufunc0);
}
#endifr3   )r   r	   r   rangelenr   rX   diffr   r   r
   r?   )
r!   r"   r#   var_symbolsr$   r   ir   r   r'   s
             r    test_ufuncify_source_multioutputr   n  s    gGA!)K!t8bAgD&z*'=>Lbghklwhxbyzby]^X__Q/;>1JKXbyHz++XLF_
~ K//0_1H@ E {s   7B8)file)$rC   r@   rz   ior   
sympy.corer   r   sympy.utilities.autowrapr   r   r   r	   r
   sympy.utilities.codegenr   r   r   r   sympy.testing.pytestr   sympy.testing.tmpfilesr   r   r(   r/   r1   rO   r[   rd   rn   rv   r~   r   r   r    r   r   <module>r      sz    
    "A A  ( 1"&"Wr*&,	 #]@gr   