
    ph                     J    S r SSKrSSKrSSKJrJrJr  SS jr " S S5      r	g)	z)
Decorators and objects for memoization.
    N   )config	constantsdbc                    ^  U 4S jnU$ )zNDecorator for memoizing a function using either the filesystem or a
database.
c                    >^ ^^ [         R                  R                  T TS9m[        T T5      m[        R
                  " T 5      UU U4S j5       nU$ )N)ignorec                     > TR                   S:X  a  [        R                  (       d  TnO-[        R                  S:X  a  TnO[        R                  S:X  a  TnW" U 0 UD6$ )z9Dynamically choose the cache at call-time, not at import._siafsr   )__name__r   
CACHE_SIASCACHING_BACKEND)argskwargsf	db_cachedfuncjoblib_cacheds      F/home/james-whalen/.local/lib/python3.13/site-packages/pyphi/memory.pywrapper)cache.<locals>.decorator.<locals>.wrapper   sT     }}&v/@/@''4/!''4/d%f%%    )r   joblib_memorycacheDbMemoizedFunc	functoolswraps)r   r   r   r   r	   s   ` @@r   	decoratorcache.<locals>.decorator   sL    !//55d65J"40				& 
	& r    )r	   r   s   ` r   r   r      s    " r   c                   0    \ rS rSrSrS rS rS rS rSr	g)	r   *   z6A memoized function, with a databse backing the cache.c                 |   ^ ^ TT l         Ub  UO/ T l        [        R                  " T5      UU 4S j5       nUT l        g )Nc                     > TR                  X5      n[        R                  " U5      nUb  U$ T" U 0 UD6n[        R                  " X$5        U$ N)get_output_keyr   findinsert)r   r   keycached_valueresultr   selfs        r   r   (DbMemoizedFunc.__init__.<locals>.wrapper4   sL    %%d3C773<L'##4*6*FIIc"Mr   )r   r	   r   r   _memoized_func)r-   r   r	   r   s   ``  r   __init__DbMemoizedFunc.__init__-   s?    	 & 2f 
		 
	 &r   c                 &    U R                   " U0 UD6$ r&   )r/   r-   r   r   s      r   __call__DbMemoizedFunc.__call__E   s    ""D3F33r   c                     [         R                  R                  U R                  U R                  X5      n[        [        UR                  5       5      5      n[        R                  " U5      $ )z}Return the key that the output should be cached with, given
arguments, keyword arguments, and a list of arguments to ignore.
)
joblibfunc_inspectfilter_argsr   r	   tuplesortedvaluesr   generate_key)r-   r   r   filtered_argss       r   r'   DbMemoizedFunc.get_output_keyI   sR     ++77IIt{{D2 f]%9%9%;<=}--r   c                 L    [         R                  " U R                  X5      5      $ )zReturn cached output.)r   r(   r'   r3   s      r   load_outputDbMemoizedFunc.load_outputV   s    wwt**4899r   )r/   r   r	   N)
r   
__module____qualname____firstlineno____doc__r0   r4   r'   rA   __static_attributes__r!   r   r   r   r   *   s    @&04.:r   r   r&   )
rF   r   joblib.func_inspectr7    r   r   r   r   r   r!   r   r   <module>rJ      s'   
   # #0.: .:r   