
    bi	                         d Z ddlZddlmZmZ ddlmZ  ed      Z ed      Zd Z	d Z
d	eegef   d
eegef   fdZy)a,  
Copyright 2013 Steven Diamond

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
    N)CallableTypeVar)scopesRTc                 T     t         t        j                          fd              }|S )z+Wraps a property so it is lazily evaluated.c                     t        j                         rdj                  z   }ndj                  z   }	 t        | |      S # t        $ r t        | | |              Y nw xY wt        | |      S )N
_lazy_dpp__lazy_)r   dpp_scope_active__name__getattrAttributeErrorsetattr)self	attr_namefuncs     \/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/cvxpy/utilities/performance_utils.py	_lazypropzlazyprop.<locals>._lazyprop   sk     ""$$t}}4I 4==0I	14++ 	1D)T$Z0	1tY''s   A A! A!)property	functoolswraps)r   r   s   ` r   lazypropr      s0     __T
(  
(     c                     | t        t        |j                                     z   }t        j                         rd|z   }|S )N)__dpp_scope_active__)tuplelistitemsr   r   )argskwargskeys      r   
_cache_keyr#   ,   s7    
tFLLN+,
,C '#-Jr   r   returnc                 P     t        j                         dt        f fd       }|S )a  Computes an instance method caches the result.

    A result is stored for each unique combination of arguments and
    keyword arguments. Similar to functools.lru_cache, except this works
    decorator works for instance methods (functools.lru_cache decorates
    functions, not methods; using it on a method leaks memory.)

    This decorator should not be used when there are an unbounded or very
    large number of argument and keyword argument combinations.
     r$   c                     j                   dz   }t        | |      st        | |i        t        | |      }t	        ||      }||v r||   S  | g|i |}|||<   |S )N	__cache__)r   hasattrr   r   r#   )r   r    r!   
cache_namecacher"   resultr   s          r   _compute_oncez#compute_once.<locals>._compute_once?   sr    ]][0
tZ(D*b)j)v&%<:d,T,V,c
r   )r   r   r   )r   r,   s   ` r   compute_oncer-   3   s/     __T   r   )__doc__r   typingr   r   cvxpy.utilitiesr   r   r   r   r#   r-    r   r   <module>r2      sZ     $ "CLCL&xQ' HaS!V,< r   