U
    9%e                     @   s   d dl mZ d dlmZ d dlZedr<d dlm  mZ ndZ	d dl
Z
d dlmZmZm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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S )+    )import_module)raisesNZllvmliteT)abnc                 C   s$   d}d}t | | ||t |  kS )Ngh㈵>g:0yE>)abs)r   r   ZrtolZatol r   `/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/sympy/printing/tests/test_llvmjit.pyisclose   s    r
   c                  C   sF   t d } tt g| }t| t di }|d}t||sBtd S )Ng      ?      @)r   gllvm_callablefloatsubsevalfr
   AssertionErrorefresjit_resr   r   r	   test_simple_expr   s
    r   c                  C   sV   dt  t d } tt tg| }t| t dtdi }|dd}t||sRtd S )Nr   g      @	r   r   r   r   r   r   r   r
   r   r   r   r   r	   test_two_arg   s
    
r   c                  C   sN   dt t  } ttg| }t| tdi }|d}t||sJt	d S )Nr         ?)
sympyexpr   r   r   r   r   r   r
   r   r   r   r   r	   	test_func(   s
    r   c                  C   s`   dt t  t t } tttg| }t| tdtdi }|dd}t	||s\t
d S Nr   r          @)r   r   r   r   r   r   r   r   r   r
   r   r   r   r   r	   test_two_func1   s
    
r    c                  C   s^   dt t t t } tttg| }t| tdtdi }|dd}t	||sZt
d S r   )r   sqrtr   r   r   r   r   r   r   r
   r   r   r   r   r	   test_two_sqrt:   s
    
r"   c                  C   sV   t d td  } tt tg| }t| t dtdi }|dd}t||sRtd S )Nr      r   r   r   r   r   r	   test_two_powC   s
    
r$   c                  C   sp   t d } tjt g| dd}td}tjd }t di}||t  }|||}t| | }t	||slt
d S )N333333?scipy.integrate.testZcallback_type   皙@)r   r   r   ctypesc_intc_doubler   r   r   r
   r   r   r   m
array_typeinparrayr   r   r   r   r	   test_callbackL   s    


r2   c            	      C   s   t d } tjt g| dd}td}tjd }t di}||t  }|d}|||d ||}|dksftt| |	 }t
|d |std S )Nr%   cubaturer'   r(   r)   g        r   )r   r   r   r*   r+   r,   r   r   r   r   r
   )	r   r   r.   r/   r0   r1   	out_arrayjit_retr   r   r   r	   test_callback_cubatureZ   s    

r6   c                  C   s   dt  t } tjt tg| dd}td}tjd }t dtdi}||t  |t }|||}t| |	 }t
||s|td S )N   r&   r'      皙?333333?)r   r   r   r   r*   r+   r,   r   r   r   r
   r   r-   r   r   r	   test_callback_twok   s    


r;   c            	      C   s   t d} d| d  | d  }tjt| g|dd}td}tjd }| d d| d d	i}||| d  || d  }|||}t|	|
 }t||std S )
Ndr7   r   r(   r&   r'   r8   r9   r:   )r   ZIndexedBaser   r   r   r*   r+   r,   r   r   r   r
   r   )	r<   r   r   r.   r/   r0   r1   r   r   r   r   r	   test_callback_alt_twoy   s    



r=   c            
      C   s   t dt fgt d gg} ttg| }| d d d tdi}t| d d t |i }|d}t||stttjtg| dd}t	
d}t	jd }|d}|||}	t|	|std S )Nr      r   r(   r   r&   r'   )r   r   r   r   r   r   r   r
   r   r*   r+   r,   )
r   r   Zb_valr   r   Z
f_callbackr.   r/   r1   Zjit_callback_resr   r   r	   test_multiple_statements   s    


r?   c                  C   sx   t t  tt  tt  t  tt   } t| }tt tg|}t| t dtdi	 }|dd}t
||sttd S )Ngffffff@皙?)r   r   r   r   cser   r   r   r   r   r
   r   )r   e2r   r   r   r   r   r	   test_cse   s    (

rC   c                    sJ   i | d D ]$\}}|  }| }||< q fdd| d D S )Nr   c                    s   g | ]}|   qS r   r   ).0r   sub_dictZtmp_dictr   r	   
<listcomp>   s     zeval_cse.<locals>.<listcomp>r(   rD   )r   rG   tmp_nameZtmp_exprrB   e3r   rF   r	   eval_cse   s    


rK   c                     s   t t  } t t  tt  }t| |g tt fdd tt tg }|dd}t|dksbt	t
 t dtdi}t|d |d st	t|d |d st	d S )Nc                      s   t jttg ddS )Nzscipy.integrater'   )r   r   r   r   r   rJ   r   r	   <lambda>       z#test_cse_multiple.<locals>.<lambda>r@   r   r8   r   r(   )r   r   r   rA   r   NotImplementedErrorr   r   lenr   rK   r
   )e1rB   r   r   r   r   rL   r	   test_cse_multiple   s    

rR   c                  C   s   t t  } t t  tt  }t| |d| g}tjt tg|dd}d}d}t|}t|}tj| }tj| }	t dtdi}
||
t  |
t }|	 }|||d ||}|dkst	t
||
}t|d |d st	t|d	 |d	 st	t|d |d st	d S )
N   r3   r'   r8   r7   r9   r   r   r(   )r   r   r   rA   r   r   r*   r+   r,   r   rK   r
   )rQ   rB   rJ   r   ndimZoutdimr.   Zfdimr/   Zout_array_typer0   r1   r4   r5   r   r   r   r	   test_callback_cubature_multiple   s&    




rU   c                      s"   t t  t  tt fdd d S )Nc                      s   t tg S )Nr   r   r   r   r   r   r	   rM      rN   z'test_symbol_not_found.<locals>.<lambda>)r   r   r   LookupErrorr   r   rW   r	   test_symbol_not_found   s    rY   c                      s   t  tt fdd d S )Nc                      s   t jtg ddS )NZbad_callbackr'   rV   r   rW   r   r	   rM      rN   z#test_bad_callback.<locals>.<lambda>)r   r   
ValueErrorr   r   rW   r	   test_bad_callback   s    r[   )!Zsympy.externalr   Zsympy.testing.pytestr   r*   Zsympy.printing.llvmjitcodeZprintingZllvmjitcoder   disabledr   Z	sympy.abcr   r   r   r
   r   r   r   r    r"   r$   r2   r6   r;   r=   r?   rC   rK   rR   rU   rY   r[   r   r   r   r	   <module>   s2   						
	