Ë
    ßGìjW=  ã                  óú  — d dl mZ d dlmZmZ d dlmZmZmZ d dl	m
Z
  ed«      Zddœdd„Z	 d	 	 	 dd	„Z	 d	 	 	 dd
„Zddœ	 	 	 	 	 	 	 dd„Zeddœ	 	 	 	 	 dd„«       Ze	 d	 	 	 	 	 	 	 d d„«       Ze
j"                  df	 	 	 	 	 	 	 d!d„Z e
j$                  «       ddœ	 	 	 	 	 	 	 	 	 d"d„Z	 d	 	 	 d#d„Z	 	 	 	 	 	 d$d„Z	 	 	 	 d%d„Z	 	 d&	 	 	 	 	 	 	 d'd„Z	 	 d&	 	 	 	 	 	 	 d(d„Zdddœ	 	 	 	 	 	 	 	 	 	 	 d)d„Z	 d	 	 	 d*d„Zy)+é    )Úannotations)ÚCallableÚIterable)ÚAnyÚTypeVarÚoverload)Ú	tree_utilÚTN©Úis_leafc               ó0   — t        j                  | |¬«      S )a“  Call all() over the leaves of a tree.

  Args:
    tree: the pytree to evaluate
    is_leaf : an optionally specified function that will be called at each
      flattening step. It should return a boolean, which indicates whether the
      flattening should traverse the current object, or if it should be stopped
      immediately, with the whole subtree being treated as a leaf.

  Returns:
    result: boolean True or False

  Examples:
    >>> import jax
    >>> jax.tree.all([True, {'a': True, 'b': (True, True)}])
    True
    >>> jax.tree.all([False, (True, False)])
    False

  See Also:
    - :func:`jax.tree.reduce`
    - :func:`jax.tree.leaves`
  r   )r	   Útree_all©Útreer   s     úQC:\Users\Stabi\Downloads\virtual-tryon(1)\venv\Lib\site-packages\jax/_src/tree.pyÚallr      s   € ô0 
×	Ñ	˜D¨'Ô	2Ð2ó    c                ó.   — t        j                  | |«      S )aº  Flattens a pytree.

  The flattening order (i.e. the order of elements in the output list)
  is deterministic, corresponding to a left-to-right depth-first tree
  traversal.

  Args:
    tree: a pytree to flatten.
    is_leaf: an optionally specified function that will be called at each
      flattening step. It should return a boolean, with true stopping the
      traversal and the whole subtree being treated as a leaf, and false
      indicating the flattening should traverse the current object.

  Returns:
    A pair where the first element is a list of leaf values and the second
    element is a treedef representing the structure of the flattened tree.

  Examples:
    >>> import jax
    >>> vals, treedef = jax.tree.flatten([1, (2, 3), [4, 5]])
    >>> vals
    [1, 2, 3, 4, 5]
    >>> treedef
    PyTreeDef([*, (*, *), [*, *]])

  See Also:
    - :func:`jax.tree.leaves`
    - :func:`jax.tree.structure`
    - :func:`jax.tree.unflatten`
  )r	   Útree_flattenr   s     r   Úflattenr   3   s   € ôB 
×	Ñ	  gÓ	.Ð.r   c                ó.   — t        j                  | |«      S )a„  Gets the leaves of a pytree.

  Args:
    tree: the pytree for which to get the leaves
    is_leaf : an optionally specified function that will be called at each
      flattening step. It should return a boolean, which indicates whether the
      flattening should traverse the current object, or if it should be stopped
      immediately, with the whole subtree being treated as a leaf.

  Returns:
    leaves: a list of tree leaves.

  Examples:
    >>> import jax
    >>> jax.tree.leaves([1, (2, 3), [4, 5]])
    [1, 2, 3, 4, 5]

  See Also:
    - :func:`jax.tree.flatten`
    - :func:`jax.tree.structure`
    - :func:`jax.tree.unflatten`
  )r	   Útree_leavesr   s     r   Úleavesr   W   s   € ô2 
