
    g                         d Z ddlmZ ddlmZ  G d de          Z e            Zej        Zej	        Z	ddl
mZmZ d Zd Zd	 ZddZ edd                                          Z edd          Ze                                dk    rd
Zn'	  ee          Zn# e$ r  eddez  z             w xY wedk    reZn2edk    r ee          Zn edk    r ee          Zn edez            d ZdededefdZd
S )z Caching facility for SymPy     )import_module)Callablec                       e Zd ZdZd Zd ZdS )_cachez List of cached functions c                     | D ]i}|j         }|}t          |d          r<t          |d          r|                                }n|j        }t          |d          <d}t	          ||           jdS )zprint cache info__wrapped__
cache_infoN)__name__hasattrr	   r   print)selfitemnamemyfuncinfos        L/var/www/html/ai-engine/env/lib/python3.11/site-packages/sympy/core/cache.pyprint_cachez_cache.print_cache   s      	 	D=DF&-00 6<00 0!,,..D#/F &-00  $	 	    c                     | D ]P}|}t          |d          r<t          |d          r|                                 n|j        }t          |d          <QdS )zclear cache contentr   cache_clearN)r   r   r   )r   r   r   s      r   clear_cachez_cache.clear_cache   sv     	0 	0DF&-00 06=11 0&&(((#/F &-00 0	0 	0r   N)r
   
__module____qualname____doc__r   r    r   r   r   r      s8        $$  "	0 	0 	0 	0 	0r   r   )	lru_cachewrapsc                       fd}|S )a  caching decorator.

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


        Examples
        ========

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

        >>> @cacheit
        ... def f(a, b): # noqa: F811
        ...    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                       t          d                     t                      fd            }j        |_        j        |_        t                              |           |S )NT)typedc                      	  | i |}nG# t           $ r:}|j        r |j        d                             d          s  | i |}Y d }~nd }~ww xY w|S )Nr   zunhashable type:)	TypeErrorargs
startswith)r#   kwargsretvalecfuncfuncs       r   wrapperz0__cacheit.<locals>.func_wrapper.<locals>.wrapperE   s    //// / / /v QVAY%9%9:L%M%M t.v../ Ms    
A0AA)r   r   r	   r   CACHEappendr)   r*   r(   maxsizes   ` @r   func_wrapperz__cacheit.<locals>.func_wrapperB   s~    .	'...t44	t	 	 	 	 	 
	 #-#/Wr   r   r.   r/   s   ` r   	__cacheitr1   -   s$    *    & r   c                     | S Nr   )r)   s    r   __cacheit_nocacher4   Y   s    Kr   c                       fd}|S )z)cacheit + code to check cache consistencyc                 r      t                               t                      fd            }|S )Nc                       | i |} | i |}t          |          t          |          f ||k    rt          d          |S )Nz Returned values are not the same)hashRuntimeError)r#   kw_argsr1r2r(   r)   s       r   r*   z6__cacheit_debug.<locals>.func_wrapper.<locals>.wrapperb   se     t'w''B(((B HHd2hh Rxx"#EFFFIr   )r1   r   r-   s   ` @r   r/   z%__cacheit_debug.<locals>.func_wrapper_   sQ    "	'""4((	t	 	 	 	 	 
	( r   r   r0   s   ` r   __cacheit_debugr=   ]   s$        2 r   Nc                 &    ddl m}  || |          S )Nr   )getenv)osr?   )keydefaultr?   s      r   _getenvrC   {   s&    6#wr   SYMPY_USE_CACHEyesSYMPY_CACHE_SIZE1000nonez2SYMPY_CACHE_SIZE must be a valid integer or None. zGot: %snodebugz*unrecognized value for SYMPY_USE_CACHE: %sc                 d     d j         z   t                       fd}t          |          S )z"Decorator to cache property method__c                 j    t          |           }|u r |           }t          | |           |S r3   )getattrsetattr)r   val_cached_property_sentinelattrnamer)   s     r   propfuncz!cached_property.<locals>.propfunc   sE    dH&?@@+++$t**CD(C(((
r   )r
   objectproperty)r)   rS   rQ   rR   s   ` @@r   cached_propertyrV      sN    dm#H &       Hr   moduler   returnc                      d fd G  fddt                     } G  fdd|          } |            S )zCreate a lazy proxy for a function in a module.

    The module containing the function is not imported until the function is used.

    Nc                  F     t          t                                S r3   rN   r   )r)   rW   r   s   r   _get_functionz$lazy_function.<locals>._get_function   s$    <=00$77Dr   c                   .    e Zd Ze fd            ZdS )'lazy_function.<locals>.LazyFunctionMetac                 X                 j         }|d| j        j         d d dz  }|S Nz

Note: this is a z wrapper of '.'r   	__class__r
   r   	docstringr\   rW   r   s     r   r   z/lazy_function.<locals>.LazyFunctionMeta.__doc__   D    %/If0GffV\ff_cffffIr   N)r
   r   r   rU   r   )r\   rW   r   s   r   LazyFunctionMetar^      sB        		 	 	 	 	 	 
	 	 	r   rh   c                   Z     e Zd ZfdZefd            ZfdZ fdZ xZS )#lazy_function.<locals>.LazyFunctionc                 R    t          t                               |i |S r3   r[   )r   r#   r%   r)   rW   r   s      r   __call__z,lazy_function.<locals>.LazyFunction.__call__   s6     |}V44d;;4((((r   c                 X                 j         }|d| j        j         d d dz  }|S r`   rc   re   s     r   r   z+lazy_function.<locals>.LazyFunction.__doc__   rg   r   c                 <                                                  S r3   )__str__)r   r\   s    r   ro   z+lazy_function.<locals>.LazyFunction.__str__   s     =??**,,,r   c           	      H    dj          dt          |           dd d d	S )N<z object at 0xxz>: wrapping 'ra   rb   )r
   id)r   rd   rW   r   s    r   __repr__z,lazy_function.<locals>.LazyFunction.__repr__   s:    ay)aa4aaaQWaaZ^aaaar   )	r
   r   r   rl   rU   r   ro   rt   __classcell__)rd   r\   r)   rW   r   s   @r   LazyFunctionrj      s        	) 	) 	) 	) 	) 	) 	) 
	 	 	 	 	 	 
	
	- 	- 	- 	- 	-	b 	b 	b 	b 	b 	b 	b 	b 	b 	b 	br   rv   )	metaclass)type)rW   r   rh   rv   r\   r)   s   ``  @@r   lazy_functionry      s     D              4   b b b b b b b b b b!1 b b b b( <>>r   r3   )r   	importlibr   typingr   listr   r+   r   r   	functoolsr   r   r1   r4   r=   rC   lower	USE_CACHEscsrF   int
ValueErrorr9   cacheitrV   strry   r   r   r   <module>r      s&   " " # # # # # #      0 0 0 0 0T 0 0 0B 	 & & & & & & & &( ( (X    <       
 G%u--3355	
 g &))99;;&*3s88 * * *l@(()* * 	**
 GG%i())GG'o.//GG
,4y@B B B
 
 
*3 *s *x * * * * * *s   B B3