ó
Ąź\c           @   sâ  d  d l  m Z m Z m Z m Z m Z m Z d  d l m Z d  d l	 m
 Z
 m Z d  d l	 m Z d  d l m Z m Z d  d l m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z d  d l m Z d  d l m Z d	 e  e  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   Z. d   Z/ d   Z0 d   Z1 d   Z2 d   Z3 d   Z4 d   Z5 d   Z6 d    Z7 d!   Z8 d"   Z9 d#   Z: d$   Z; d%   Z< d&   Z= d'   Z> d(   Z? d)   Z@ d*   ZA d+   ZB d,   ZC d-   ZD d.   ZE d/   ZF d0   ZG d1   ZH d2   ZI d3   ZJ d4   ZK d5   ZL d6   ZM d7   ZN d8   ZO d9   ZP d:   ZQ d;   ZR d<   ZS d=   ZT d>   ZU d?   ZV d@   ZW dA S(B   i˙˙˙˙(   t   symbolst   Eqt   pit   Catalant   Lambdat   Dummy(   t   StringIO(   t   erft   Integral(   t   Equality(   t   Matrixt   MatrixSymbol(   t   codegent   make_routinet   CCodeGent
   C89CodeGent
   C99CodeGent   InputArgumentt   CodeGenErrort   FCodeGent   CodeGenArgumentListErrort   OutputArgumentt   InOutArgument(   t   raises(   t   implemented_functiont   filec         C   s9   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 generated to facilitate the
       testing of the output.
    (   R   t   getvaluet   close(   t   dump_fnt   routinest   prefixt   headert   emptyt   outputt   source(    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt
   get_string   s
    	
c             sŠ  t  d  \          t t    f d    t t       f d    t d t     d      g }  g  |  j D] } | j ^ q      g k sĹ t  g  |  j D] } t |  ^ qĎ t	 t	 t
 t	 g k s˙ t  t d t    d    g }  g  |  j D] } t |  ^ q0t t	 t	 g k s]t  d d l m } m } t | d d	 g  \ } } t  d
 d t } | d |  } t d t | | | |  d | | | g }  g  |  j D] } | j ^ qč| j | j | g k st  t     d d f  d d f   t d t     d      g }  g  |  j D] } | j ^ qx     g k sĽt  d  S(   Ns   a x y zc              s   t  d   d   g S(   Nt   testt   argument_sequence(   R   (    (   t   exprt   xt   z(    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   <lambda>#   s   c              s%   t  d t     d    g S(   NR$   R%   (   R   R   (    (   t   aR&   R'   t   yR(   (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyR)   %   s   R$   R%   i˙˙˙˙(   t   IndexedBaset   Idxt   At   Bt   mt   integert   ii   i   i   (   R    R   R   R   R   t	   argumentst   namet   AssertionErrort   typeR   R   R   t   sympy.tensorR,   R-   t   mapt   Truet   labelR   (   t   rt   argR,   R-   R.   R/   R0   R2   (    (   R*   R&   R'   R+   R(   sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_Routine_argument_order    s(    "*7'/:,*c          C   s1   t    }  t |  j g   } | d k s- t  d  S(   Ns$   #include "file.h"
#include <math.h>
(   R   R#   t   dump_cR5   (   t   code_genR"   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_empty_c_code;   s    	c          C   sQ   t    }  t |  j g  d t } | d  d k s7 t  | d d k sM t  d  S(   NR   iR   sR   /******************************************************************************
 *i   sˇ  *
 *                                                                            *
 *              See http://www.sympy.org/ for more information.               *
 *                                                                            *
 *                       This file is part of 'project'                       *
 ******************************************************************************/
#include "file.h"
#include <math.h>
(   R   R#   R>   R9   R5   (   R?   R"   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_empty_c_code_with_commentA   s
    	c          C   s1   t    }  t |  j g   } | d k s- t  d  S(   Ns9   #ifndef PROJECT__FILE__H
#define PROJECT__FILE__H
#endif
(   R   R#   t   dump_hR5   (   R?   R"   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_empty_c_headerS   s    	c          C   sl   t  d  \ }  } } |  | | } t d |  } t   } t | j | g  } d } | | k sh t  d  S(   Ns   x,y,zR$   s   #include "file.h"
#include <math.h>
double test(double x, double y, double z) {
   double test_result;
   test_result = z*(x + y);
   return test_result;
}
(   R    R   R   R#   R>   R5   (   R'   R+   R(   R&   t   routineR?   R"   t   expected(    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_simple_c_codeY   s    	c          C   sl   t  d  \ }  } } |  | | } t d |  } t   } t | j | g  } d } | | k sh t  d  S(   Ns   if, typedef, whileR$   s¸   #include "file.h"
#include <math.h>
double test(double if_, double typedef_, double while_) {
   double test_result;
   test_result = while_*(if_ + typedef_);
   return test_result;
}
(   R    R   R   R#   R>   R5   (   R'   R+   R(   R&   RD   R?   R"   RE   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_c_code_reserved_wordsk   s    	c          C   sZ   t  d t t  }  t   } t | j |  g  } d t j d  } | | k sV t  d  S(   NR$   s§   #include "file.h"
#include <math.h>
double test() {
   double test_result;
   double const Catalan = %s;
   test_result = pow(M_PI, Catalan);
   return test_result;
}
i   (   R   R   R   R   R#   R>   t   evalfR5   (   RD   R?   R"   RE   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_numbersymbol_c_code}   s    	c          C   sw   t  d  \ }  } } |  | } t d | d | |  | g } t   } t | j | g  } d } | | k ss t  d  S(   Ns   x,y,zR$   R%   s   #include "file.h"
#include <math.h>
double test(double z, double x, double y) {
   double test_result;
   test_result = x + y;
   return test_result;
}
(   R    R   R   R#   R>   R5   (   R'   R+   R(   R&   RD   R?   R"   RE   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_c_code_argument_order   s    
	c          C   sl   t  d  \ }  } } |  | | } t d |  } t   } t | j | g  } d } | | k sh t  d  S(   Ns   x,y,zR$   sd   #ifndef PROJECT__FILE__H
#define PROJECT__FILE__H
double test(double x, double y, double z);
#endif
(   R    R   R   R#   RB   R5   (   R'   R+   R(   R&   RD   R?   R"   RE   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_simple_c_header    s    	c          C   si   t  d  \ }  } } |  | | } d d g } t d | f d d d	 t d
 t } | | k se t  d  S(   Ns   x,y,zs   file.cs   #include "file.h"
#include <math.h>
double test(double x, double y, double z) {
   double test_result;
   test_result = z*(x + y);
   return test_result;
}
s   file.hsd   #ifndef PROJECT__FILE__H
#define PROJECT__FILE__H
double test(double x, double y, double z);
#endif
R$   t   CR   R   R    (   s   file.cs   #include "file.h"
#include <math.h>
double test(double x, double y, double z) {
   double test_result;
   test_result = z*(x + y);
   return test_result;
}
(   s   file.hsd   #ifndef PROJECT__FILE__H
#define PROJECT__FILE__H
double test(double x, double y, double z);
#endif
(   R    R   t   FalseR5   (   R'   R+   R(   R&   RE   t   result(    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_simple_c_codegenŻ   s      	$c             sl   t  d  \ }  } } |  | | } |  | | } t d | | g   t     t t    f d    d  S(   Ns   x,y,zR$   c              s   t    j  g  S(   N(   R#   RB   (    (   R?   RD   (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyR)   Î   t    (   R    R   R   R   R   (   R'   R+   R(   t   expr1t   expr2(    (   R?   RD   sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_multiple_results_cĹ   s    	c           C   s   t  t d    d  S(   Nc           S   s   t  d g   S(   NR$   (   R   (    (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyR)   Ň   RP   (   R   t
   ValueError(    (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_no_results_cŃ   s    c          C   sá  d d l  m }  m } m } m } m } m } m } m } m	 } m
 }	 m }
 m } m } m } m } t d  } d | |  f d |  |  f d | |  f d | |  f d | |  f d	 | |  f d
 | |  f d | |  f d | |  f d | |  f d |	 |  f d |
 |  f d | |  f d | |  f d | |  f g } t | d d d t d t } | d d d k st  | d d d k sŠt  | d d d k sĂt  | d d d k sÝt  d  S(   Ni˙˙˙˙(   t   acost   asint   atant   ceilingt   cost   cosht   floort   logt   lnt   sint   sinht   sqrtt   tant   tanht   AbsR'   t	   test_fabst	   test_acost	   test_asint	   test_atant	   test_ceilt   test_cost	   test_cosht
   test_floort   test_logt   test_lnt   test_sint	   test_sinht	   test_sqrtt   test_tant	   test_tanht   C89R   R   R    i    s   file.ci   sö  #include "file.h"
#include <math.h>
double test_fabs(double x) {
   double test_fabs_result;
   test_fabs_result = fabs(x);
   return test_fabs_result;
}
double test_acos(double x) {
   double test_acos_result;
   test_acos_result = acos(x);
   return test_acos_result;
}
double test_asin(double x) {
   double test_asin_result;
   test_asin_result = asin(x);
   return test_asin_result;
}
double test_atan(double x) {
   double test_atan_result;
   test_atan_result = atan(x);
   return test_atan_result;
}
double test_ceil(double x) {
   double test_ceil_result;
   test_ceil_result = ceil(x);
   return test_ceil_result;
}
double test_cos(double x) {
   double test_cos_result;
   test_cos_result = cos(x);
   return test_cos_result;
}
double test_cosh(double x) {
   double test_cosh_result;
   test_cosh_result = cosh(x);
   return test_cosh_result;
}
double test_floor(double x) {
   double test_floor_result;
   test_floor_result = floor(x);
   return test_floor_result;
}
double test_log(double x) {
   double test_log_result;
   test_log_result = log(x);
   return test_log_result;
}
double test_ln(double x) {
   double test_ln_result;
   test_ln_result = log(x);
   return test_ln_result;
}
double test_sin(double x) {
   double test_sin_result;
   test_sin_result = sin(x);
   return test_sin_result;
}
double test_sinh(double x) {
   double test_sinh_result;
   test_sinh_result = sinh(x);
   return test_sinh_result;
}
double test_sqrt(double x) {
   double test_sqrt_result;
   test_sqrt_result = sqrt(x);
   return test_sqrt_result;
}
double test_tan(double x) {
   double test_tan_result;
   test_tan_result = tan(x);
   return test_tan_result;
}
double test_tanh(double x) {
   double test_tanh_result;
   test_tanh_result = tanh(x);
   return test_tanh_result;
}
s   file.hsŘ  #ifndef PROJECT__FILE__H
#define PROJECT__FILE__H
double test_fabs(double x);
double test_acos(double x);
double test_asin(double x);
double test_atan(double x);
double test_ceil(double x);
double test_cos(double x);
double test_cosh(double x);
double test_floor(double x);
double test_log(double x);
double test_ln(double x);
double test_sin(double x);
double test_sinh(double x);
double test_sqrt(double x);
double test_tan(double x);
double test_tanh(double x);
#endif
(   t   sympyRV   RW   RX   RY   RZ   R[   R\   R]   R^   R_   R`   Ra   Rb   Rc   Rd   R    R   RM   R5   (   RV   RW   RX   RY   RZ   R[   R\   R]   R^   R_   R`   Ra   Rb   Rc   Rd   R'   t	   name_exprRN   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_ansi_math1_codegenŐ   s0    dc          C   sŃ   d d l  m }  t d  \ } } d |  | |  f d | | f g } t | d d d t d	 t } | d
 d
 d k s t  | d
 d d k s t  | d d
 d k sł t  | d d d k sÍ t  d  S(   Ni˙˙˙˙(   t   atan2s   x,yt
   test_atan2t   test_powRt   R   R   R    i    s   file.ci   s*  #include "file.h"
#include <math.h>
double test_atan2(double x, double y) {
   double test_atan2_result;
   test_atan2_result = atan2(x, y);
   return test_atan2_result;
}
double test_pow(double x, double y) {
   double test_pow_result;
   test_pow_result = pow(x, y);
   return test_pow_result;
}
s   file.hs   #ifndef PROJECT__FILE__H
#define PROJECT__FILE__H
double test_atan2(double x, double y);
double test_pow(double x, double y);
#endif
(   Ru   Rx   R    R   RM   R5   (   Rx   R'   R+   Rv   RN   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_ansi_math2_codegen  s    c          C   s/  d d l  m }  m } m } t d  \ } } } d |  |  | |  | |  d j   f d | | | | | | | | | | |         f g } t | d d d	 t d
 t } | d d d k sÝ t  | d d d k s÷ t  | d d d k st  | d d d k s+t  d  S(   Ni˙˙˙˙(   R_   RZ   Rb   s   x,y,zt   test1i   t   test2Rt   R   R   R    i    s   file.ci   s-  #include "file.h"
#include <math.h>
double test1(double x, double y, double z) {
   double test1_result;
   test1_result = pow(sin(x), 7) + 7*pow(sin(x), 6)*cos(y) + 7*pow(sin(x), 6)*tan(z) + 21*pow(sin(x), 5)*pow(cos(y), 2) + 42*pow(sin(x), 5)*cos(y)*tan(z) + 21*pow(sin(x), 5)*pow(tan(z), 2) + 35*pow(sin(x), 4)*pow(cos(y), 3) + 105*pow(sin(x), 4)*pow(cos(y), 2)*tan(z) + 105*pow(sin(x), 4)*cos(y)*pow(tan(z), 2) + 35*pow(sin(x), 4)*pow(tan(z), 3) + 35*pow(sin(x), 3)*pow(cos(y), 4) + 140*pow(sin(x), 3)*pow(cos(y), 3)*tan(z) + 210*pow(sin(x), 3)*pow(cos(y), 2)*pow(tan(z), 2) + 140*pow(sin(x), 3)*cos(y)*pow(tan(z), 3) + 35*pow(sin(x), 3)*pow(tan(z), 4) + 21*pow(sin(x), 2)*pow(cos(y), 5) + 105*pow(sin(x), 2)*pow(cos(y), 4)*tan(z) + 210*pow(sin(x), 2)*pow(cos(y), 3)*pow(tan(z), 2) + 210*pow(sin(x), 2)*pow(cos(y), 2)*pow(tan(z), 3) + 105*pow(sin(x), 2)*cos(y)*pow(tan(z), 4) + 21*pow(sin(x), 2)*pow(tan(z), 5) + 7*sin(x)*pow(cos(y), 6) + 42*sin(x)*pow(cos(y), 5)*tan(z) + 105*sin(x)*pow(cos(y), 4)*pow(tan(z), 2) + 140*sin(x)*pow(cos(y), 3)*pow(tan(z), 3) + 105*sin(x)*pow(cos(y), 2)*pow(tan(z), 4) + 42*sin(x)*cos(y)*pow(tan(z), 5) + 7*sin(x)*pow(tan(z), 6) + pow(cos(y), 7) + 7*pow(cos(y), 6)*tan(z) + 21*pow(cos(y), 5)*pow(tan(z), 2) + 35*pow(cos(y), 4)*pow(tan(z), 3) + 35*pow(cos(y), 3)*pow(tan(z), 4) + 21*pow(cos(y), 2)*pow(tan(z), 5) + 7*cos(y)*pow(tan(z), 6) + pow(tan(z), 7);
   return test1_result;
}
double test2(double x, double y, double z) {
   double test2_result;
   test2_result = cos(cos(cos(cos(cos(cos(cos(cos(x + y + z))))))));
   return test2_result;
}
s   file.hs   #ifndef PROJECT__FILE__H
#define PROJECT__FILE__H
double test1(double x, double y, double z);
double test2(double x, double y, double z);
#endif
(	   Ru   R_   RZ   Rb   R    t   expandR   RM   R5   (   R_   RZ   Rb   R'   R+   R(   Rv   RN   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_complicated_codegen%  s    -G0c          C   s§  d d l  m }  m } d d l m } | d d t \ } } |  d  } |  d  } |  d  } | d	 |  } | d
 |  }	 t d t | | | | |	 f | |	  f d d d t d t \ \ }
 } \ } } |
 d k sç t	  d } | | i d | | |	 d 6k s| | i d |	 | | d 6k s| | i d | | |	 d 6k s| | i d |	 | | d 6k st	  | d k st	  | d k sŁt	  d  S(   Ni˙˙˙˙(   R,   R-   (   R    s   n mR1   R.   R'   R+   R2   t   jt   matrix_vectort   C99R   R   R    s   file.cs  #include "file.h"
#include <math.h>
void matrix_vector(double *A, int m, int n, double *x, double *y) {
   for (int i=0; i<m; i++){
      y[i] = 0;
   }
   for (int i=0; i<m; i++){
      for (int j=0; j<n; j++){
         y[i] = %(rhs)s + y[i];
      }
   }
}
s
   A[%s]*x[j]t   rhss
   x[j]*A[%s]s   file.hs|   #ifndef PROJECT__FILE__H
#define PROJECT__FILE__H
void matrix_vector(double *A, int m, int n, double *x, double *y);
#endif
(
   R7   R,   R-   Ru   R    R9   R   R   RM   R5   (   R,   R-   R    t   nR0   R.   R'   R+   R2   R   t   f1t   codet   f2t	   interfaceRE   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_loops_ci  s&    R###)c          C   s˙   d d l  m }  m } t d d t d t \ } } |  d  } |  d  } | | |  } d i | j j d	 6| j d
 6} t d t	 | | | |   } t
   } t   }	 t |	 j | g  }
 |
 | k sŐ t  t t   t | j | g  Wd  QXd  S(   Ni˙˙˙˙(   R,   R-   s   i mR1   t   clsR'   R+   sĂ   #include "file.h"
#include <math.h>
void test_dummies(int m_%(mno)i, double *x, double *y) {
   for (int i_%(ino)i=0; i_%(ino)i<m_%(mno)i; i_%(ino)i++){
      y[i_%(ino)i] = x[i_%(ino)i];
   }
}
t   inot   mnot   test_dummies(   R7   R,   R-   R    R9   R   R:   t   dummy_indexR   R   R   R   R#   R>   R5   R   t   NotImplementedError(   R,   R-   R2   R0   R'   R+   RE   R;   t   c89t   c99R   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_dummy_loops_c  s     		c          C   sŮ  d d l  m }  m } d d l m } | d d t \ } } } } |  d d | | f } |  d  } |  d	  }	 | d
 | | d f  }
 | d |  } t d t |	 |
 | |
 | f | |  f d d d t d t \ \ } } \ } } | d k st	  d i | d d 6d d 6} | | i d |
 | | d 6k są| | i d | |
 | d 6k są| | i d |
 | | d 6k są| | i d | |
 | d 6k sąt	  | d k sĂt	  | d k sŐt	  d  S(   Ni˙˙˙˙(   R,   R-   (   R    s   n m o pR1   R.   t   shapeR'   R+   R2   i   R   R   R   R   R   R    s   file.cs#  #include "file.h"
#include <math.h>
void matrix_vector(double *A, int m, int n, int o, int p, double *x, double *y) {
   for (int i=o; i<%(upperi)s; i++){
      y[i] = 0;
   }
   for (int i=o; i<%(upperi)s; i++){
      for (int j=0; j<n; j++){
         y[i] = %(rhs)s + y[i];
      }
   }
}
i   t   upperis   %(rhs)sR   s
   A[%s]*x[j]s
   x[j]*A[%s]s   file.hs   #ifndef PROJECT__FILE__H
#define PROJECT__FILE__H
void matrix_vector(double *A, int m, int n, int o, int p, double *x, double *y);
#endif
(
   R7   R,   R-   Ru   R    R9   R   R   RM   R5   (   R,   R-   R    R   R0   t   ot   pR.   R'   R+   R2   R   R   R   R   R   RE   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_partial_loops_cŞ  s(    R###)c    
      C   sĂ   d d l  m }  m } m } t d  \ } } } t d | | |  |   | |  g  } t   } | j | g d d t d t } | d d d	 k s t	  d
 }	 | d d |	 k sż t	  d  S(   Ni˙˙˙˙(   R_   RZ   R	   s   x,y,zt   fooR$   R   R    i    s   test.cs   #include "test.h"
#include <math.h>
double foo(double x, double *y) {
   (*y) = sin(x);
   double foo_result;
   foo_result = cos(x);
   return foo_result;
}
i   (
   Ru   R_   RZ   R	   R    R   R   t   writeRM   R5   (
   R_   RZ   R	   R'   R+   R(   R;   t   cRN   RE   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_output_arg_cÖ  s    *	!	c    
      C   sĂ   d d l  m }  m } m } t d  \ } } } t d | | |  |   | |  g  } t   } | j | g d d t d t } | d d d	 k s t	  d
 }	 | d d |	 k sż t	  d  S(   Ni˙˙˙˙(   R_   RZ   R	   s   if, while, zR   R$   R   R    i    s   test.csŽ   #include "test.h"
#include <math.h>
double foo(double if_, double *while_) {
   (*while_) = sin(if_);
   double foo_result;
   foo_result = cos(if_);
   return foo_result;
}
i   (
   Ru   R_   RZ   R	   R    R   R   R   RM   R5   (
   R_   RZ   R	   R'   R+   R(   R;   R   RN   RE   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt    test_output_arg_c_reserved_wordsę  s    *	!	c          C   sů   t  d  \ }  } } t  d  \ } } t d d d  } t | t d d |  g g   } t | |  | |  } t | d |   } d | | | g f }	 d }
 t |	 d	 d d
 t d t d |  | | | | | f } | d d } | |
 k ső t  d  S(   Ns   x,y,zs   B,CR.   i   i   i   R$   sź   #include "test.h"
#include <math.h>
void test(double x, double *C, double z, double y, double *A, double *B) {
   (*C) = z*(x + y);
   A[0] = 1;
   A[1] = 2;
   A[2] = x;
   (*B) = 2*x;
}
R   R   R    R%   i    (   R    R   R	   R
   R   RM   R5   (   R'   R+   R(   R/   RL   R.   RQ   RR   t   expr3Rv   RE   RN   R"   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt    test_ccode_results_named_orderedţ  s    !c          C   sđ   t  d d d  }  t  d d d  } t  d d d  } t  d d d  } d t | |  d	 d  d   f  t | |  d d  d   f  t | |  d  d   d
 f  g f } t | d d d t d t } | d	 d } d } | | k sě t  d  S(   NR.   i   i   R/   i   RL   t   DR$   i    i   R   R   R    s  #include "test.h"
#include <math.h>
void test(double *A, double *B, double *C, double *D) {
   B[0] = A[0];
   B[1] = A[1];
   B[2] = A[2];
   C[0] = A[3];
   C[1] = A[4];
   C[2] = A[5];
   D[0] = A[2];
   D[1] = A[5];
   D[2] = A[8];
   D[3] = A[11];
   D[4] = A[14];
}
(   R   R	   R   RM   R5   (   R.   R/   RL   R   Rv   RN   R"   RE   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_ccode_matrixsymbol_slice  s    %c    
      C   sÍ   t  d  \ }  } } } t d d d  } d t | t |  | g |  | | | g |  | | | g g   g f } t d t  } t | d | d t d	 t } | d
 d } d }	 | |	 k sÉ t  d  S(   Ns   a b c dt   ei   i   R$   t   cseR?   R   R    i    sË   #include "test.h"
#include <math.h>
void test(double a, double b, double c, double d, double *e) {
   const double x0 = a*b;
   const double x1 = c*d;
   e[0] = x0;
   e[1] = x0 + x1;
   e[2] = x0*x1;
}
(	   R    R   R	   R
   R   R9   R   RM   R5   (
   R*   t   bR   t   dRĄ   Rv   t	   generatorRN   R"   RE   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_ccode_cse5  s    L
c          C   s1   t    }  t |  j g   } | d k s- t  d  S(   NRP   (   R   R#   t   dump_f95R5   (   R?   R"   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_empty_f_codeI  s    	c          C   sQ   t    }  t |  j g  d t } | d  d k s7 t  | d d k sM t  d  S(   NR   iR   sR   !******************************************************************************
!*i   s  *
!*                                                                            *
!*              See http://www.sympy.org/ for more information.               *
!*                                                                            *
!*                       This file is part of 'project'                       *
!******************************************************************************
(   R   R#   R§   R9   R5   (   R?   R"   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_empty_f_code_with_headerO  s
    	c          C   s1   t    }  t |  j g   } | d k s- t  d  S(   NRP   (   R   R#   RB   R5   (   R?   R"   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_empty_f_header_  s    	c          C   sl   t  d  \ }  } } |  | | } t d |  } t   } t | j | g  } d } | | k sh t  d  S(   Ns   x,y,zR$   s   REAL*8 function test(x, y, z)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(in) :: y
REAL*8, intent(in) :: z
test = z*(x + y)
end function
(   R    R   R   R#   R§   R5   (   R'   R+   R(   R&   RD   R?   R"   RE   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_simple_f_codee  s    	c          C   si   t  d t t  }  t   } t | j |  g  } d t j d  t j d  f } | | k se t  d  S(   NR$   s   REAL*8 function test()
implicit none
REAL*8, parameter :: Catalan = %sd0
REAL*8, parameter :: pi = %sd0
test = pi**Catalan
end function
i   (   R   R   R   R   R#   R§   RH   R5   (   RD   R?   R"   RE   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_numbersymbol_f_codew  s    	c          C   so   t  d  }  t d t |   t d |    } t   } t | j | g  } d } | | k sk t |   d  S(   NR'   R$   iţ˙˙˙sh   REAL*8 function test(x)
implicit none
REAL*8, intent(in) :: x
test = erf(x) + erf(2.0d0*x)
end function
(   R    R   R   R   R#   R§   R5   (   R'   RD   R?   R"   RE   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_erf_f_code  s    #	c          C   sw   t  d  \ }  } } |  | } t d | d | |  | g } t   } t | j | g  } d } | | k ss t  d  S(   Ns   x,y,zR$   R%   s   REAL*8 function test(z, x, y)
implicit none
REAL*8, intent(in) :: z
REAL*8, intent(in) :: x
REAL*8, intent(in) :: y
test = x + y
end function
(   R    R   R   R#   R§   R5   (   R'   R+   R(   R&   RD   R?   R"   RE   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_f_code_argument_order  s    
	c          C   sl   t  d  \ }  } } |  | | } t d |  } t   } t | j | g  } d } | | k sh t  d  S(   Ns   x,y,zR$   s   interface
REAL*8 function test(x, y, z)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(in) :: y
REAL*8, intent(in) :: z
end function
end interface
(   R    R   R   R#   RB   R5   (   R'   R+   R(   R&   RD   R?   R"   RE   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_simple_f_headerĽ  s    		c          C   si   t  d  \ }  } } |  | | } t d | f d d d t d t } d d g } | | k se t  d  S(   Ns   x,y,zR$   t   F95R   R   R    s   file.f90s   REAL*8 function test(x, y, z)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(in) :: y
REAL*8, intent(in) :: z
test = z*(x + y)
end function
s   file.hs   interface
REAL*8 function test(x, y, z)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(in) :: y
REAL*8, intent(in) :: z
end function
end interface
(   s   file.f90s   REAL*8 function test(x, y, z)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(in) :: y
REAL*8, intent(in) :: z
test = z*(x + y)
end function
(   s   file.hs   interface
REAL*8 function test(x, y, z)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(in) :: y
REAL*8, intent(in) :: z
end function
end interface
(   R    R   RM   R5   (   R'   R+   R(   R&   RN   RE   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_simple_f_codegen¸  s    !  		c             sl   t  d  \ }  } } |  | | } |  | | } t d | | g   t     t t    f d    d  S(   Ns   x,y,zR$   c              s   t    j  g  S(   N(   R#   RB   (    (   R?   RD   (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyR)   Ü  RP   (   R    R   R   R   R   (   R'   R+   R(   RQ   RR   (    (   R?   RD   sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_multiple_results_fÓ  s    	c           C   s   t  t d    d  S(   Nc           S   s   t  d g   S(   NR$   (   R   (    (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyR)   ŕ  RP   (   R   RT   (    (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_no_results_fß  s    c          C   sĎ  d d l  m }  m } m } m } m } m } m } m } m	 } m
 }	 m }
 m } m } m } m } t d  } d | |  f d |  |  f d | |  f d | |  f d | |  f d	 | |  f d
 | |  f d | |  f d |	 |  f d |
 |  f d | |  f d | |  f d | |  f g } t | d d d t d t } | d d d k sqt  d } | d d | k st  | d d d k sŤt  d } | d d | k sËt  d  S(   Ni˙˙˙˙(   RV   RW   RX   RY   RZ   R[   R\   R]   R^   R_   R`   Ra   Rb   Rc   Rd   R'   t   test_absRf   Rg   Rh   Rj   Rk   Rm   Rn   Ro   Rp   Rq   Rr   Rs   R°   R   R   R    i    s   file.f90s   REAL*8 function test_abs(x)
implicit none
REAL*8, intent(in) :: x
test_abs = abs(x)
end function
REAL*8 function test_acos(x)
implicit none
REAL*8, intent(in) :: x
test_acos = acos(x)
end function
REAL*8 function test_asin(x)
implicit none
REAL*8, intent(in) :: x
test_asin = asin(x)
end function
REAL*8 function test_atan(x)
implicit none
REAL*8, intent(in) :: x
test_atan = atan(x)
end function
REAL*8 function test_cos(x)
implicit none
REAL*8, intent(in) :: x
test_cos = cos(x)
end function
REAL*8 function test_cosh(x)
implicit none
REAL*8, intent(in) :: x
test_cosh = cosh(x)
end function
REAL*8 function test_log(x)
implicit none
REAL*8, intent(in) :: x
test_log = log(x)
end function
REAL*8 function test_ln(x)
implicit none
REAL*8, intent(in) :: x
test_ln = log(x)
end function
REAL*8 function test_sin(x)
implicit none
REAL*8, intent(in) :: x
test_sin = sin(x)
end function
REAL*8 function test_sinh(x)
implicit none
REAL*8, intent(in) :: x
test_sinh = sinh(x)
end function
REAL*8 function test_sqrt(x)
implicit none
REAL*8, intent(in) :: x
test_sqrt = sqrt(x)
end function
REAL*8 function test_tan(x)
implicit none
REAL*8, intent(in) :: x
test_tan = tan(x)
end function
REAL*8 function test_tanh(x)
implicit none
REAL*8, intent(in) :: x
test_tanh = tanh(x)
end function
i   s   file.hsA  interface
REAL*8 function test_abs(x)
implicit none
REAL*8, intent(in) :: x
end function
end interface
interface
REAL*8 function test_acos(x)
implicit none
REAL*8, intent(in) :: x
end function
end interface
interface
REAL*8 function test_asin(x)
implicit none
REAL*8, intent(in) :: x
end function
end interface
interface
REAL*8 function test_atan(x)
implicit none
REAL*8, intent(in) :: x
end function
end interface
interface
REAL*8 function test_cos(x)
implicit none
REAL*8, intent(in) :: x
end function
end interface
interface
REAL*8 function test_cosh(x)
implicit none
REAL*8, intent(in) :: x
end function
end interface
interface
REAL*8 function test_log(x)
implicit none
REAL*8, intent(in) :: x
end function
end interface
interface
REAL*8 function test_ln(x)
implicit none
REAL*8, intent(in) :: x
end function
end interface
interface
REAL*8 function test_sin(x)
implicit none
REAL*8, intent(in) :: x
end function
end interface
interface
REAL*8 function test_sinh(x)
implicit none
REAL*8, intent(in) :: x
end function
end interface
interface
REAL*8 function test_sqrt(x)
implicit none
REAL*8, intent(in) :: x
end function
end interface
interface
REAL*8 function test_tan(x)
implicit none
REAL*8, intent(in) :: x
end function
end interface
interface
REAL*8 function test_tanh(x)
implicit none
REAL*8, intent(in) :: x
end function
end interface
(   Ru   RV   RW   RX   RY   RZ   R[   R\   R]   R^   R_   R`   Ra   Rb   Rc   Rd   R    R   RM   R5   (   RV   RW   RX   RY   RZ   R[   R\   R]   R^   R_   R`   Ra   Rb   Rc   Rd   R'   Rv   RN   RE   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_intrinsic_math_codegenă  s,    dBOc          C   sÝ   d d l  m }  t d  \ } } d |  | |  f d | | f g } t | d d d t d	 t } | d
 d
 d k s t  d } | d
 d | k s t  | d d
 d k sš t  d } | d d | k sŮ t  d  S(   Ni˙˙˙˙(   Rx   s   x,yRy   Rz   R°   R   R   R    i    s   file.f90s˙   REAL*8 function test_atan2(x, y)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(in) :: y
test_atan2 = atan2(x, y)
end function
REAL*8 function test_pow(x, y)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(in) :: y
test_pow = x**y
end function
i   s   file.hs  interface
REAL*8 function test_atan2(x, y)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(in) :: y
end function
end interface
interface
REAL*8 function test_pow(x, y)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(in) :: y
end function
end interface
(   Ru   Rx   R    R   RM   R5   (   Rx   R'   R+   Rv   RN   RE   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_intrinsic_math2_codegen  s    c    	      C   s;  d d l  m }  m } m } t d  \ } } } d |  |  | |  | |  d j   f d | | | | | | | | | | |         f g } t | d d d	 t d
 t } | d d d k sÝ t  d } | d d | k sý t  | d d d k st  d } | d d | k s7t  d  S(   Ni˙˙˙˙(   R_   RZ   Rb   s   x,y,zR|   i   R}   R°   R   R   R    i    s   file.f90s{  REAL*8 function test1(x, y, z)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(in) :: y
REAL*8, intent(in) :: z
test1 = sin(x)**7 + 7*sin(x)**6*cos(y) + 7*sin(x)**6*tan(z) + 21*sin(x) &
      **5*cos(y)**2 + 42*sin(x)**5*cos(y)*tan(z) + 21*sin(x)**5*tan(z) &
      **2 + 35*sin(x)**4*cos(y)**3 + 105*sin(x)**4*cos(y)**2*tan(z) + &
      105*sin(x)**4*cos(y)*tan(z)**2 + 35*sin(x)**4*tan(z)**3 + 35*sin( &
      x)**3*cos(y)**4 + 140*sin(x)**3*cos(y)**3*tan(z) + 210*sin(x)**3* &
      cos(y)**2*tan(z)**2 + 140*sin(x)**3*cos(y)*tan(z)**3 + 35*sin(x) &
      **3*tan(z)**4 + 21*sin(x)**2*cos(y)**5 + 105*sin(x)**2*cos(y)**4* &
      tan(z) + 210*sin(x)**2*cos(y)**3*tan(z)**2 + 210*sin(x)**2*cos(y) &
      **2*tan(z)**3 + 105*sin(x)**2*cos(y)*tan(z)**4 + 21*sin(x)**2*tan &
      (z)**5 + 7*sin(x)*cos(y)**6 + 42*sin(x)*cos(y)**5*tan(z) + 105* &
      sin(x)*cos(y)**4*tan(z)**2 + 140*sin(x)*cos(y)**3*tan(z)**3 + 105 &
      *sin(x)*cos(y)**2*tan(z)**4 + 42*sin(x)*cos(y)*tan(z)**5 + 7*sin( &
      x)*tan(z)**6 + cos(y)**7 + 7*cos(y)**6*tan(z) + 21*cos(y)**5*tan( &
      z)**2 + 35*cos(y)**4*tan(z)**3 + 35*cos(y)**3*tan(z)**4 + 21*cos( &
      y)**2*tan(z)**5 + 7*cos(y)*tan(z)**6 + tan(z)**7
end function
REAL*8 function test2(x, y, z)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(in) :: y
REAL*8, intent(in) :: z
test2 = cos(cos(cos(cos(cos(cos(cos(cos(x + y + z))))))))
end function
i   s   file.hs4  interface
REAL*8 function test1(x, y, z)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(in) :: y
REAL*8, intent(in) :: z
end function
end interface
interface
REAL*8 function test2(x, y, z)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(in) :: y
REAL*8, intent(in) :: z
end function
end interface
(	   Ru   R_   RZ   Rb   R    R~   R   RM   R5   (	   R_   RZ   Rb   R'   R+   R(   Rv   RN   RE   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_complicated_codegen_f95Ŕ  s    -Gc          C   s=  d d l  m }  m } d d l m } | d d t \ } } t |  d  \ } } } | d |  } | d |  }	 t d	 t | | | | |	 f | |	  f d
 d d t	 d t	 \ \ }
 } \ } } |
 d k sŰ t
  d } | | i d d 6k s| | i d d 6k st
  | d k s't
  | d k s9t
  d  S(   Ni˙˙˙˙(   R,   R-   (   R    s   n,mR1   t   AxyR2   R   R   R°   R   R   R    s   file.f90s~  subroutine matrix_vector(A, m, n, x, y)
implicit none
INTEGER*4, intent(in) :: m
INTEGER*4, intent(in) :: n
REAL*8, intent(in), dimension(1:m, 1:n) :: A
REAL*8, intent(in), dimension(1:n) :: x
REAL*8, intent(out), dimension(1:m) :: y
INTEGER*4 :: i
INTEGER*4 :: j
do i = 1, m
   y(i) = 0
end do
do i = 1, m
   do j = 1, n
      y(i) = %(rhs)s + y(i)
   end do
end do
end subroutine
s   A(i, j)*x(j)R   s   x(j)*A(i, j)s   file.hs  interface
subroutine matrix_vector(A, m, n, x, y)
implicit none
INTEGER*4, intent(in) :: m
INTEGER*4, intent(in) :: n
REAL*8, intent(in), dimension(1:m, 1:n) :: A
REAL*8, intent(in), dimension(1:n) :: x
REAL*8, intent(out), dimension(1:m) :: y
end subroutine
end interface
(   R7   R,   R-   Ru   R    R9   R8   R   R   RM   R5   (   R,   R-   R    R   R0   R.   R'   R+   R2   R   R   R   R   R   RE   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt
   test_loopsţ  s    Rc    
      C   sĐ   d d l  m }  m } t d d t d t \ } } |  d  } |  d  } | | |  } d i | j j d	 6| j d
 6} t d t	 | | | |   } t
   } t | j | g  }	 |	 | k sĚ t  d  S(   Ni˙˙˙˙(   R,   R-   s   i mR1   R   R'   R+   s>  subroutine test_dummies(m_%(mcount)i, x, y)
implicit none
INTEGER*4, intent(in) :: m_%(mcount)i
REAL*8, intent(in), dimension(1:m_%(mcount)i) :: x
REAL*8, intent(out), dimension(1:m_%(mcount)i) :: y
INTEGER*4 :: i_%(icount)i
do i_%(icount)i = 1, m_%(mcount)i
   y(i_%(icount)i) = x(i_%(icount)i)
end do
end subroutine
t   icountt   mcountR   (   R7   R,   R-   R    R9   R   R:   R   R   R   R   R#   R§   R5   (
   R,   R-   R2   R0   R'   R+   RE   R;   R   R   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_dummy_loops_f951  s    
 	c          C   sn  d d l  m }  m } d d l m } | d d t \ } } } } | d  \ } } }	 |  |  | | |  | | |  f } |  |  | | |  } |  |	  | | |  }	 t d t |	 |	 | |  f d d	 d
 t d t \ \ }
 } \ } } |
 d k st	  d } | | i d d 6k sF| | i d d 6k sFt	  | d k sXt	  | d k sjt	  d  S(   Ni˙˙˙˙(   R,   R-   (   R    s   i,j,n,mR1   s   A,x,yR   R°   R   R   R    s   file.f90sa  subroutine matrix_vector(A, m, n, x, y)
implicit none
INTEGER*4, intent(in) :: m
INTEGER*4, intent(in) :: n
REAL*8, intent(in), dimension(1:m, 1:n) :: A
REAL*8, intent(in), dimension(1:n) :: x
REAL*8, intent(inout), dimension(1:m) :: y
INTEGER*4 :: i
INTEGER*4 :: j
do i = 1, m
   do j = 1, n
      y(i) = %(rhs)s + y(i)
   end do
end do
end subroutine
s   A(i, j)*x(j)R   s   x(j)*A(i, j)s   file.hs  interface
subroutine matrix_vector(A, m, n, x, y)
implicit none
INTEGER*4, intent(in) :: m
INTEGER*4, intent(in) :: n
REAL*8, intent(in), dimension(1:m, 1:n) :: A
REAL*8, intent(in), dimension(1:n) :: x
REAL*8, intent(inout), dimension(1:m) :: y
end subroutine
end interface
(
   R7   R,   R-   Ru   R    R9   R   R   RM   R5   (   R,   R-   R    R2   R   R   R0   R.   R'   R+   R   R   R   R   RE   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_loops_InOutI  s     (Dc          C   sq  d d l  m }  m } d d l m } | d d t \ } } } } |  d d | | f } |  d  } |  d	  }	 | d
 | | d f  }
 | d |  } t d t |	 |
 | |
 | f | |  f d d d t d t \ \ } } \ } } d i d d 6t	 | d  d 6t	 d |  d 6t	 | d |  d 6} | | i d d 6k sm| | i d d 6k smt
  d  S(   Ni˙˙˙˙(   R,   R-   (   R    s   n m o pR1   R.   R   R'   R+   R2   i   R   R   R°   R   R   R    sß  subroutine matrix_vector(A, m, n, o, p, x, y)
implicit none
INTEGER*4, intent(in) :: m
INTEGER*4, intent(in) :: n
INTEGER*4, intent(in) :: o
INTEGER*4, intent(in) :: p
REAL*8, intent(in), dimension(1:m, 1:p) :: A
REAL*8, intent(in), dimension(1:n) :: x
REAL*8, intent(out), dimension(1:%(iup-ilow)s) :: y
INTEGER*4 :: i
INTEGER*4 :: j
do i = %(ilow)s, %(iup)s
   y(i) = 0
end do
do i = %(ilow)s, %(iup)s
   do j = 1, n
      y(i) = %(rhs)s + y(i)
   end do
end do
end subroutine
s   %(rhs)sR   i   t   iupi   t   ilows   iup-ilows   A(i, j)*x(j)s   x(j)*A(i, j)(   R7   R,   R-   Ru   R    R9   R   R   RM   t   strR5   (   R,   R-   R    R   R0   R   R   R.   R'   R+   R2   R   R   R   R   R   RE   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_partial_loops_fz  s$    Rc    	      C   s˝   d d l  m }  m } m } t d  \ } } } t d | | |  |   | |  g  } t   } | j | g d d t d t } | d d d	 k s t	  | d d
 d k sš t	  d  S(   Ni˙˙˙˙(   R_   RZ   R	   s   x,y,zR   R$   R   R    i    s   test.f90i   s~   REAL*8 function foo(x, y)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(out) :: y
y = sin(x)
foo = cos(x)
end function
(
   Ru   R_   RZ   R	   R    R   R   R   RM   R5   (	   R_   RZ   R	   R'   R+   R(   R;   R   RN   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_output_arg_fŠ  s    *	!c          C   s  d d l  m }  m } d d l m } | d d t \ } } t |  d  \ } } } | d |  } t   }	 t d t	 | | | d	   }
 t
 d
 t | | |
 | |    } t |	 j | g  } d } d } | | | k s| | | d  d  d  k st  d  S(   Ni˙˙˙˙(   R,   R-   (   R    s   n mR1   R¸   R2   t   funci   t   test_inlinesŰ   subroutine test_inline(m, x, y)
implicit none
INTEGER*4, intent(in) :: m
REAL*8, intent(in), dimension(1:m) :: x
REAL*8, intent(out), dimension(1:m) :: y
INTEGER*4 :: i
do i = 1, m
   y(i) = %s*%s
end do
end subroutine
s   x(i)s
   (x(i) + 1)(   s   x(i)s
   (x(i) + 1)(   R7   R,   R-   Ru   R    R9   R8   R   R   R   R   R   R#   R§   R5   (   R,   R-   R    R   R0   R.   R'   R+   R2   R   RĂ   RD   R   RE   t   args(    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_inline_functionť  s    	 &c          C   sv   t  d  }  d } x |  D] } | | 7} q Wt d |  } t   } t | j | g  } d } | | k sr t  d  S(   Ns   x:20i    R$   s  REAL*8 function test(x0, x1, x10, x11, x12, x13, x14, x15, x16, x17, x18, &
      x19, x2, x3, x4, x5, x6, x7, x8, x9)
implicit none
REAL*8, intent(in) :: x0
REAL*8, intent(in) :: x1
REAL*8, intent(in) :: x10
REAL*8, intent(in) :: x11
REAL*8, intent(in) :: x12
REAL*8, intent(in) :: x13
REAL*8, intent(in) :: x14
REAL*8, intent(in) :: x15
REAL*8, intent(in) :: x16
REAL*8, intent(in) :: x17
REAL*8, intent(in) :: x18
REAL*8, intent(in) :: x19
REAL*8, intent(in) :: x2
REAL*8, intent(in) :: x3
REAL*8, intent(in) :: x4
REAL*8, intent(in) :: x5
REAL*8, intent(in) :: x6
REAL*8, intent(in) :: x7
REAL*8, intent(in) :: x8
REAL*8, intent(in) :: x9
test = x0 + x1 + x10 + x11 + x12 + x13 + x14 + x15 + x16 + x17 + x18 + &
      x19 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9
end function
(   R    R   R   R#   R§   R5   (   R'   R&   t   symRD   R?   R"   RE   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_f_code_call_signature_wrapÖ  s    	c              s/   t  d  \    t t    f d    d  S(   Ns   x,Xc              s   t  d    f d d  S(   NR$   t   f95R   (   R   (    (   t   XR'   (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyR)      RP   (   R    R   R   (    (    (   RĘ   R'   sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_check_caseţ  s    c          C   s{   t  d  }  t  d d t } y t d |  | f d d  Wn8 t k
 rv } | j d j d  rw t d   qw n Xd  S(	   NR'   t   my_assumptionR$   RÉ   R   i    s   Fortran ignores case.s$   This exception should not be raised!(   R    R9   R   R   RĹ   t
   startswithR5   (   t   x1t   x2RĄ   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_check_case_false_positive  s    c          C   sv  t  d  \ }  } d d |  f g } t | d d t d t } t | d d d t d t } | d d | d d k s t  d |  | f } t | d d t d t } t | d d d t d t } | d d | d d k së t  d t |  | g |  | |  | g g  f } t | d	 d t d t } t | d	 d d t d t } | d d | d d k srt  d  S(
   Ns   x,yR   i   R°   R   R    i    i   Rt   (   R    R   RM   R5   R
   (   R'   R+   Rv   RN   t	   expresult(    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt    test_c_fortran_omit_routine_name  s    "",c          C   sŃ   t  d  \ }  } } |  | } t |  | g | d g g  } d | | f f } t | d d d t d t } | d d } d	 } | j   d
 }	 |	 j d  }
 |
 d } | i | d 6} | | k sÍ t  d  S(   Ns   x,y,zi   R$   RÉ   R   R    i    i   s2  REAL*8 function test(x, y, z, out_%(hash)s)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(in) :: y
REAL*8, intent(in) :: z
REAL*8, intent(out), dimension(1:2, 1:2) :: out_%(hash)s
out_%(hash)s(1, 1) = x
out_%(hash)s(2, 1) = z
out_%(hash)s(1, 2) = y
out_%(hash)s(2, 2) = 16
test = x + y
end function
i   t   _t   hash(   R    R
   R   RM   t
   splitlinest   splitR5   (   R'   R+   R(   t   e1t   e2Rv   RN   R"   RE   R*   RŁ   t   out(    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_fcode_matrix_output#  s    

c          C   sů   t  d  \ }  } } t  d  \ } } t d d d  } t | t d d |  g g   } t | |  | |  } t | d |   } d | | | g f }	 t |	 d d d	 t d
 t d |  | | | | | f }
 |
 d d } d } | | k ső t  d  S(   Ns   x,y,zs   B,CR.   i   i   i   R$   RÉ   R   R    R%   i    s!  subroutine test(x, z, y, C, A, B)
implicit none
REAL*8, intent(in) :: x
REAL*8, intent(in) :: z
REAL*8, intent(in) :: y
REAL*8, intent(out) :: C
REAL*8, intent(out) :: B
REAL*8, intent(out), dimension(1:1, 1:3) :: A
C = z*(x + y)
A(1, 1) = 1
A(1, 2) = 2
A(1, 3) = x
B = 2*x
end subroutine
(   R    R   R	   R
   R   RM   R5   (   R'   R+   R(   R/   RL   R.   RQ   RR   R   Rv   RN   R"   RE   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt    test_fcode_results_named_ordered@  s    !c          C   sđ   t  d d d  }  t  d d d  } t  d d d  } t  d d d  } d t | |  d	 d  d   f  t | |  d d  d   f  t | |  d  d   d f  g f } t | d
 d d t d t } | d	 d } d } | | k sě t  d  S(   NR.   i   i   R/   i   RL   R   R$   i    RÉ   R   R    s  subroutine test(A, B, C, D)
implicit none
REAL*8, intent(in), dimension(1:2, 1:3) :: A
REAL*8, intent(out), dimension(1:1, 1:3) :: B
REAL*8, intent(out), dimension(1:1, 1:3) :: C
REAL*8, intent(out), dimension(1:2, 1:1) :: D
B(1, 1) = A(1, 1)
B(1, 2) = A(1, 2)
B(1, 3) = A(1, 3)
C(1, 1) = A(2, 1)
C(1, 2) = A(2, 2)
C(1, 3) = A(2, 3)
D(1, 1) = A(1, 3)
D(2, 1) = A(2, 3)
end subroutine
(   R   R	   R   RM   R5   (   R.   R/   RL   R   Rv   RN   R"   RE   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_fcode_matrixsymbol_slice^  s    %c          C   s°   t  d d d  }  d |  d  d   d f f } t | d d d t d t } | d	 d } d
 } | j   d } | j d  } | d } | i | d 6} | | k sŹ t  d  S(   NR.   i   i   R$   i   RÉ   R   R    i    sŢ   subroutine test(A, out_%(hash)s)
implicit none
REAL*8, intent(in), dimension(1:2, 1:3) :: A
REAL*8, intent(out), dimension(1:2, 1:1) :: out_%(hash)s
out_%(hash)s(1, 1) = A(1, 2)
out_%(hash)s(2, 1) = A(2, 2)
end subroutine
RÓ   RÔ   (   R   R   RM   RŐ   RÖ   R5   (   R.   Rv   RN   R"   RE   R*   RŁ   RŮ   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt&   test_fcode_matrixsymbol_slice_autoname|  s    	
c       
   C   sË   t  d  \ }  } } } t d |  | f d d t d t d | f } | d d } d	 } | | k sl t  d
 } t d |  | | f d d t d t d | | f } | d d } | | k sÇ t  d  S(   Ns   x y z tt   fR°   R   R    t   global_varsi    i   sP   REAL*8 function f(x)
implicit none
REAL*8, intent(in) :: x
f = x*y
end function
s   #include "f.h"
#include <math.h>
double f(double x, double y) {
   double f_result;
   f_result = x*y + z;
   return f_result;
}
RL   (   R    R   RM   R5   (   R'   R+   R(   t   tRN   R"   RE   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_global_vars  s    "&c    
      C   s.  d d l  m }  d d l m } |  d i i d d 6d 6 } t d  \ } } | | |  } t d	 | d
 d g  } d } t d | f d t d t d | } | d d }	 |	 | k sÁ t  t d	 |  } | j	 j
 d  d } t d | f d t d t d | } | d d }	 |	 | k s*t  d  S(   Ni˙˙˙˙(   t   C99CodePrinter(   t   expt   settingst   fastexpRă   t   user_functionss   x yt   printert   preprocessor_statementss   #include "fastexp.h"s   #include "expr.h"
#include "fastexp.h"
double expr(double x, double y) {
   double expr_result;
   expr_result = fastexp(x + y);
   return expr_result;
}
R&   R   R    R?   i    i   sŹ   #include "expr.h"
#include <math.h>
#include "fastexp.h"
double expr(double x, double y) {
   double expr_result;
   expr_result = fastexp(x + y);
   return expr_result;
}
(   t   sympy.printing.ccodeRâ   t&   sympy.functions.elementary.exponentialRă   R    R   R   RM   R5   Rč   t   append(
   Râ   Ră   Rç   R'   R+   R&   t   genRE   RN   R"   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_custom_codegenŽ  s"    	$
$c       
   C   s   d d l  m }  d |  f d     Y} t d  } | d } d d g } t d | f d d d t d t d |   } | | k s t  d  S(   Ni˙˙˙˙(   Râ   t   CustomPrinterc           B   s   e  Z d    Z RS(   c         S   s(   d j  |  j | j  |  j | j   S(   Ns   fastpow({}, {})(   t   formatt   _printt   baseRă   (   t   selfR&   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt
   _print_Powŕ  s    (   t   __name__t
   __module__Ró   (    (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyRî   ß  s   R'   i   s   file.cs   #include "file.h"
#include <math.h>
double test(double x) {
   double test_result;
   test_result = fastpow(x, 3);
   return test_result;
}
s   file.hsP   #ifndef PROJECT__FILE__H
#define PROJECT__FILE__H
double test(double x);
#endif
R$   RL   R   R   R    Rç   (   s   file.cs   #include "file.h"
#include <math.h>
double test(double x) {
   double test_result;
   test_result = fastpow(x, 3);
   return test_result;
}
(   s   file.hsP   #ifndef PROJECT__FILE__H
#define PROJECT__FILE__H
double test(double x);
#endif
(   Ré   Râ   R    R   RM   R5   (   Râ   Rî   R'   R&   RE   RN   (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   test_c_with_printerÜ  s    
  	-N(X   t
   sympy.coreR    R   R   R   R   R   t   sympy.core.compatibilityR   Ru   R   R   R	   t   sympy.matricesR
   R   t   sympy.utilities.codegenR   R   R   R   R   R   R   R   R   R   R   t   sympy.utilities.pytestR   t   sympy.utilities.lambdifyR   RM   R#   R=   R@   RA   RC   RF   RG   RI   RJ   RK   RO   RS   RU   Rw   R{   R   R   R   R   R   R   R   R    RŚ   R¨   RŠ   RŞ   RŤ   RŹ   R­   RŽ   RŻ   Rą   R˛   Rł   Rľ   Rś   Rˇ   Rš   Rź   R˝   RÁ   RÂ   RĆ   RČ   RË   RĐ   RŇ   RÚ   RŰ   RÜ   RÝ   Rá   Rí   Rö   (    (    (    sA   lib/python2.7/site-packages/sympy/utilities/tests/test_codegen.pyt   <module>   s|   .L													8		D	*		,																	Ż	.	>	3		1	/			(									.