×	Ñ	˜t WÓ	-Ð-r   c               ó6   — t        j                  | |g|¢­d|iŽS )a�  Maps a multi-input function over pytree args to produce a new pytree.

  Args:
    f: function that takes ``1 + len(rest)`` arguments, to be applied at the
      corresponding leaves of the pytrees.
    tree: a pytree to be mapped over, with each leaf providing the first
      positional argument to ``f``.
    rest: a tuple of pytrees, each of which has the same structure as ``tree``
      or has ``tree`` as a prefix.
    is_leaf: an optionally specified function that will be called at each
      flattening step. It should return a boolean, which indicates whether the
      flattening should traverse the current object, or if it should be stopped
      immediately, with the whole subtree being treated as a leaf.

  Returns:
    A new pytree with the same structure as ``tree`` but with the value at each
    leaf given by ``f(x, *xs)`` where ``x`` is the value at the corresponding
    leaf in ``tree`` and ``xs`` is the tuple of values at corresponding nodes in
    ``rest``.

  Examples:

    >>> import jax
    >>> jax.tree.map(lambda x: x + 1, {"x": 7, "y": 42})
    {'x': 8, 'y': 43}

    If multiple inputs are passed, the structure of the tree is taken from the
    first input; subsequent inputs need only have ``tree`` as a prefix:

    >>> jax.tree.map(lambda x, y: [x] + y, [5, 6], [[7, 9], [1, 2]])
    [[5, 7, 9], [6, 1, 2]]

  See Also:
    - :func:`jax.tree.leaves`
    - :func:`jax.tree.reduce`
  r   )r	   Útree_map)Úfr   r   Úrests       r   Úmapr   s   s"   € ôP 
×	Ñ	˜A˜tÐ	< dÒ	<°GÑ	<Ð<r   c                ó   — y ©N© )Úfunctionr   r   s      r   Úreducer#   ž   ó   € ð
 r   c                 ó   — y r    r!   ©r"   r   Úinitializerr   s       r   r#   r#   ¤   r$   r   c                ó4   — t        j                  | |||¬«      S )a®  Call reduce() over the leaves of a tree.

  Args:
    function: the reduction function
    tree: the pytree to reduce over
    initializer: the optional initial value
    is_leaf : an optionally specified function that will be called at each
      flattening step. It should return a boolean, which indicates whether the
      flattening should traverse the current object, or if it should be stopped
      immediately, with the whole subtree being treated as a leaf.

  Returns:
    result: the reduced value.

  Examples:
    >>> import jax
    >>> import operator
    >>> jax.tree.reduce(operator.add, [1, (2, 3), [4, 5, 6]])
    21

  Notes:
    **Tip**: You can exclude leaves from the reduction by first mapping them to
    ``None`` using :func:`jax.tree.map`. This causes them to not be counted as
    leaves after that.

  See Also:
    - :func:`jax.tree.reduce_associative`
    - :func:`jax.tree.leaves`
    - :func:`jax.tree.map`
  r   )r	   Útree_reducer&   s       r   r#   r#   ª   s   € ôD 
×	Ñ	˜x¨¨{ÀGÔ	LÐLr   ©Úidentityr   c               ó4   — t        j                  | |||¬«      S )a  Perform a reduction over a pytree with an associative binary operation.

  This function exploits the fact that the operation is associative to perform
  the reduction in parallel (logarithmic depth).

  Args:
    operation: the associative binary operation
    tree: the pytree to reduce
    identity: the identity element of the associative binary operation.
      This is used only when the tree is empty. It is optional otherwise.
    is_leaf: an optionally specified function that will be called at each
      flattening step. It should return a boolean, which indicates whether the
      flattening should traverse the current object, or if it should be stopped
      immediately, with the whole subtree being treated as a leaf.

  Returns:
    result: the reduced value

  Examples:
    >>> import jax
    >>> import operator
    >>> jax.tree.reduce_associative(operator.add, [1, (2, 3), [4, 5, 6]])
    21

  Notes:
    **Tip**: You can exclude leaves from the reduction by first mapping them to
    ``None`` using :func:`jax.tree.map`. This causes them to not be counted as
    leaves after that.

  See Also:
    - :func:`jax.tree.reduce`
  r*   )r	   Útree_reduce_associative)Ú	operationr   r+   r   s       r   Úreduce_associativer/   Ï   s$   € ôN 
