o
    i                      @   s`   d dl Z d dlZd dlmZmZmZ d dlmZm	Z	m
Z
 G dd dZdd ZG dd	 d	ZdS )
    N)assert_allcloseassert_assert_array_equal)fmin_cobylaminimizeBoundsc                   @   sD   e Z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 )
TestCobylac                 C   s.   ddg| _ tddg| _ddddd	| _d S )
Ng@gQ?g888@gUUUUUU?F   h㈵>d   )disprhobegtolmaxiter)x0mathsqrtsolutionoptsself r   o/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/scipy/optimize/tests/test_cobyla.pysetup_method
   s
   
zTestCobyla.setup_methodc                 C   s   |d d t |d d  S )Nr      r	      )absr   xr   r   r   fun      zTestCobyla.func                 C   s   |d d |d d  d S )Nr   r   r	      r   r   r   r   r   con1   r    zTestCobyla.con1c                 C   s   |  | S N)r"   r   r   r   r   con2      zTestCobyla.con2c              	   C   s6   t | j| j| j| jgddddd}t|| jdd d S )Nr	   r
   r   T)r   rhoendZmaxfunr   -C6?Zatol)r   r   r   r"   r$   r   r   r   r   r   r   test_simple   s   zTestCobyla.test_simplec                 C   s   G dd d}| }d| j dd| jdf}t| j| jd||| jd}t|j| jdd t	|j
|j t	|jd	k | t	|jd
k | t	|j| | jd k | t	|j|jkd t|j|jd d S )Nc                   @      e Zd Zdd Zdd ZdS )z1TestCobyla.test_minimize_simple.<locals>.Callbackc                 S   s   d| _ d | _d S )Nr   n_callslast_xr   r   r   r   __init__!   s   
z:TestCobyla.test_minimize_simple.<locals>.Callback.__init__c                 S   s   |  j d7  _ || _d S Nr	   r+   r   r   r   r   __call__%   s   
z:TestCobyla.test_minimize_simple.<locals>.Callback.__call__N)__name__
__module____qualname__r.   r0   r   r   r   r   Callback    s    r4   ineqtyper   cobyla)methodconstraintscallbackoptionsr'   r(   r
   F   MbP?z<Callback is not called exactly once for every function eval.zGLast design vector sent to the callback is not equal to returned value.)r"   r$   r   r   r   r   r   r   r   r   successmessagemaxcvZnfevr,   r   r-   )r   r4   r;   conssolr   r   r   test_minimize_simple   s&   	


zTestCobyla.test_minimize_simplec                    s   t jd t jddt jdfdd fdd} fdd} fd	d
} fdd}d|dd|dd|df}t d}t||d|ddid}t|jdk t|j  d S )Ni  
   c                    s
     | S r#   )dotw)pbr   r   p?   s   
z8TestCobyla.test_minimize_constraint_violation.<locals>.pc                    s   |      S r#   )sumrG   )spreadr   r   fB      z8TestCobyla.test_minimize_constraint_violation.<locals>.fc                       dt  |   S )Ni  r   rK   rG   rJ   r   r   c1E      z9TestCobyla.test_minimize_constraint_violation.<locals>.c1c                    s   dt  |   S N   rP   rG   rQ   r   r   c2H   rS   z9TestCobyla.test_minimize_constraint_violation.<locals>.c2c                    rO   rT   )r   maxrG   rQ   r   r   c3K   rS   z9TestCobyla.test_minimize_constraint_violation.<locals>.c3r5   r6   )rE   r8   Zcatolgư>)r9   r:   r<   )	nprandomseedZrandZzerosr   r   rA   r?   )r   rM   rR   rV   rX   rB   Zw0rC   r   )rJ   rI   rL   r   "test_minimize_constraint_violation:   s$   

z-TestCobyla.test_minimize_constraint_violationN)
r1   r2   r3   r   r   r"   r$   r)   rD   r\   r   r   r   r   r   	   s    r   c            	         s  dd   fdd} dd }dd }t d	d
g} ||g}ddg}d}t ||dd}t||dd t || dd}t |ddd dd |D }t ||dd}t|j|dd t|j|j t|j	|dd d| d}t ||dd}t|j	ddd d S )Nc                 S   s    | d d d | d d d  S )Nr   r	   r   g      @r   r   r   r   r   r   [   s    z$test_vector_constraints.<locals>.func                    s    | d S r/   r   r]   r   r   r   fmin^   r%   z%test_vector_constraints.<locals>.fminc                    s>   t g dg dg dg t  fddtt D S )N)r	   r   )r`      )ra   r   r   c                    s@   g | ]} |d f d    |df d    |df  qS )r   r	   r   r   ).0iar   r   r   
<listcomp>c   s
    &
z:test_vector_constraints.<locals>.cons1.<locals>.<listcomp>)rY   arrayrangelenr]   r   re   r   cons1a   s   
z&test_vector_constraints.<locals>.cons1c                 S   s   | S r#   r   r]   r   r   r   cons2f   s   z&test_vector_constraints.<locals>.cons2r   r   gffffff?g333333?g?r
   )r&   r'   r(   r	   c                 S   s   g | ]}d |dqS )r5   r6   r   )rc   rB   r   r   r   rg   w   s    z+test_vector_constraints.<locals>.<listcomp>)r:   r   r5   r6   )
rY   rh   r   r   r   r   r   r?   r@   r   )	r_   rk   rl   r   Z	cons_listZxsolZfsolrC   r:   r   r^   r   test_vector_constraintsX   s(   

rm   c                   @   r*   )
TestBoundsc                 C   sf   dd }g d}g d}dd t ||D }t|g dd|d	}g d
}|js)J t|j|dd d S )Nc                 S      t | d S Nr   rY   rK   r]   r   r   r   rM      rN   z TestBounds.test_basic.<locals>.f)ra   Nr	   N      )rr   rr   NNrr   c                 S   s   g | ]\}}||fqS r   r   )rc   rf   br   r   r   rg      s    z)TestBounds.test_basic.<locals>.<listcomp>)r	   r   r      rU   r8   r   r9   bounds)rr   rr   r	   r   rr   r>   r(   )zipr   r?   r   r   )r   rM   ZlbZubrv   resrefr   r   r   
test_basic   s   
zTestBounds.test_basicc                 C   s   dd }t tj tj gtjtjg}t|ddgd|d}|js"J t|jddd	 t dtj gtjtjg}t|ddgd|d}|jsFJ t|jddgdd	 d S )
Nc                 S   ro   rp   rq   r]   r   r   r   rM      rN   z$TestBounds.test_unbounded.<locals>.fr	   r   r8   ru   r   r>   r(   )r   rY   infr   r?   r   r   )r   rM   rv   rx   r   r   r   test_unbounded   s   

zTestBounds.test_unboundedN)r1   r2   r3   rz   r|   r   r   r   r   rn      s    rn   )r   numpyrY   Znumpy.testingr   r   r   Zscipy.optimizer   r   r   r   rm   rn   r   r   r   r   <module>   s    O*