
    uki2'                       d dl mZ d dlmZ d dlmZmZ d dlZd dl	m
Z
 d dl	mZ d dlmZ d dlmZ d d	lmZ d d
lmZmZmZmZmZmZ d dlmZmZ d dlmZ  ed      Zg dZddZ  G d d      Z! e e!             Z" G d d      Z# e e#             Z$eee%e&f   Z' G d d      Z( G d de(      Z) e e)             Z* G d de(      Z+ e e+             Z,ejZ                  Z-ej\                  Z.y)    )annotations)Iterable)AnyUnionN)config)core)array)promote_dtypes)linspace)arangeconcatenateexpand_dimsmeshgridstack	transpose)Array	ArrayLike)
set_modulez	jax.numpy)c_	index_expmgridogridr_s_c           	     t   t        j                  d | j                  d|       xs d}t        j                  d | j                  d|       }t        j                  d | j                  d|       xs d}t        j                  |      r!t        ||t        t        |                  }|S t        |||      }|S )Nzslice start of jnp.r   zslice stop of jnp.zslice step of jnp.   )r   concrete_or_errorstartstopstepnp	iscomplexr   intabsr   )sop_namer   r   r    newobjs         V/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/jax/_src/numpy/index_tricks.py_make_1d_grid_from_slicer)   (   s    

 
 qww#6wi!@B GEF 			aff"4WI >
@$			aff"4WI >
@ 
ECD \\$eT3s4y>2F 
- E4&F	-    c                      e Zd ZdZddZy)_Mgrida?  Return dense multi-dimensional "meshgrid".

  LAX-backend implementation of :obj:`numpy.mgrid`. This is a convenience wrapper for
  functionality provided by :func:`jax.numpy.meshgrid` with ``sparse=False``.

  See Also:
    jnp.ogrid: open/sparse version of jnp.mgrid

  Examples:
    Pass ``[start:stop:step]`` to generate values similar to :func:`jax.numpy.arange`:

    >>> jnp.mgrid[0:4:1]
    Array([0, 1, 2, 3], dtype=int32)

    Passing an imaginary step generates values similar to :func:`jax.numpy.linspace`:

    >>> jnp.mgrid[0:1:4j]
    Array([0.        , 0.33333334, 0.6666667 , 1.        ], dtype=float32)

    Multiple slices can be used to create broadcasted grids of indices:

    >>> jnp.mgrid[:2, :3]
    Array([[[0, 0, 0],
            [1, 1, 1]],
           [[0, 1, 2],
            [0, 1, 2]]], dtype=int32)
  c                   t        |t              rt        |d      S d |D        }t        j                  d      5  t        | }d d d        t        |ddd}t        |      dk(  rt        d      S t        |d      S # 1 sw Y   :xY w)	Nr   r&   c              3  6   K   | ]  }t        |d         yw)r   r.   Nr)   .0ks     r(   	<genexpr>z%_Mgrid.__getitem__.<locals>.<genexpr>W        YPQ77KKY   standardijFindexingsparser   )

isinstanceslicer)   r   numpy_dtype_promotionr
   r   lenr   r   )selfkeyoutput