×	*Ñ	*ØØ
ØØô	
ð r   c                ó.   — t        j                  | |«      S )aµ  Gets the treedef for a pytree.

  Args:
    tree: the pytree for which to get the leaves
    is_leaf : an optionally specified function that will be called at each
      flattening step. It should return a boolean, which indicates whether the
      flattening should traverse the current object, or if it should be stopped
      immediately, with the whole subtree being treated as a leaf.

  Returns:
    pytreedef: a PyTreeDef representing the structure of the tree.

  Examples:
    >>> import jax
    >>> jax.tree.structure([1, (2, 3), [4, 5]])
    PyTreeDef([*, (*, *), [*, *]])

  See Also:
    - :func:`jax.tree.flatten`
    - :func:`jax.tree.leaves`
    - :func:`jax.tree.unflatten`
  )r	   Útree_structurer   s     r   Ú	structurer2   þ   s   € ô0 
×	!Ñ	! $¨Ó	0Ð0r   c                ó0   — t        j                  | ||«      S )aQ  Transform a tree having tree structure (outer, inner) into one having structure (inner, outer).

  Args:
    outer_treedef: PyTreeDef representing the outer tree.
    inner_treedef: PyTreeDef representing the inner tree.
      If None, then it will be inferred from outer_treedef and the structure of
      pytree_to_transpose.
    pytree_to_transpose: the pytree to be transposed.

  Returns:
    transposed_pytree: the transposed pytree.

  Examples:
    >>> import jax
    >>> tree = [(1, 2, 3), (4, 5, 6)]
    >>> inner_structure = jax.tree.structure(('*', '*', '*'))
    >>> outer_structure = jax.tree.structure(['*', '*'])
    >>> jax.tree.transpose(outer_structure, inner_structure, tree)
    ([1, 4], [2, 5], [3, 6])

    Inferring the inner structure:

    >>> jax.tree.transpose(outer_structure, None, tree)
    ([1, 4], [2, 5], [3, 6])
  )r	   Útree_transpose)Úouter_treedefÚinner_treedefÚpytree_to_transposes      r   Ú	transposer8     s   € ô8 
×	!Ñ	! -°Ð@SÓ	TÐTr   c                ó.   — t        j                  | |«      S )aÇ  Reconstructs a pytree from the treedef and the leaves.

  The inverse of :func:`tree_flatten`.

  Args:
    treedef: the treedef to reconstruct
    leaves: the iterable of leaves to use for reconstruction. The iterable must
      match the leaves of the treedef.

  Returns:
    The reconstructed pytree, containing the ``leaves`` placed in the structure
    described by ``treedef``.

  Examples:
    >>> import jax
    >>> vals, treedef = jax.tree.flatten([1, (2, 3), [4, 5]])
    >>> newvals = [100, 200, 300, 400, 500]
    >>> jax.tree.unflatten(treedef, newvals)
    [100, (200, 300), [400, 500]]

  See Also:
    - :func:`jax.tree.flatten`
    - :func:`jax.tree.leaves`
    - :func:`jax.tree.structure`
  )r	   Útree_unflatten)Útreedefr   s     r   Ú	unflattenr<   8  s   € ô6 
