ó
¡¼™\c           @  s   d  d l  m Z d  d l m Z m Z m Z d  d l m Z d  d l m	 Z	 m
 Z
 m Z d  d l Z d  d l Z d  d l Z d  d l Z i  Z d e d <d e d	 <e d	 e d
 <i  Z d e d	 <e d	 e d
 <d e d <i  Z d d d g e d <d d d g e d <d d d g e d <d d d g e d <d* d+ d, d- d. g Z d „  Z e d „ Z d „  Z d  „  Z g  Z g  Z xV e D]N \ Z Z e e Z e e e ƒ r´e j e e f ƒ qye j e e f ƒ qyWd! „  Z d" „  Z  d# „  Z! d$ „  Z" d% „  Z# d& „  Z$ d' „  Z% d( „  Z& d) „  Z' d S(/   iÿÿÿÿ(   t   print_function(   t   xt   yt   z(   t   skip(   t   codegent   make_routinet   get_code_generatorNsy   
program main
  include "codegen.h"
  integer :: result;
  result = 0

  %(statements)s

  call exit(result)
end program
t   F95s   
#include "codegen.h"
#include <stdio.h>
#include <math.h>

int main() {
  int result = 0;

  %(statements)s

  return result;
}
t   C89t   C99s™   
  if (fabs(%(call)s)>%(threshold)s) {
    printf("Numerical validation failed: %(call)s=%%e threshold=%(threshold)s\n", %(call)s);
    result = -1;
  }
sÁ   
  if (abs(%(call)s)>%(threshold)s) then
    write(6,"('Numerical validation failed:')")
    write(6,"('%(call)s=',e15.5,'threshold=',e15.5)") %(call)s, %(threshold)s
    result = -1;
  end if
