
    Vpf^$                        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d0dZ	 d*d1dZd2d$Zd3d(ZdS )4    )annotations)CallableIterable)AnyTypeVaroverload)	tree_utilTNis_leaftreer   r   Callable[[Any], bool] | Nonereturnboolc               .    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r   r   s     M/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/jax/_src/tree.pyallr      s    0 
	D'	2	2	22    0tuple[list[tree_util.Leaf], tree_util.PyTreeDef]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   list[tree_util.Leaf]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 
	tW	-	--r   fCallable[..., Any]restc               .    t          j        | |g|R 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)r   r   r   r!   s       r   mapr$   s   s(    P 
	At	<d	<	<	<G	<	<<r   functionCallable[[T, Any], T]c                   d S N )r%   r   r   s      r   reducer*      	    
 Cr   initializerc                    d S r(   r)   r%   r   r,   r   s       r   r*   r*      r+   r   c                2    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

  See Also:
    - :func:`jax.tree.leaves`
    - :func:`jax.tree.map`
  r   )r	   tree_reducer.   s       r   r*   r*      s    8 
	x{G	L	L	LLr   None | Callable[[Any], bool]tree_util.PyTreeDefc                ,    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   	structurer5      s    0 
	!$	0	00r   outer_treedefinner_treedeftree_util.PyTreeDef | Nonepytree_to_transposec                .    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)r6   r7   r9   s      r   	transposer<      s    8 
	!-@S	T	TTr   treedefr   Iterable[tree_util.Leaf]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)r=   r   s     r   	unflattenrA     s    6 
	!'6	2	22r   )r   r   r   r   r   r   r(   )r   r   r   r   r   r   )r   r   r   r   r   r   )
r   r    r   r   r!   r   r   r   r   r   )r%   r&   r   r   r   r   r   r
   )
r%   r&   r   r   r,   r
   r   r   r   r
   )
r%   r&   r   r   r,   r   r   r   r   r
   )r   r   r   r1   r   r2   )r6   r2   r7   r8   r9   r   r   r   )r=   r2   r   r>   r   r   )
__future__r   collections.abcr   r   typingr   r   r   jax._srcr	   r
   r   r   r   r$   r*   no_initializerr5   r<   rA   r)   r   r   <module>rG      s   # " " " " " . . . . . . . . ) ) ) ) ) ) ) ) ) )      GCLL ?C 3 3 3 3 3 38 59!/ !/ !/ !/ !/J 48. . . . .> 15(= (= (= (= (= (=V 
 48     

 
 48    
 (637M M M M M@ 9=1 1 1 1 16U U U U>3 3 3 3 3 3r   