ó
¡¼™\c           @   s0  d  d l  Z  d  d l Z d  d l Z d  d l m Z m Z d  d l m Z d  d l m	 Z	 m
 Z
 m Z m Z m Z d  d l m Z m Z m Z m Z d  d l m Z d  d l m Z d d	 „ Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z  d „  Z! d „  Z" d „  Z# d S(   iÿÿÿÿN(   t   symbolst   Eq(   t   StringIO(   t   autowrapt   binary_functiont   CythonCodeWrappert   UfuncifyCodeWrappert   CodeWrapper(   t   CCodeGent
   C99CodeGent   CodeGenArgumentListErrort   make_routine(   t   raises(   t   TmpFileManagert   filec         K   s6   t  ƒ  } |  | | | |  | j ƒ  } | j ƒ  | S(   s5  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   t   getvaluet   close(   t   dump_fnt   routinest   prefixt   kwargst   outputt   source(    (    sB   lib/python2.7/site-packages/sympy/utilities/tests/test_autowrap.pyt
   get_string   s
    	
c          C   sr   t  d ƒ \ }  } } |  | | } t d | ƒ } t t ƒ  ƒ } t | j | g ƒ } d } | | k sn t ‚ d  S(   Ns   x,y,zt   tests   cdef 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   t   dump_pyxt   AssertionError(   t   xt   yt   zt   exprt   routinet   code_genR   t   expected(    (    sB   lib/python2.7/site-packages/sympy/utilities/tests/test_autowrap.pyt#   test_cython_wrapper_scalar_function"   s    c          C   s   d d l  m }  t d ƒ \ } } } t t ƒ  ƒ } t d |  | | | ƒ ƒ } t | j | g ƒ } d } | | k s} t ‚ d  S(   Niÿÿÿÿ(   t   Equalitys   x,y,zR   sŸ   cdef 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(	   t   sympyR#   R    R   R	   R   R   R   R   (   R#   R   R   R   R    R   R   R!   (    (    sB   lib/python2.7/site-packages/sympy/utilities/tests/test_autowrap.pyt   test_cython_wrapper_outarg3   s    c          C   s…   d d l  m }  t d ƒ \ } } } t t ƒ  ƒ } t d |  | | | | ƒ ƒ } t | j | g ƒ } d } | | k s t ‚ d  S(   Niÿÿÿÿ(   R#   s   x,y,zR   s“   cdef 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 z(	   R$   R#   R    R   R	   R   R   R   R   (   R#   R   R   R   R    R   R   R!   (    (    sB   lib/python2.7/site-packages/sympy/utilities/tests/test_autowrap.pyt   test_cython_wrapper_inoutargF   s     c          C   sü  d d l  m }  t d ƒ \ } } } t d |  | | | ƒ ƒ } t t ƒ  ƒ } d i t j d 6} t j	 ƒ  } t
 j | ƒ t j j | d ƒ } | j | d | ƒt | ƒ  }	 |	 j ƒ  }
 Wd  QX|
 | k sØ t ‚ t t ƒ  d	 d
 d g d d g d d d g d d g d d d g d i i t d 6d 6ƒ} d i t j d 6} | j | d | ƒt | ƒ  }	 |	 j ƒ  }
 Wd  QX|
 | k s‹t ‚ d i t j d 6} t | _ | j | d | ƒt | ƒ  }	 |	 j ƒ  }
 Wd  QX|
 | k sît ‚ t
 j ƒ  d  S(   Niÿÿÿÿ(   R#   s   x,y,zR   sÿ  try:
    from setuptools import setup
    from setuptools import Extension
except ImportError:
    from distutils.core import setup
    from distutils.extension import Extension
from Cython.Build import cythonize
cy_opts = {}

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))
t   nums   setup.pyt	   build_dirt   include_dirss   /usr/local/includes   /opt/booger/includet   library_dirss   /user/local/libt	   librariest   thelibt   nilibt   extra_compile_argss
   -slow-matht   extra_link_argss   -lswamps	   -ltridentt   cythonize_optionst   boundscheckt   compiler_directivess  try:
    from setuptools import setup
    from setuptools import Extension
