ó
Ħĵ\c           @@ s]  d  d l  m Z m Z d  d l Z d  d l Z d  d l m Z d  d l m	 Z	 d  d l
 m Z 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 d  d
 l m Z m Z m Z d  d l m Z m Z d  d l m  Z  m! Z! m" Z" e d  Z# e d  Z$ d   Z% e d    Z& e d    Z' d   Z( e d    Z) d S(   i    (   t   absolute_importt   print_functionN(   t   exec_(   t
   Assignment(   t   newtons_methodt   newtons_method_function(   t   bind_C(   t   render_as_module(   t   import_module(   t   ccode(   t   compile_link_import_stringst   has_ct   has_fortran(   t   TemporaryDirectoryt	   may_xfail(   t   skipt
   USE_PYTESTt   raisest   cythont	   wurlitzerc          C@ st   t  j d  \ }  } } t  j |   |  d } t | |  | |  } | j t | | | j |     sp t  d  S(   Ns	   x dx atoli   (   t   spt   symbolst   cosR   t   hasR   t   difft   AssertionError(   t   xt   dxt   atolt   exprt   algo(    (    sB   lib/python2.7/site-packages/sympy/codegen/tests/test_algorithms.pyt   test_newtons_method   s    c       
   C@ sâ   t  j d d t }  t  j |   |  d } t | |   } t sN t d  n  t   sd t d  n  t d d  } t	   ` } t
 d d	 t |  f d g d | d | \ } } t | j d  d  d k  sĜ t  Wd  QXd  S(   NR   t   reali   s   cython not installed.s   No C compiler found.t   stdt   c99s   newton.cs%   #include <math.h>
#include <stdio.h>
s   _newton.pyxsI   cdef extern double newton(double)
def py_newton(x):
    return newton(x)
t	   build_dirt   compile_kwargsg      à?gßşvöħë?gê-q=(   s   _newton.pyxsI   cdef extern double newton(double)
def py_newton(x):
    return newton(x)
(   R   t   Symbolt   TrueR   R   R   R   R   t   dictR   R
   R	   t   abst	   py_newtonR   (   R   R   t   funct
   compile_kwt   foldert   modt   info(    (    sB   lib/python2.7/site-packages/sympy/codegen/tests/test_algorithms.pyt#   test_newtons_method_function__ccode   s    		c          C@ sç   t  j d d t }  t  j |   |  d } t | |  d t d d  g } t s` t d  n  t   sv t d  n  t	 | g d	  } t
   P } t d
 | f d g d | \ } } t | j d  d  d k  sŬ t  Wd  QXd  S(   NR   R    i   t   attrst   namet   newtons   cython not installed.s   No Fortran compiler found.t
   mod_newtons
   newton.f90s   _newton.pyxsR   cdef extern double newton(double*)
def py_newton(double x):
    return newton(&x)
R#   g      à?gßşvöħë?gê-q=(   s   _newton.pyxsR   cdef extern double newton(double*)
def py_newton(double x):
    return newton(&x)
(   R   R%   R&   R   R   R   R   R   R   t   f_moduleR   R
   R(   R)   R   (   R   R   R*   t   f_modR,   R-   R.   (    (    sB   lib/python2.7/site-packages/sympy/codegen/tests/test_algorithms.pyt#   test_newtons_method_function__fcode3   s    !			c          C@ s   t  j d d t }  t  j |   |  d } t | |   } t |  } i  } t | | |  t d |  } t | d  d k  s t	  d  S(   NR   R    i   s   newton(0.5)gßşvöħë?gê-q=(
   R   R%   R&   R   R   t	   py_moduleR   t   evalR(   R   (   R   R   R*   t   py_modt	   namespacet   res(    (    sB   lib/python2.7/site-packages/sympy/codegen/tests/test_algorithms.pyt$   test_newtons_method_function__pycodeI   s    c       
   @ sİ  t  j d  }  \  } } } | t  j |   |  d   t t    f d    t } t    |  d | } t   s t d  n  t	 s˘ t d  n  t
 d d  } t   é } t d	 d
 t |  f d g d | d | \ } }	 | r$t j    \ }
 } | j d  } Wd  QXn | j d  } t | d  d k  sOt  | sbt d  n  |
 j   | j   }
 } | d k st  |
 d k st  Wd  QXd  S(   Ns   x A k pi   c           @ s   t      S(   N(   R   (    (   R   R   (    sB   lib/python2.7/site-packages/sympy/codegen/tests/test_algorithms.pyt   <lambda>X   t    t   debugs   No C compiler found.s   cython not installed.R!   R"   s   newton_par.cs%   #include <math.h>
#include <stdio.h>
s   _newton_par.pyxsy   cdef extern double newton(double, double, double, double)
def py_newton(x, A=1, k=1, p=1):
    return newton(x, A, k, p)
R$   R#   g      à?gßşvöħë?gê-q=sA   C-level output only tested when package 'wurlitzer' is available.R>   sà   x=         0.5 d_x=     0.61214
x=      1.1121 d_x=    -0.20247
x=     0.90967 d_x=   -0.042409
x=     0.86726 d_x=  -0.0017867
x=     0.86548 d_x= -3.1022e-06
x=     0.86547 d_x= -9.3421e-12
x=     0.86547 d_x=  3.6902e-17
(   s   _newton_par.pyxsy   cdef extern double newton(double, double, double, double)
def py_newton(x, A=1, k=1, p=1):
    return newton(x, A, k, p)
(   R   R   R   R   t
   ValueErrorR   R   R   R   R   R'   R   R
   R	   t   pipesR)   R(   R   t   read(   t   argst   At   kt   pt   use_wurlitzerR*   R+   R,   R-   R.   t   outt   errt   result(    (   R   R   sB   lib/python2.7/site-packages/sympy/codegen/tests/test_algorithms.pyt.   test_newtons_method_function__ccode_parametersT   s6    #		(*   t
   __future__R    R   t   syst   sympyR   t   sympy.core.compatibilityR   t   sympy.codegen.astR   t   sympy.codegen.algorithmsR   R   t   sympy.codegen.fnodesR   t   sympy.codegen.futilsR   R4   t   sympy.codegen.pyutilsR7   t   sympy.externalR   t   sympy.printing.ccodeR	   t   sympy.utilities._compilationR
   R   R   t!   sympy.utilities._compilation.utilR   R   t   sympy.utilities.pytestR   R   R   R   R   R   R/   R6   R<   RK   (    (    (    sB   lib/python2.7/site-packages/sympy/codegen/tests/test_algorithms.pyt   <module>   s(   		