s   cc -c codegen.c -o codegen.os   cc -c main.c -o main.os#   cc main.o codegen.o -lm -o test.exet   ccs$   gfortran -c codegen.f90 -o codegen.os6   gfortran -ffree-line-length-none -c main.f90 -o main.os%   gfortran main.o codegen.o -o test.exet   gfortrans   g95 -c codegen.f90 -o codegen.os1   g95 -ffree-line-length-huge -c main.f90 -o main.os    g95 main.o codegen.o -o test.exet   g95s!   ifort -c codegen.f90 -o codegen.os   ifort -c main.f90 -o main.os"   ifort main.o codegen.o -o test.exet   ifortc      	   C  s[   t  t j d ƒ } xB |  D]: } t j | d | d t d t j ƒ} | d k r t Sq Wt S(   s>   Run a series of commands and only return True if all ran fine.t   wt   stdoutt   shellt   stderri    (   t   opent   ost   devnullt
   subprocesst   callt   Truet   STDOUTt   False(   t   commandst   nullt   commandt   retcode(    (    s@   lib/python2.7/site-packages/sympy/external/tests/test_codegen.pyt   try_runv   s    c      	   C  s#  | j  ƒ  } | t k s t ‚ | t k s0 t ‚ t j d d ƒ j ƒ  } | d% k rc t d ƒ ‚ n  t j	 d | d |  ƒ } t j
 ƒ  } t j | ƒ | rµ t | | d d	 t ƒn% t | d ƒ }	 |	 j | d d	 t ƒg  }
 x | D]ˆ \ } } } } d
 | d j d „  | Dƒ ƒ | f } | d k rLt | ƒ } t t | ƒ ƒ } n  |
 j t | i | d 6| d 6ƒ qç W| d k rˆd } n( | j d ƒ r d } n t d | ƒ ‚ t | d ƒ , } | j t | i d j |
 ƒ d 6ƒ Wd QXt | ƒ } | rt d g ƒ } n t } | d k s;| d k r±| r±| r±d „  } | d ƒ | d ƒ | d ƒ | d ƒ | d ƒ | d ƒ | d ƒ | d ƒ t j | ƒ t j | ƒ n$ t d  | d! t j ƒt j | ƒ | sút d" | d# j | ƒ f ƒ ‚ | st d$ | d# j | ƒ f ƒ ‚ d S(&   s|  A driver for the codegen tests.

       This driver assumes that a compiler ifort is present in the PATH and that
       ifort is (at least) a Fortran 90 compiler. The generated code is written in
       a temporary directory, together with a main program that validates the
       generated code. The test passes when the compilation and the validation
       run correctly.
    t   SYMPY_TEST_CLEAN_TEMPt   alwayst   successt   neversS   SYMPY_TEST_CLEAN_TEMP must be one of the following: 'always', 'success' or 'never'.s   _sympy_%s_tests   %s_R   t   to_filess   %s(%s)-(%s)t   ,c         s  s   |  ] } t  | ƒ Vq d  S(   N(   t   str(   t   .0t   arg(    (    s@   lib/python2.7/site-packages/sympy/external/tests/test_codegen.pys	   <genexpr>©   s    R   R   t	   thresholds   main.f90t   Cs   main.cs2   FIXME: filename extension unknown for language: %sR   t    t
   statementsNs
   ./test.exec         S  s&   t  j j |  ƒ r" t  j |  ƒ n  d  S(   N(   R   t   patht   isfilet   remove(   t   filename(    (    s@   lib/python2.7/site-packages/sympy/external/tests/test_codegen.pyt   safe_removeÉ   s    s   codegen.f90s	   codegen.cs	   codegen.hs	   codegen.os   main.os   test.exes   TEST NOT REMOVED: %st   files"   failed to compile %s code with:
%ss   
s"   failed to execute %s code from:
%s(   R!   R"   R#   (   t   uppert   main_templatet   AssertionErrort   numerical_test_templateR   t   getenvt   lowert
   ValueErrort   tempfilet   mkdtempt   getcwdt   chdirR   R   R   t   writet   joint   fortranize_double_constantsR&   t   appendt
   startswitht   NotImplementedErrorR   R   R   t   rmdirt   printt   sysR   (   t   labelt   routinest   numerical_testst   languageR   t   friendlyt   cleant   workt   oldworkt   code_gent   test_stringst   fn_namet   argst   expectedR)   t   call_stringt   f_namet   ft   compiledt   executedR1   (    (    s@   lib/python2.7/site-packages/sympy/external/tests/test_codegen.pyt   run_test   sl    #		%$	







c           sj   d d l  ‰  ˆ  j d ƒ } ˆ  j d ƒ } ‡  f d †  } d „  } | j | |  ƒ }  | j | |  ƒ }  |  S(   s;   
    Replaces every literal float with literal doubles
    iÿÿÿÿNs   \d+(\.)?\d*[eE]-?\d+s   \d+\.\d*(?!\d*d)c           s   ˆ  j  d d |  j d ƒ ƒ S(   Ns   [eE]t   di    (   t   subt   group(   t   matchobj(   t   re(    s@   lib/python2.7/site-packages/sympy/external/tests/test_codegen.pyt   subs_expé   s    c         S  s   d |  j  d ƒ S(   Ns   %sd0i    (   R\   (   R]   (    (    s@   lib/python2.7/site-packages/sympy/external/tests/test_codegen.pyt
   subs_floatì   s    (   R^   t   compileR[   (   t   code_stringt   pattern_expt   pattern_floatR_   R`   (    (   R^   s@   lib/python2.7/site-packages/sympy/external/tests/test_codegen.pyR@   á   s    	c         C  ss   t  d t ƒ } d d d d f d d d d f g } y' t d | g | |  | d t ƒt SWn t k
 rn t SXd  S(	   Nt   testg      ð?gVçž¯Ò<g      ð¿t   is_feasibleRK   (   g      ð?(   g      ð¿(   R   R   RY   R   R   R5   (   RJ   R   t   routineRI   (    (    s@   lib/python2.7/site-packages/sympy/external/tests/test_codegen.pyRf   õ   s    c           C  s   d t  k r t d ƒ n  d  S(   NR	   R   s*   `cc' command didn't work as expected (C89)(   R	   R   (   t   invalid_lang_compilersR   (    (    (    s@   lib/python2.7/site-packages/sympy/external/tests/test_codegen.pyt   test_C89_cc  s    c           C  s   d t  k r t d ƒ n  d  S(   NR
   R   s*   `cc' command didn't work as expected (C99)(   R
   R   (   Rh   R   (    (    (    s@   lib/python2.7/site-packages/sympy/external/tests/test_codegen.pyt   test_C99_cc  s    c           C  s   d t  k r t d ƒ n  d  S(   NR   R   s'   `ifort' command didn't work as expected(   R   R   (   Rh   R   (    (    (    s@   lib/python2.7/site-packages/sympy/external/tests/test_codegen.pyt   test_F95_ifort  s    c           C  s   d t  k r t d ƒ n  d  S(   NR   R   s*   `gfortran' command didn't work as expected(   R   R   (   Rh   R   (    (    (    s@   lib/python2.7/site-packages/sympy/external/tests/test_codegen.pyt   test_F95_gfortran  s    c           C  s   d t  k r t d ƒ n  d  S(   NR   R   s%   `g95' command didn't work as expected(   R   R   (   Rh   R   (    (    (    s@   lib/python2.7/site-packages/sympy/external/tests/test_codegen.pyt   test_F95_g95"  s    c          C  sl   d d d d f d d d	 d f g }  d t  t t f g } x* t D]" \ } } t d
 | |  | | ƒ qB Wd  S(   NRe   g      ð?g      @g      @g      5@gVçž¯Ò<g      ð¿g       @g      Àt   basic_codegen(   g      ð?g      @g      @(   g      ð¿g       @g      À(   R   R   R   t   valid_lang_commandsRY   (   RI   t	   name_exprt   langR   (    (    s@   lib/python2.7/site-packages/sympy/external/tests/test_codegen.pyt   test_basic_codegen)  s
    c          C  s   d d l  m }  m } m } m } m } m } m } m } m	 } m
 }	 m }
 m } m } m } m } d t t ƒ f d |  t ƒ f d | t ƒ f d | t ƒ f d | t ƒ f d | t ƒ f d	 | t ƒ f d
 | t ƒ f d |	 t ƒ f d |
 t ƒ f d | t ƒ f d | t ƒ f d | t ƒ f g } g  } xY | D]Q \ } } xB d D]: } | | j t | ƒ ƒ } | j | | f | d f ƒ qMWq:Wxj t D]b \ } } | j d ƒ rØd | t ƒ f d | t ƒ f g } n g  } t d | | | | | ƒ q–Wd  S(   Niÿÿÿÿ(   t   acost   asint   atant   ceilingt   cost   cosht   floort   logt   lnt   sint   sinht   sqrtt   tant   tanht   Nt	   test_fabst	   test_acost	   test_asint	   test_atant   test_cost	   test_cosht   test_logt   test_lnt   test_sint	   test_sinht	   test_sqrtt   test_tant	   test_tanhgš™™™™™É?g      à?gš™™™™™é?g›+¡†›„=R*   t
   test_floort	   test_ceilt   intrinsic_math1(   gš™™™™™É?g      à?gš™™™™™é?(   t   sympyRs   Rt   Ru   Rv   Rw   Rx   Ry   Rz   R{   R|   R}   R~   R   R€   R   t   absR   t   subsRA   Ro   RB   RY   (   Rs   Rt   Ru   Rv   Rw   Rx   Ry   Rz   R{   R|   R}   R~   R   R€   R   Rp   RI   t   namet   exprt   xvalRS   Rq   R   t   name_expr_C(    (    s@   lib/python2.7/site-packages/sympy/external/tests/test_codegen.pyt   test_intrinsic_math1_codegen3  s2    d$'c          C  sì   d d l  m }  m } d |  t t ƒ f d t t f g } g  } xw | D]o \ } } x` d d d f D]O \ } } | | j t | ƒ j t | ƒ ƒ } | j | | | f | d
 f ƒ qd WqH Wx* t D]" \ }	 }
 t d | | |	 |
 ƒ qÂ Wd  S(   Niÿÿÿÿ(   t   atan2R   t
   test_atan2t   test_powgš™™™™™É?gÍÌÌÌÌÌô?g      à?gš™™™™™É¿gš™™™™™é?g›+¡†›„=t   intrinsic_math2(   gš™™™™™É?gÍÌÌÌÌÌô?(   g      à?gš™™™™™É¿(   gš™™™™™é?gš™™™™™é?(	   R’   Rš   R   R   R   R”   RA   Ro   RY   (   Rš   R   Rp   RI   R•   R–   R—   t   yvalRS   Rq   R   (    (    s@   lib/python2.7/site-packages/sympy/external/tests/test_codegen.pyt   test_instrinsic_math2_codegenT  s    $'c          C  sY  d d l  m }  m } m } m } d |  t ƒ | t ƒ | t ƒ d j ƒ  f d | | | | | | | | t t t ƒ ƒ ƒ ƒ ƒ ƒ ƒ ƒ f g } g  } x‰ | D] \ } } xr d d d f D]a \ } }	 }
 | | j	 t | ƒ j	 t |	 ƒ j	 t |
 ƒ ƒ } | j
 | | |	 |
 f | d f ƒ q¿ Wq£ Wx* t D]" \ } } t d | | | | ƒ q/Wd  S(   Niÿÿÿÿ(   R|   Rw   R   R   t   test1i   t   test2gš™™™™™É?gÍÌÌÌÌÌô?g333333Ó¿g      à?gš™™™™™É¿g        gš™™™™™é?gÍÌÌÌÌÌ @gê-™—q=t   complicated_codegen(   gš™™™™™É?gÍÌÌÌÌÌô?g333333Ó¿(   g      à?gš™™™™™É¿g        (   gš™™™™™é?gÍÌÌÌÌÌ @gš™™™™™é?(   R’   R|   Rw   R   R   R   R   R   t   expandR”   RA   Ro   RY   (   R|   Rw   R   R   Rp   RI   R•   R–   R—   Rž   t   zvalRS   Rq   R   (    (    s@   lib/python2.7/site-packages/sympy/external/tests/test_codegen.pyt   test_complicated_codegend  s    "-G0*(   R	   R   (   R
   R   (   R   R   (   R   R   (   R   R   ((   t
   __future__R    t	   sympy.abcR   R   R   t   sympy.utilities.pytestR   t   sympy.utilities.codegenR   R   R   RF   R   R:   R   R4   R6   t   compile_commandst   combinations_lang_compilerR   R   RY   R@   Rf   Ro   Rh   Rq   t   compilerR   RA   Ri   Rj   Rk   Rl   Rm   Rr   R™   RŸ   R¥   (    (    (    s@   lib/python2.7/site-packages/sympy/external/tests/test_codegen.pyt   <module>   sj   



		`		
						
	!	