o
    giC                     @   s  d dl Z d dlZd dlZd dlmZ d dlZd dlZdZdd Z	d.ddZ
dd Zd	d
 Zeedd7 Zed7 Zeedd7 Zd Zee	e7 Zeedd7 Zee
edd7 Zeedd7 Zee
edd7 Zeedd7 Zee
edd7 Zeedd7 Zee
edd7 Zeedd7 Zeed7 Zeedd7 Zeed7 Zeedd7 Zd Zee	e7 Zeed!d7 Zee
ed"d7 Zeed#d7 Zee
ed$d7 Zeed%d7 Zee
ed&d7 Zeed'd7 Zd(Zee	e7 Zeed!d7 Zee
ed"d7 Zeed#d7 Zee
ed$d7 Zeed%d7 Zee
ed&d7 Zeed)d7 Zd*Zee	e7 Zeed!d7 Zee
ed"d7 Zeed#d7 Zee
ed$d7 Zeejejejed+d,d-Zee W d   dS 1 siw   Y  dS )/    N c                 C   sJ   |   d} d}ddd | D }|d7 }|d| d7 }|d7 }|S )	N
r   c                 S   s    g | ]}|  rd |   qS z
    strip.0line r
   `/home/ubuntu/SoloSpeech/.venv/lib/python3.10/site-packages/docs/source/generate_compiled_code.py
<listcomp>   s     zgenerate_op.<locals>.<listcomp>zThe operation

..  code-block:: Python


z!compiles to the following code:

)r   splitjoin)func_strrstfunc_str_rstr
   r
   r   generate_op   s   r   c                 C   s   |d urd| d}nd}|   d} d}d| d  | d< d| } |   } | ds.J | d d d| d } tttd	}t| || td
||}|  d}ddd |D }|d7 }|d| 7 }|d7 }|S )Nz, backend=""r   r   zcode = )z, graph=True)jnpeinxnpcodec                 S   s   g | ]
}|  rd | qS r   r   r   r
   r
   r   r   +   s    z!generate_code.<locals>.<listcomp>r   r   )	r   r   r   endswithr   r   r   execeval)r   backendr   locals_globalsr   r
   r
   r   generate_code   s&   
r!   c                 C   s    d}|t | 7 }|t| 7 }|S )Nr   )r   r!   )r   r   r
   r
   r   generate3   s   r"   c                 C   s   d|  d|t |   dS )Nr   r   )len)textcharr
   r
   r   	underline<   s   r&   zExamples of compiled code#a  
The following are examples of various einx operations along with the Python code snippet that einx compiles for them, using either
the default backend or explicitly specifying a backend. The compiled code can be inspected by passing ``graph=True`` to the einx operation.
zAxis permutation=z7
x = np.zeros((10, 5, 2))
einx.id("a b c -> b c a", x)
zWith ``backend="numpy"``-numpy)r   zWith ``backend="torch"``torchzWith ``backend="jax"``jaxzWith ``backend="arrayapi"``arrayapizAxis flatteningz=
x = np.zeros((10, 5))
einx.id("(a b) c -> a (b c)", x, b=2)
zNo-opz0
x = np.zeros((10, 5))
einx.id("a b -> a b", x)
zElement-wise multiplicationzi
x = jnp.zeros((2, (5 * 6)))
y = jnp.zeros((4, 3, 6))
einx.multiply("a (d e), c b e -> a b c d e", x, y)
z With ``backend="jax.numpylike"``zjax.numpylikezWith ``backend="jax.vmap"``zjax.vmapzWith ``backend="jax.einsum"``z
jax.einsumzDot-productzS
x = jnp.zeros((2, 3))
y = jnp.zeros((4, 3))
einx.dot("a [b], c [b] -> c a", x, y)
Indexingzg
x = jnp.zeros((2, 128, 128, 3))
y = jnp.zeros((50, 2))
einx.get_at("b [h w] c, p [2] -> b p c", x, y)
morezcompiledcode.rstw)N)r   r*   r   os	jax.numpyr   r+   array_api_compatreportr   r!   r"   r&   r   r   openpathr   dirnameabspath__file__fwriter
   r
   r
   r   <module>   st    
	($