except ImportError:
    from distutils.core import setup
    from distutils.extension 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))
sÂ  try:
    from setuptools import setup
    from setuptools import Extension
except ImportError:
    from distutils.core import setup
    from distutils.extension 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))
(   R$   R#   R    R   R   R   R   t   _module_countert   tempfilet   mkdtempR   t
   tmp_foldert   ost   patht   joint   _prepare_filest   opent   readR   t   Falset   Truet   _need_numpyt   cleanup(   R#   R   R   R   R   R    R!   t   temp_dirt   setup_file_patht   ft
   setup_text(    (    sB   lib/python2.7/site-packages/sympy/utilities/tests/test_autowrap.pyt!   test_cython_wrapper_compile_flagsW   s>    			c          C   sð   d d l  m }  m } |  d ƒ |  d ƒ |  d ƒ } } } g  | | | g D] } t | j ƒ ^ qL \ } } } | | | | ƒ }	 t d |	 ƒ }
 t t ƒ  ƒ } t | j	 |
 g ƒ } d } | j
 d | d	 | d
 | ƒ } | | k sì t ‚ d  S(   Niÿÿÿÿ(   t   DummyR#   R   R   R   R   så   cdef 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}t   x_idt   y_idt   z_id(   R$   RF   R#   t   strt   dummy_indexR   R   R   R   R   t   formatR   (   RF   R#   R   R   R   t   dRG   RH   RI   R   R   R    R   t   expected_templateR!   (    (    sB   lib/python2.7/site-packages/sympy/utilities/tests/test_autowrap.pyt$   test_cython_wrapper_unique_dummyvars¼   s    &4c          C   sP  t  d ƒ \ }  } } t |  | d d ƒ} | ƒ  t |  | ƒ k sJ t ‚ | j d k s_ t ‚ | j d k st t ‚ t t | |  | ƒ d d ƒ} | ƒ  t |  | ƒ k s² t ‚ | j d k sÇ t ‚ | j d k sÜ t ‚ t t | |  | | ƒ d d ƒ} | ƒ  t |  | | ƒ k s"t ‚ | j d k s7t ‚ | j d k sLt ‚ d  S(   Ns   x y zt   backendt   dummys   x, yt   namelessR   s   x, y, z(   R    R   RJ   R   t   argst   returnsR   (   R   R   R   RC   (    (    sB   lib/python2.7/site-packages/sympy/utilities/tests/test_autowrap.pyt   test_autowrap_dummyÐ   s    ##c             sÃ  t  d ƒ \ ‰  ‰ ‰ t t ‡  ‡ ‡ f d †  ƒ t t ˆ ˆ  ˆ ƒ d d d ˆ ˆ  g ƒ}  |  ƒ  t ˆ  ˆ ƒ k s{ t ‚ |  j d k s t ‚ |  j d k s¥ t ‚ t t ‡  ‡ ‡ f d †  ƒ t t ˆ ˆ  ˆ ˆ ƒ d d d ˆ ˆ  ˆ g ƒ}  |  ƒ  t ˆ  ˆ ˆ ƒ k st ‚ |  j d	 k s+t ‚ |  j d k s@t ‚ t t ˆ ˆ  ˆ ˆ ƒ d d d ˆ ˆ  ˆ f ƒ}  |  ƒ  t ˆ  ˆ ˆ ƒ k s•t ‚ |  j d	 k sªt ‚ |  j d k s¿t ‚ d  S(
   Ns   x y zc              s&   t  t ˆ ˆ  ˆ ƒ d d d ˆ  g ƒS(   NRP   RQ   RS   (   R   R   (    (   R   R   R   (    sB   lib/python2.7/site-packages/sympy/utilities/tests/test_autowrap.pyt   <lambda>æ   s   RP   RQ   RS   s   y, xR   c              s-   t  t ˆ ˆ  ˆ ˆ ƒ d d d ˆ  ˆ g ƒS(   NRP   RQ   RS   (   R   R   (    (   R   R   R   (    sB   lib/python2.7/site-packages/sympy/utilities/tests/test_autowrap.pyRV   í   s   s   y, x, z(	   R    R   R
   R   R   RJ   R   RS   RT   (   RC   (    (   R   R   R   sB   lib/python2.7/site-packages/sympy/utilities/tests/test_autowrap.pyt   test_autowrap_argsã   s    +2#2#c          C   s   t  d ƒ \ }  } t j ƒ  } t j | ƒ t |  | d d d | ƒ} | ƒ  t |  | ƒ k sf t ‚ t j	 | t j
 ƒ s t ‚ t j ƒ  d  S(   Ns   x yRP   RQ   t   tempdir(   R    R4   R5   R   R6   R   RJ   R   R7   t   accesst   F_OKR@   (   R   R   t   tmpRC   (    (    sB   lib/python2.7/site-packages/sympy/utilities/tests/test_autowrap.pyt   test_autowrap_store_filesù   s    c          C   s‡   t  d ƒ \ }  } d } zZ t |  | d d d | ƒ} | ƒ  t |  | ƒ k sV t ‚ t j | t j ƒ sq t ‚ Wd  t j | ƒ Xd  S(   Ns   x ys   ./tmpRP   RQ   RX   (	   R    R   RJ   R   R7   RY   RZ   t   shutilt   rmtree(   R   R   R[   RC   (    (    sB   lib/python2.7/site-packages/sympy/utilities/tests/test_autowrap.pyt'   test_autowrap_store_files_issue_gh12939  s    c          C   sQ   t  d ƒ \ }  } t d |  | d d ƒ} | j ƒ  t |  | ƒ k sM t ‚ d  S(   Ns   x yRC   RP   RQ   (   R    R   t   _imp_RJ   R   (   R   R   RC   (    (    sB   lib/python2.7/site-packages/sympy/utilities/tests/test_autowrap.pyt   test_binary_function  s    c          C   s}   t  d ƒ \ }  } } t t d ƒ ƒ } t d |  | | ƒ } t | j | g ƒ } d i t j d 6} | | k sy t ‚ d  S(   Ns   x,y,zt   ufuncifyR   sÚ  #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}
};

static void test_ufunc(char **args, npy_intp *dimensions, npy_intp* steps, void* data)
{
    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);
}
#endifR'   (	   R    R   R	   R   R   t   dump_cR   R3   R   (   R   R   R   t   code_wrapperR   R   R!   (    (    sB   lib/python2.7/site-packages/sympy/utilities/tests/test_autowrap.pyt   test_ufuncify_source  s    Tc    
      C   sÙ   t  d ƒ \ }  } } |  | | f } |  | d d | d } t t d ƒ ƒ } g  t t | ƒ ƒ D]. } t d j | ƒ | j | | ƒ | ƒ ^ qc } t | j	 | d d ƒ} d	 i t
 j d
 6}	 | |	 k sÕ t ‚ d  S(   Ns   x,y,zi   i
   i   Rb   s   func{}t   funcnamet	   multitestsŠ
  #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}
};

static void multitest_ufunc(char **args, npy_intp *dimensions, npy_intp* steps, void* data)
{
    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);
}
#endifR'   (   R    R   R	   t   ranget   lenR   RL   t   diffR   Rc   R   R3   R   (
   R   R   R   t   var_symbolsR   Rd   t   iR   R   R!   (    (    sB   lib/python2.7/site-packages/sympy/utilities/tests/test_autowrap.pyt    test_ufuncify_source_multioutputr  s    G\($   R7   R4   R]   t
   sympy.coreR    R   t   sympy.core.compatibilityR   t   sympy.utilities.autowrapR   R   R   R   R   t   sympy.utilities.codegenR   R	   R
   R   t   sympy.utilities.pytestR   t   sympy.utilities.tmpfilesR   R   R"   R%   R&   RE   RO   RU   RW   R\   R_   Ra   Re   Rm   (    (    (    sB   lib/python2.7/site-packages/sympy/utilities/tests/test_autowrap.pyt   <module>   s*   ("				e							\