ó
¡¼™\c           @  sC  d  Z  d d l m Z m Z d d l m Z d e f d „  ƒ  YZ e ƒ  Z	 e	 j
 Z
 e	 j Z d d l m Z d d l m Z y¬ d d l Z d d	 l m Z e e d
 ƒ sÁ e d e ƒ e ‚ n  e e j ƒ d k  rø e d j e j ƒ e ƒ e ‚ n  d d l Z e j ƒ  d k re ‚ n  e j Z Wn e k
 rEd „  Z n
 Xd „  Z d „  Z d „  Z d d „ Z e d d ƒ j  ƒ  Z! e d d ƒ Z" e" j  ƒ  d k r¬d Z# n8 y e$ e" ƒ Z# Wn% e% k
 rãe& d d e# ƒ ‚ n Xe! d k rùe Z' nF e! d k re e# ƒ Z' n+ e! d k r/e e# ƒ Z' n e& d e! ƒ ‚ d S(   s    Caching facility for SymPy iÿÿÿÿ(   t   print_functiont   division(   t   LooseVersiont   _cachec           B  s    e  Z d  Z d „  Z d „  Z RS(   s    List of cached functions c         C  su   xn |  D]f } | j  } | } xA t | d ƒ rY t | d ƒ rM | j ƒ  } Pq | j } q Wd } t | | ƒ q Wd S(   s   print cache infot   __wrapped__t
   cache_infoN(   t   __name__t   hasattrR   R   t   Nonet   print(   t   selft   itemt   namet   myfunct   info(    (    s/   lib/python2.7/site-packages/sympy/core/cache.pyt   print_cache	   s    	c         C  sW   xP |  D]H } | } x9 t  | d ƒ rN t  | d ƒ rB | j ƒ  Pq | j } q Wq Wd S(   s   clear cache contentR   t   cache_clearN(   R   R   R   (   R
   R   R   (    (    s/   lib/python2.7/site-packages/sympy/core/cache.pyt   clear_cache   s    
(   R   t
   __module__t   __doc__R   R   (    (    (    s/   lib/python2.7/site-packages/sympy/core/cache.pyR      s   	(   t	   lru_cache(   t   update_wrapperN(   t   warnt   __version__s#   fastcache version >= 0.4.0 requireds   0.4.0s0   fastcache version >= 0.4.0 required, detected {}t   PyPyc           s   ‡  f d †  } | S(   s  caching decorator.

           important: the result of cached function must be *immutable*


           Examples
           ========

           >>> from sympy.core.cache import cacheit
           >>> @cacheit
           ... def f(a, b):
           ...    return a+b

           >>> @cacheit
           ... def f(a, b):
           ...    return [a, b] # <-- WRONG, returns mutable object

           to force cacheit to check returned results mutability and consistency,
           set environment variable SYMPY_USE_CACHE to 'debug'
        c           sl   t  ˆ d t ƒˆ ƒ ‰  ‡  ‡ f d †  } ˆ  j | _ ˆ  j | _ t | ˆ ƒ ˆ  j | _ t j | ƒ | S(   Nt   typedc            s:   y ˆ  |  | Ž  } Wn  t  k
 r5 ˆ |  | Ž  } n X| S(   N(   t	   TypeError(   t   argst   kwargst   retval(   t   cfunct   func(    s/   lib/python2.7/site-packages/sympy/core/cache.pyt   wrapper\   s
    (   R   t   TrueR   R   R   R   t   CACHEt   append(   R   R    (   t   maxsize(   R   R   s/   lib/python2.7/site-packages/sympy/core/cache.pyt   func_wrapperW   s    (    (   R$   R%   (    (   R$   s/   lib/python2.7/site-packages/sympy/core/cache.pyt	   __cacheitB   s    c           s   ‡  f d †  } | S(   s  caching decorator.

           important: the result of cached function must be *immutable*


           Examples
           ========

           >>> from sympy.core.cache import cacheit
           >>> @cacheit
           ... def f(a, b):
           ...    return a+b

           >>> @cacheit
           ... def f(a, b):
           ...    return [a, b] # <-- WRONG, returns mutable object

           to force cacheit to check returned results mutability and consistency,
           set environment variable SYMPY_USE_CACHE to 'debug'
        c           s2   t  j ˆ  d t d d ƒ|  ƒ } t j | ƒ | S(   NR   t
   unhashablet   ignore(   t	   fastcachet
   clru_cacheR!   R"   R#   (   R   R   (   R$   (    s/   lib/python2.7/site-packages/sympy/core/cache.pyR%   ‰   s    !(    (   R$   R%   (    (   R$   s/   lib/python2.7/site-packages/sympy/core/cache.pyR&   t   s    c         C  s   |  S(   N(    (   R   (    (    s/   lib/python2.7/site-packages/sympy/core/cache.pyt   __cacheit_nocache“   s    c           s   ‡  f d †  } | S(   s)   cacheit + code to check cache consistencyc           sD   d d l  m } t ˆ ƒ ˆ ƒ ‰  | ˆ ƒ ‡  ‡ f d †  ƒ } | S(   Ni   (   t   wrapsc            sS   ˆ |  | Ž  } ˆ  |  | Ž  } t  | ƒ t  | ƒ f | | k rO t d ƒ ‚ n  | S(   Ns    Returned values are not the same(   t   hasht   RuntimeError(   R   t   kw_argst   r1t   r2(   R   R   (    s/   lib/python2.7/site-packages/sympy/core/cache.pyR    ž   s    (   t
   decoratorsR,   R&   (   R   R,   R    (   R$   (   R   R   s/   lib/python2.7/site-packages/sympy/core/cache.pyR%   ™   s    (    (   R$   R%   (    (   R$   s/   lib/python2.7/site-packages/sympy/core/cache.pyt   __cacheit_debug—   s    c         C  s   d d l  m } | |  | ƒ S(   Niÿÿÿÿ(   t   getenv(   t   osR4   (   t   keyt   defaultR4   (    (    s/   lib/python2.7/site-packages/sympy/core/cache.pyt   _getenv·   s    t   SYMPY_USE_CACHEt   yest   SYMPY_CACHE_SIZEt   1000t   nones2   SYMPY_CACHE_SIZE must be a valid integer or None. s   Got: %st   not   debugs*   unrecognized value for SYMPY_USE_CACHE: %s((   R   t
   __future__R    R   t   distutils.versionR   t   Vt   listR   R"   R   R   t   sympy.core.compatibilityR   t	   functoolsR   R)   t   warningsR   R   t   UserWarningt   ImportErrorR   t   formatt   platformt   python_implementationR*   R&   R+   R3   R   R8   t   lowert	   USE_CACHEt   scsR;   t   intt
   ValueErrorR.   t   cacheit(    (    (    s/   lib/python2.7/site-packages/sympy/core/cache.pyt   <module>   s\    							2			 		