
    vh#                    |   U d dl mZ d dlmZ d dlZd dlZd dlZd dlZd dlZd dl	m
Z
mZmZ d dlmZ d dlmZ d dlmZ  eded	e
f   
      Zeej&                  gZded<   d#dZdZd$dZd%dZd&dZd%dZd'dZd(dZd)dZd*dZd+dZ d,dZ! G d de"      Z#dZ$ G d de"      Z%de%_&        d-dZ'd-d Z(d.d!Z)d/d"Z*y)0    )annotations)CallableN)AnyTypeVarcast)config)util)_jaxC.)boundz	list[str]_exclude_pathsc                .    t         j                  |        y N)r   append)paths    R/opt/face_recognition/venv/lib/python3.12/site-packages/jax/_src/traceback_util.pyregister_exclusionr   "   s        zThe stack trace below excludes JAX-internal frames.
The preceding is the original exception that occurred, unmodified.

--------------------c                N   t         j                  j                  |       } t         j                  j                  |      }	 t         j                  j                  | |g      }	 ||k(  xs  t         j                  j                  ||      S # t        $ r Y yw xY w# t        $ r Y yw xY w)NF)osr   abspath
commonpath
ValueErrorsamefileOSError)r   path_prefixcommons      r   _path_starts_withr   *   s    		$,+WW{ 34F[ IBGG$4$4V[$II 
  	 
 s$    !B	 "&B 		BB	B$#B$c                @    t        | j                  j                        S r   )include_filenamef_codeco_filenamefs    r   include_framer%   :   s    	!((..	//r   c                6     t         fdt        D               S )Nc              3  6   K   | ]  }t        |        y wr   )r   ).0r   filenames     r   	<genexpr>z#include_filename.<locals>.<genexpr>>   s     Nt"8T2Ns   )anyr   )r)   s   `r   r    r    =   s    N~NN	NNr   c                2    d| j                   j                  v S )Nzimportlib._bootstrap)r!   r"   r#   s    r   _ignore_known_hidden_framer-   C   s    	188#7#7	77r   c                t    t        j                  |       D ]   \  }}t        |      rd|j                  d<   " y )NT__tracebackhide__)	tracebackwalk_tbr%   f_locals)tbr$   _linenos      r   #_add_tracebackhide_to_hidden_framesr5   F   s7    %%b) -ja(,ajj$%-r   c                    d }t        t        j                  |             }t        |      D ]3  \  }}t	        |      st        j                  |||j                  |      }5 |S r   )listr0   r1   reversedr%   typesTracebackTypef_lasti)r3   outframesr$   linenos        r   filter_tracebackr?   K   s]    #	!!"%&&F# ;iaQQ		6:c; 
*r   c                B   | }d}t        j                  | j                        D ]x  \  }}t        |      r|r|j                  j
                  dk7  r |S t        |      r"t        j                  |||j                  |      }|j                  j
                  dk(  swd}z |S )NFz<module>T)
r0   
walk_stacktb_framer-   r!   co_namer%   r9   r:   r;   )r3   r<   reached_module_levelr$   r>   s        r   _add_call_stack_framesrE   T   s     	#''4 "ia!!$ 0 0J >
 
*	 QQ		6:cxx:%!" 
*r   c                J    | j                   t        k(  xr | j                  dk(  S )Nreraise_with_filtered_traceback)r)   __file__namer#   s    r   _is_reraiser_framerJ   l   s%    
**
  6
&&5
57r   c                    | j                   yt        j                  | j                   j                        }t	        d |d d D              S )NFc              3  2   K   | ]  }t        |        y wr   )rJ   )r(   r$   s     r   r*   z%_is_under_reraiser.<locals>.<genexpr>t   s     4q"4s   )__traceback__r0   extract_stackrB   r+   )er3   s     r   _is_under_reraiserrQ   p   s@    __q778"	4BsG4	44r   c                z    dj                  t        j                  t        |       |             j	                         S )N )joinr0   format_exception_onlytypestrip)rP   s    r   rU   rU   v   s+    	00a!<	=	C	C	EEr   c                      e Zd Zy)UnfilteredStackTraceN)__name__
__module____qualname__ r   r   rY   rY   y   s    r   rY   zFor simplicity, JAX has removed its internal frames from the traceback of the following exception. Set JAX_TRACEBACK_FILTERING=off to include these.c                      e Zd Zd Zy)SimplifiedTracebackc                    t         S r   )_simplified_tb_msg)selfs    r   __str__zSimplifiedTraceback.__str__   s    r   N)rZ   r[   r\   rc   r]   r   r   r_   r_      s    r   r_   z
jax.errorsc                 8    	 t                y# t        $ r Y yw xY w)z6Returns true if we appear to be in an IPython session.TF)get_ipython	NameErrorr]   r   r   _running_under_ipythonrg      s!    M	 s   
 	c                 .    ddl } | j                  dd dk\  S )z?Returns true if the IPython version supports __tracebackhide__.r   N   )      )IPythonversion_info)rl   s    r   _ipython_supports_tracebackhidern      s    			bq	!W	,,r   c                 |    t         j                  j                  } | | dk(  rt               rt	               rd} | S d} | S )Nautotracebackhidequiet_remove_frames)r   traceback_filteringvaluerg   rn   )modes    r   _filtering_moderv      sB    		#	#	)	)$	\TV^ %D%Fd 
+ #d	+r   c                ^     t        j                          fd       }t        t        |      S )a  Wraps ``fun`` to form a boundary for filtering exception tracebacks.

  When an exception occurs below ``fun``, this appends to it a custom
  ``__cause__`` that carries a filtered traceback. The traceback imitates the
  stack trace of the original exception, but with JAX-internal frames removed.

  This boundary annotation works in composition with itself. The topmost frame
  corresponding to an :func:`~api_boundary` is the one below which stack traces
  are filtered. In other words, if ``api_boundary(f)`` calls
  ``api_boundary(g)``, directly or indirectly, the filtered stack trace provided
  is the same as if ``api_boundary(f)`` were to simply call ``g`` instead.

  This annotation is primarily useful in wrapping functions output by JAX's
  transformations. For example, consider ``g = jax.jit(f)``. When ``g`` is
  called, JAX's JIT compilation machinery is invoked, which in turn calls ``f``
  in order to trace and translate it. If the function ``f`` raises an exception,
  the stack unwinds through JAX's JIT internals up to the original call site of
  ``g``. Because the function returned by :func:`~jax.jit` is annotated as an
  :func:`~api_boundary`, such an exception is accompanied by an additional
  traceback that excludes the frames specific to JAX's implementation.
  c                    d}	  
| i |S # t         $ ri}t               }t        |      s|dk(  r |dk(  rt        |j                          d\  }}	 |j                  }t        |      }|j                  |       t        t        d      rt        j                  |       t        j                  dk\  r|dk(  r|j                  dt        z           |dk(  rt               }nP|d	k(  r<t        |      }	|	 d
t          }	t#        |	      }|j                  t%        |             nt'        d| d      |j(                  |_        |j*                  |_        |j,                  |_        ||_        d |_         # ~~~w xY wd }~ww xY w)NToffrq   )NNreplace_thread_exc_traceback)      rr   z--------------------
remove_framesz

zJAX_TRACEBACK_FILTERING=z is not a valid value.)	Exceptionrv   rQ   r5   rN   r?   with_tracebackhasattrr
   rz   sysrm   add_notera   r_   rU   _jax_message_appendrY   rE   r   	__cause____context____suppress_context__)argskwargsr/   rP   ru   filtered_tb
unfilteredr3   	jax_errormsgfuns             r   rG   z5api_boundary.<locals>.reraise_with_filtered_traceback   s   1$!&!! /d	A	$%-		 +AOO< *k:&__&r*	% 478 
+
+K
8w&43H+H
**-0BB
C$ 	! ** ,-I&'*CE123C,S1I$$%;B%?@7v=STUU !)
"#--)
+,+A+A)
(!!+!-_/s'    
F ;E;D E33E88E;;F )	functoolswrapsr   r   )r   rG   s   ` r   api_boundaryr      s1    . ??33 3h 
a0	11r   )r   str)r   r   r   r   returnbool)r$   ztypes.FrameTyper   r   )r)   r   r   r   )r3   types.TracebackType)r3   r   r   ztypes.TracebackType | None)r3   r   r   r   )r$   ztraceback.FrameSummaryr   r   )rP   BaseExceptionr   r   )rP   r   r   r   )r   r   )r   r   )r   r   r   r   )+
__future__r   collections.abcr   r   r   r   r0   r9   typingr   r   r   jax._srcr   r	   jax._src.libr
   r   rH   r   __annotations__r   r   r   r%   r    r-   r5   r?   rE   rJ   rQ   rU   r~   rY   ra   r_   r[   rg   rn   rv   r   r]   r   r   <module>r      s    # $  	 
   % %    CxS)*%t}}5	 5 
 0O8-
075F ,9 +F )  ".  -
L2r   