output_arrs       r(   __getitem__z_Mgrid.__getitem__T   s    #u%c7;;YUXYF		%	%j	1 'v&f'6D?J
:!AYQ' 's   	A>>BN)rA   slice | tuple[slice, ...]returnr   __name__
__module____qualname____doc__rD    r*   r(   r,   r,   7   s    8	 r*   r,   c                       e Zd ZdZ	 	 	 	 ddZy)_Ogrida  Return open multi-dimensional "meshgrid".

  LAX-backend implementation of :obj:`numpy.ogrid`. This is a convenience wrapper for
  functionality provided by :func:`jax.numpy.meshgrid` with ``sparse=True``.

  See Also:
    jnp.mgrid: dense version of jnp.ogrid

  Examples:
    Pass ``[start:stop:step]`` to generate values similar to :func:`jax.numpy.arange`:

    >>> jnp.ogrid[0:4:1]
    Array([0, 1, 2, 3], dtype=int32)

    Passing an imaginary step generates values similar to :func:`jax.numpy.linspace`:

    >>> jnp.ogrid[0:1:4j]
    Array([0.        , 0.33333334, 0.6666667 , 1.        ], dtype=float32)

    Multiple slices can be used to create sparse grids of indices:

    >>> jnp.ogrid[:2, :3]
    [Array([[0],
            [1]], dtype=int32),
     Array([[0, 1, 2]], dtype=int32)]
  c                    t        |t              rt        |d      S d |D        }t        j                  d      5  t        | }d d d        t        |dddS # 1 sw Y   xY w)Nr   r.   c              3  6   K   | ]  }t        |d         yw)r   r.   Nr0   r1   s     r(   r4   z%_Ogrid.__getitem__.<locals>.<genexpr>   r5   r6   r7   r8   Tr9   )r<   r=   r)   r   r>   r
   r   )r@   rA   rB   s      r(   rD   z_Ogrid.__getitem__   sb     #u%c7;;YUXYF		%	%j	1 'v&f'Vd488' 's   	AA"N)rA   rE   rF   zArray | list[Array]rG   rL   r*   r(   rN   rN   c   s    69*99r*   rN   c                  J    e Zd ZU dZded<   ded<   ded<   ded<   ddZdd	Zy
)_AxisConcatzGConcatenates slices, scalars and array-like objects along a given axis.r#   axisndmintrans1dstrr&   c                   t        |t              r|n|f}| j                  | j                  | j                  dg}|d   }t        |t
              rk|dd  }|dk(  rd|d<   n[|dk(  rd|d<   nP|j                  d      }t        |      }|dk  r	|||d  z  }n|d d |d   gz   }	 t        t        t        |            }|\  }}	}
}g }|D ]  }t        |t              rt        || j                  
      }d}n4t        |t
              rt        d      t        |d      }|j                   }t        |d|	      }|
dk7  rS|	|z
  dkD  rKt        t#        |	            }|	t%        |	|
z   dz         |	z  z
  }t        ||d  |d | z         }t'        ||      }|j)                  |        t+        t        |      |      }|dk7  r|j                   dk(  rt-        ||      }|S # t        $ r}t        d	|      |d }~ww xY w)Nr   r   rc,      zcould not understand directive r.   z0string directive must be placed at the beginningF)copy)r^   rT   )rS   )r<   tuplerS   rT   rU   rV   splitr?   listmapr#   
ValueErrorr=   r)   r&   r	   ndimranger$   r   appendr   r   )r@   rA   key_tupparams	directivevecr3   errrS   rT   rU   matrixrB   itemr'   	item_ndim	shape_objnum_lshiftsress                      r(   rD   z_AxisConcat.__getitem__   s   -7U-Cc#GiiT\\26F
I)S!g	c	r
r
"-Hq5