×	!Ñ	! '¨6Ó	2Ð2r   Fc                ó0   — t        j                  | ||«      S )a6  Flattens a pytree like ``tree_flatten``, but also returns each leaf's key path.

  Args:
    tree: a pytree to flatten. If it contains a custom type, it is recommended
      to be registered with ``register_pytree_with_keys``.

  Returns:
    A pair which the first element is a list of key-leaf pairs, each of
    which contains a leaf and its key path. The second element is a treedef
    representing the structure of the flattened tree.

  Examples:
    >>> import jax
    >>> path_vals, treedef = jax.tree.flatten_with_path([1, {'x': 3}])
    >>> path_vals
    [((SequenceKey(idx=0),), 1), ((SequenceKey(idx=1), DictKey(key='x')), 3)]
    >>> treedef
    PyTreeDef([*, {'x': *}])

  See Also:
    - :func:`jax.tree.flatten`
    - :func:`jax.tree.map_with_path`
    - :func:`jax.tree_util.register_pytree_with_keys`
  )r	   Útree_flatten_with_path©r   r   Úis_leaf_takes_paths      r   Úflatten_with_pathrA   V  s   € ô8 
×	)Ñ	)¨$°Ð9KÓ	LÐLr   c                ó0   — t        j                  | ||«      S )a`  Gets the leaves of a pytree like ``tree_leaves`` and returns each leaf's key path.

  Args:
    tree: a pytree. If it contains a custom type, it is recommended to be
      registered with ``register_pytree_with_keys``.

  Returns:
    A list of key-leaf pairs, each of which contains a leaf and its key path.

  Examples:
    >>> import jax
    >>> jax.tree.leaves_with_path([1, {'x': 3}])
    [((SequenceKey(idx=0),), 1), ((SequenceKey(idx=1), DictKey(key='x')), 3)]

  See Also:
    - :func:`jax.tree.leaves`
    - :func:`jax.tree.flatten_with_path`
    - :func:`jax.tree_util.register_pytree_with_keys`
  )r	   Útree_leaves_with_pathr?   s      r   Úleaves_with_pathrD   u  s   € ô. 
×	(Ñ	(¨¨wÐ8JÓ	KÐKr   ©r   r@   c               ó8   — t        j                  | |g|¢­||dœŽS )aÅ  Maps a multi-input function over pytree key path and args to produce a new pytree.

  This is a more powerful alternative of ``tree_map`` that can take the key path
  of each leaf as input argument as well.

  Args:
    f: function that takes ``2 + len(rest)`` arguments, aka. the key path and
      each corresponding leaves of the pytrees.
    tree: a pytree to be mapped over, with each leaf's key path as the first
      positional argument and the leaf itself as the second argument to ``f``.
    *rest: a tuple of pytrees, each of which has the same structure as ``tree``
      or has ``tree`` as a prefix.

  Returns:
    A new pytree with the same structure as ``tree`` but with the value at each
    leaf given by ``f(kp, x, *xs)`` where ``kp`` is the key path of the leaf at
    the corresponding leaf in ``tree``, ``x`` is the leaf value and ``xs`` is
    the tuple of values at corresponding nodes in ``rest``.

  Examples:
    >>> import jax
    >>> jax.tree.map_with_path(lambda path, x: x + path[0].idx, [1, 2, 3])
    [1, 3, 5]

  See Also:
    - :func:`jax.tree.map`
    - :func:`jax.tree.flatten_with_path`
    - :func:`jax.tree.leaves_with_path`
    - :func:`jax.tree_util.register_pytree_with_keys`
  rE   )r	   Útree_map_with_path)r   r   r   r@   r   s        r   Úmap_with_pathrH   �  s0   € ôJ 
×	%Ñ	%Øˆð
Øñ
Ø%Ð:Lò
ð r   c                ó2   — t        j                  | ||¬«      S )aÇ  Broadcasts a tree prefix into the full structure of a given tree.

    Args:
      prefix_tree: a pytree that is a tree prefix of full_tree.
      full_tree: a pytree with the structure to broadcast the prefix leaves into.
      is_leaf: an optionally specified function that will be called at each
        flattening step. It should return a boolean, with true stopping the
        traversal and the whole subtree being treated as a leaf, and false
        indicating the flattening should traverse the current object.

    Returns:
      A pytree matching the structure of full_tree where the leaves of prefix_tree have been
      broadcasted into the leaves of each corresponding subtree.

    Examples:
      >>> import jax
      >>> prefix = (1, 2, 3)
      >>> full = (0, {'a': 0, 'b': 0}, (0, 0))
      >>> jax.tree.broadcast(prefix, full)
      (1, {'a': 2, 'b': 2}, (3, 3))

    See Also:
      - :func:`jax.tree.leaves`
      - :func:`jax.tree.structure`
  r   )r	   Útree_broadcast)Úprefix_treeÚ	full_treer   s      r   Ú	broadcastrM   ¹  s   € ô8 
×	!Ñ	! +¨yÀ'Ô	JÐJr   )r   r   r   úCallable[[Any], bool] | NoneÚreturnÚboolr    )r   r   r   rN   rO   z0tuple[list[tree_util.Leaf], tree_util.PyTreeDef])r   r   r   rN   rO   zlist[tree_util.Leaf])
r   úCallable[..., Any]r   r   r   r   r   rN   rO   r   )r"   úCallable[[T, Any], T]r   r   r   rN   rO   r
   )
r"   rR   r   r   r'   r
   r   rN   rO   r
   )
r"   rR   r   r   r'   r   r   rN   rO   r
   )
r.   zCallable[[T, T], T]r   r   r+   zT | tree_util.Unspecifiedr   rN   rO   r
   )r   r   r   zNone | Callable[[Any], bool]rO   útree_util.PyTreeDef)r5   rS   r6   ztree_util.PyTreeDef | Noner7   r   rO   r   )r;   rS   r   zIterable[tree_util.Leaf]rO   r   )NF)r   r   r   úCallable[..., bool] | Noner@   rP   rO   z?tuple[list[tuple[tree_util.KeyPath, Any]], tree_util.PyTreeDef])r   r   r   rT   r@   rP   rO   z#list[tuple[tree_util.KeyPath, Any]])r   rQ   r   r   r   r   r   rT   r@   rP   rO   r   )rK   r   rL   r   r   rN   rO   r   )Ú
__future__r   Úcollections.abcr   r   Útypingr   r   r   Újax._srcr	   r
   r   r   r   r   r#   Úno_initializerÚUnspecifiedr/   r2   r8   r<   rA   rD   rH   rM   r!   r   r   Ú<module>r[      s¢  ðõ #ç .ß )Ñ )å áˆCƒL€ð ?Cõ 3ð8 59ð!/Ø1ð!/àAó!/ðJ 48ð.Ø0ð.à$ó.ð> 15ñ(=Øð(=àð(=ð .ð(=ð :=ó(=ðV 
ð 48ñØðð 1ðð =>òó 
ðð
 
ð 48ðØðàðð 1ðð =>òó 
ðð (×6Ñ6Ø37ð"MØð"Màð"Mð 1ð"Mð =>ó"MðR +@¨)×*?Ñ*?Ó*AØ,0ñ,Ø"ð,à
ð,ð (ð	,ð
 *ð,ð ó,ð` 9=ð1Ø5ð1ØATó1ð6UØ7ðUà#&ðUà+.óUð>3Ø.ð3Ø36ó3ð> 6:Ø$ðMØ
ðMØ2ðMàðMð EóMð@ 6:Ø$ðLØ
ðLØ2ðLàðLð )óLð< +/Ø$ñ'Øð'à
ð'ð ð'ð (ð	'ð
 ð'ð 	ó'ðV 7;ðKØ3ðKàôKr   