# BQ6":,&#	C&& $* D%&F 	D%	 )$E	dC KLLt%(KK	V%u5f	B59,q0%,'	c%'/A"56>>)KL1Il{4KKL	69-mmF), eFm$
/C|AV$cJI  	-i];	s   !G 	G4 G//G4c                     y)Nr   rL   )r@   s    r(   __len__z_AxisConcat.__len__   s    r*   N)rA   z#_IndexType | tuple[_IndexType, ...]rF   r   )rF   r#   )rH   rI   rJ   rK   __annotations__rD   rs   rL   r*   r(   rR   rR      s$    O)	*,,;zr*   rR   c                       e Zd ZdZdZdZdZdZy)RClassa  Concatenate slices, scalars and array-like objects along the first axis.

  LAX-backend implementation of :obj:`numpy.r_`.

  See Also:
    ``jnp.c_``: Concatenates slices, scalars and array-like objects along the last axis.

  Examples:
    Passing slices in the form ``[start:stop:step]`` generates ``jnp.arange`` objects:

    >>> jnp.r_[-1:5:1, 0, 0, jnp.array([1,2,3])]
    Array([-1,  0,  1,  2,  3,  4,  0,  0,  1,  2,  3], dtype=int32)

    An imaginary value for ``step`` will create a ``jnp.linspace`` object instead,
    which includes the right endpoint:

    >>> jnp.r_[-1:1:6j, 0, jnp.array([1,2,3])]  # doctest: +SKIP
    Array([-1. , -0.6, -0.2,  0.2,  0.6,  1. ,  0. ,  1. ,  2. ,  3. ],      dtype=float32)

    Use a string directive of the form ``"axis,dims,trans1d"`` as the first argument to
    specify concatenation axis, minimum number of dimensions, and the position of the
    upgraded array's original dimensions in the resulting array's shape tuple:

    >>> jnp.r_['0,2', [1,2,3], [4,5,6]] # concatenate along first axis, 2D output
    Array([[1, 2, 3],
           [4, 5, 6]], dtype=int32)

    >>> jnp.r_['0,2,0', [1,2,3], [4,5,6]] # push last input axis to the front
    Array([[1],
           [2],
           [3],
           [4],
           [5],
           [6]], dtype=int32)

    Negative values for ``trans1d`` offset the last axis towards the start
    of the shape tuple:

    >>> jnp.r_['0,2,-2', [1,2,3], [4,5,6]]
    Array([[1],
           [2],
           [3],
           [4],
           [5],
           [6]], dtype=int32)

    Use the special directives ``"r"`` or ``"c"`` as the first argument on flat inputs
    to create an array with an extra row or column axis, respectively:

    >>> jnp.r_['r',[1,2,3], [4,5,6]]
    Array([[1, 2, 3, 4, 5, 6]], dtype=int32)

    >>> jnp.r_['c',[1,2,3], [4,5,6]]
    Array([[1],
           [2],
           [3],
           [4],
           [5],
           [6]], dtype=int32)

    For higher-dimensional inputs (``dim >= 2``), both directives ``"r"`` and ``"c"``
    give the same result.
  r   r   rX   r   NrH   rI   rJ   rK   rS   rT   rU   r&   rL   r*   r(   rv   rv      s    >~ 
$
%''r*   rv   c                       e Zd ZdZdZdZdZdZy)CClassaz  Concatenate slices, scalars and array-like objects along the last axis.

  LAX-backend implementation of :obj:`numpy.c_`.

  See Also:
    ``jnp.r_``: Concatenates slices, scalars and array-like objects along the first axis.

  Examples:

    >>> a = jnp.arange(6).reshape((2,3))
    >>> jnp.c_[a,a]
    Array([[0, 1, 2, 0, 1, 2],
           [3, 4, 5, 3, 4, 5]], dtype=int32)

    Use a string directive of the form ``"axis:dims:trans1d"`` as the first argument to specify
    concatenation axis, minimum number of dimensions, and the position of the upgraded array's
    original dimensions in the resulting array's shape tuple:

    >>> jnp.c_['0,2', [1,2,3], [4,5,6]]
    Array([[1],
           [2],
           [3],
           [4],
           [5],
           [6]], dtype=int32)

    >>> jnp.c_['0,2,-1', [1,2,3], [4,5,6]]
    Array([[1, 2, 3],
           [4, 5, 6]], dtype=int32)

    Use the special directives ``"r"`` or ``"c"`` as the first argument on flat inputs
    to create an array with inputs stacked along the last axis:

    >>> jnp.c_['r',[1,2,3], [4,5,6]]
    Array([[1, 4],
           [2, 5],
           [3, 6]], dtype=int32)
  rX      r   r   Nrw   rL   r*   r(   ry   ry   !  s    %L 
$
%''r*   ry   )r%   r=   r&   rV   rF   r   )/
__future__r   collections.abcr   typingr   r   numpyr!   jax._srcr   r   !jax._src.numpy.array_constructorsr	   jax._src.numpy.utilr
   jax._src.numpy.array_creationr   jax._src.numpy.lax_numpyr   r   r   r   r   r   jax._src.typingr   r   jax._src.utilr   export__all__r)   r,   r   rN   r   rV   r=   
_IndexTyperR   rv   r   ry   r   r   r   rL   r*   r(   <module>r      s    # $     3 . 2  - $ 
K	  <&  & R 	vx$9 $9N 	vx 9c5()
E EPC[ CL FH*[ *Z FHUULL	r*   