a
    ==icô/  ã                   @   s@   d dl mZmZmZmZ d dlZe e¡ZG dd„ dej	ƒZ
dS )é    )ÚcontrolÚcoreÚ	test_utilÚ	workspaceNc                       st  e Zd Z‡ f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%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Zd7d8„ Zd9d:„ Zd;d<„ Z d=d>„ Z!d?d@„ Z"dAdB„ Z#dCdD„ Z$dEdF„ Z%dGdH„ Z&dIdJ„ Z'dKdL„ Z(dMdN„ Z)dOdP„ Z*dQdR„ Z+dSdT„ Z,dUdV„ Z-dWdX„ Z.‡  Z/S )YÚTestControlc           	         sØ  t t| ƒ ¡  d| _t d¡| _| jjg dd}| jjg g | jtj	j
d}| jjg g dtj	j
d}t d¡| _| j |g¡ | j |g¡}| jjg |gg dtj	j
d | j |¡ t d¡| _| j |g¡ | j |g¡ | j |g¡}| jjg |gg dtj	j
d | j |¡ t d¡| _| j ||g¡}| j |¡ t d	¡| _| j ||g¡}| j |¡ t d
¡| _| j ||g¡}| j |¡ t d¡| _| j ||g¡}| j |¡ t d¡| _| jjg g dtj	j
d d S )Né
   zinit-netr   )Z
init_count)ÚshapeÚvalueZdtypezcnt-netz	cnt-2-netzcond-netznot-cond-netztrue-cond-netzfalse-cond-netzidle-net)Úsuperr   ÚsetUpÚN_r   ZNetÚ	init_net_ZCreateCounterZConstantFillZDataTypeZINT64Úcnt_net_ZCountUpZRetrieveCountZAddExternalOutputÚ
cnt_2_net_Ú	cond_net_ÚLTÚnot_cond_net_ZGEÚtrue_cond_net_Úfalse_cond_net_ÚGTÚ	idle_net_)	ÚselfZcntZconst_nZconst_0Zcurr_cntZ
curr_cnt_2Z	cond_blobZ	true_blobZ
false_blob©Ú	__class__© úk/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/caffe2/python/control_test.pyr      sR    ÿÿÿÿÿzTestControl.setUpc                 C   s2   |D ](\}}t  | ¡ jd ¡}|  ||¡ qdS )zm
        Check the net output is expected
        nets_and_expects is a list of tuples (net, expect)
        éÿÿÿÿN)r   Ú	FetchBlobÚProtoÚexternal_outputÚassertEqual)r   Znets_and_expectsÚnetÚexpectÚoutputr   r   r   ÚCheckNetOutput;   s
    ÿzTestControl.CheckNetOutputc                 C   sT   |   t| ¡ jƒt|ƒ¡ tt|ƒƒD ](}t | ¡ j| ¡}|   ||| ¡ q&dS )zV
        Check the net output is expected
        expects is a list of bools.
        N)r    Úlenr   r   Úranger   r   )r   r!   ZexpectsÚir#   r   r   r   ÚCheckNetAllOutputE   s    ÿzTestControl.CheckNetAllOutputc                 C   s>   t  d¡}| t d| j¡¡ | |¡ |  t |¡d¡ d S )NÚtestÚinitT)	r   ZPlanZAddStepr   ÚDor   r    r   ZRunPlan)r   ÚstepZplanr   r   r   ÚBuildAndRunPlanP   s    

zTestControl.BuildAndRunPlanc                 C   s2   t  d|| j¡}|  |¡ |  | j| jfg¡ d S )NZmyFor)r   ÚForr   r-   r$   r   ©r   Znets_or_stepsr,   r   r   r   ÚForLoopTestV   s    
zTestControl.ForLoopTestc                 C   s"   |   | j¡ |   | j| jg¡ d S ©N)r0   r   r   ©r   r   r   r   ÚtestForLoopWithNets[   s    zTestControl.testForLoopWithNetsc                 C   s,   t  d| j¡}|  |¡ |  || jg¡ d S ©NÚcount)r   r+   r   r0   r   ©r   r,   r   r   r   ÚtestForLoopWithStep_   s    
zTestControl.testForLoopWithStepc                 C   s2   t  d| j|¡}|  |¡ |  | j| jfg¡ d S )NZmyWhile)r   ÚWhiler   r-   r$   r   r   r/   r   r   r   ÚWhileLoopTestd   s    
zTestControl.WhileLoopTestc                 C   s"   |   | j¡ |   | j| jg¡ d S r1   )r9   r   r   r2   r   r   r   ÚtestWhileLoopWithNeti   s    z TestControl.testWhileLoopWithNetc                 C   s,   t  d| j¡}|  |¡ |  || jg¡ d S r4   )r   r+   r   r9   r   r6   r   r   r   ÚtestWhileLoopWithStepm   s    
z!TestControl.testWhileLoopWithStepc                 C   s2   t  d| j|¡}|  |¡ |  | j| jfg¡ d S )NZmyUntil)r   ZUntilr   r-   r$   r   r   r/   r   r   r   ÚUntilLoopTestr   s    
zTestControl.UntilLoopTestc                 C   s"   |   | j¡ |   | j| jg¡ d S r1   )r<   r   r   r2   r   r   r   ÚtestUntilLoopWithNetw   s    z TestControl.testUntilLoopWithNetc                 C   s,   t  d| j¡}|  |¡ |  || jg¡ d S r4   )r   r+   r   r<   r   r6   r   r   r   ÚtestUntilLoopWithStep{   s    
z!TestControl.testUntilLoopWithStepc                 C   s2   t  d| j|¡}|  |¡ |  | j| jfg¡ d S )NZ	myDoWhile)r   ZDoWhiler   r-   r$   r   r   r/   r   r   r   ÚDoWhileLoopTest€   s    
zTestControl.DoWhileLoopTestc                 C   s"   |   | j¡ |   | j| jg¡ d S r1   )r?   r   r   r2   r   r   r   ÚtestDoWhileLoopWithNet…   s    z"TestControl.testDoWhileLoopWithNetc                 C   s,   t  d| j¡}|  |¡ |  | j|g¡ d S r4   )r   r+   r   r?   r   r6   r   r   r   ÚtestDoWhileLoopWithStep‰   s    
z#TestControl.testDoWhileLoopWithStepc                 C   s2   t  d| j|¡}|  |¡ |  | j| jfg¡ d S )NZ	myDoUntil)r   ZDoUntilr   r-   r$   r   r   r/   r   r   r   ÚDoUntilLoopTestŽ   s    
zTestControl.DoUntilLoopTestc                 C   s"   |   | j¡ |   | j| jg¡ d S r1   )rB   r   r   r2   r   r   r   ÚtestDoUntilLoopWithNet“   s    z"TestControl.testDoUntilLoopWithNetc                 C   s,   t  d| j¡}|  |¡ |  | j|g¡ d S r4   )r   r+   r   rB   r   r6   r   r   r   ÚtestDoUntilLoopWithStep—   s    
z#TestControl.testDoUntilLoopWithStepc              	   C   sb   |r2t  dt  d|¡t  d| ¡ jd | j¡¡}nt  d|| j¡}|  |¡ |  | j|fg¡ d S )Nzif-allr5   ZmyIfr   )r   r+   ÚIfr   r   r   r-   r$   ©r   Úcond_netr"   Úcond_on_blobr,   r   r   r   Ú
IfCondTestœ   s    
ÿý
zTestControl.IfCondTestc                 C   s   |   | jdd¡ d S ©Né   F©rI   r   r2   r   r   r   ÚtestIfCondTrueOnNet¨   s    zTestControl.testIfCondTrueOnNetc                 C   s   |   | jdd¡ d S ©NrK   TrL   r2   r   r   r   ÚtestIfCondTrueOnBlob«   s    z TestControl.testIfCondTrueOnBlobc                 C   s   |   | jdd¡ d S ©Nr   F©rI   r   r2   r   r   r   ÚtestIfCondFalseOnNet®   s    z TestControl.testIfCondFalseOnNetc                 C   s   |   | jdd¡ d S ©Nr   TrQ   r2   r   r   r   ÚtestIfCondFalseOnBlob±   s    z!TestControl.testIfCondFalseOnBlobc              
   C   sz   |r| j }n| j}|rHt dt d|¡t d| ¡ jd | j | j¡¡}nt d|| j | j¡}|  |¡ |  ||fg¡ d S )Nzif-else-allr5   ZmyIfElser   )	r   r   r   r+   rE   r   r   r-   r$   ©r   rG   Z
cond_valuer"   rH   Zrun_netr,   r   r   r   ÚIfElseCondTest´   s     
ÿýÿ
zTestControl.IfElseCondTestc                 C   s   |   | jddd¡ d S )NTrK   F©rV   r   r2   r   r   r   ÚtestIfElseCondTrueOnNetÅ   s    z#TestControl.testIfElseCondTrueOnNetc                 C   s   |   | jddd¡ d S )NTrK   rW   r2   r   r   r   ÚtestIfElseCondTrueOnBlobÈ   s    z$TestControl.testIfElseCondTrueOnBlobc                 C   s   |   | jddd¡ d S )NFé   ©rV   r   r2   r   r   r   ÚtestIfElseCondFalseOnNetË   s    z$TestControl.testIfElseCondFalseOnNetc                 C   s   |   | jddd¡ d S )NFrZ   Tr[   r2   r   r   r   ÚtestIfElseCondFalseOnBlobÎ   s    z%TestControl.testIfElseCondFalseOnBlobc              	   C   sb   |r2t  dt  d|¡t  d| ¡ jd | j¡¡}nt  d|| j¡}|  |¡ |  | j|fg¡ d S )Nzif-notr5   ZmyIfNotr   )r   r+   ÚIfNotr   r   r   r-   r$   rF   r   r   r   ÚIfNotCondTestÑ   s    
ÿý
zTestControl.IfNotCondTestc                 C   s   |   | jdd¡ d S rP   ©r_   r   r2   r   r   r   ÚtestIfNotCondTrueOnNetÝ   s    z"TestControl.testIfNotCondTrueOnNetc                 C   s   |   | jdd¡ d S rS   r`   r2   r   r   r   ÚtestIfNotCondTrueOnBlobà   s    z#TestControl.testIfNotCondTrueOnBlobc                 C   s   |   | jdd¡ d S rJ   ©r_   r   r2   r   r   r   ÚtestIfNotCondFalseOnNetã   s    z#TestControl.testIfNotCondFalseOnNetc                 C   s   |   | jdd¡ d S rN   rc   r2   r   r   r   ÚtestIfNotCondFalseOnBlobæ   s    z$TestControl.testIfNotCondFalseOnBlobc              
   C   sz   |r| j }n| j}|rHt dt d|¡t d| ¡ jd | j| j ¡¡}nt d|| j| j ¡}|  |¡ |  ||fg¡ d S )Nzif-not-elser5   ZmyIfNotElser   )	r   r   r   r+   r^   r   r   r-   r$   rU   r   r   r   ÚIfNotElseCondTesté   s"    
þýÿ
zTestControl.IfNotElseCondTestc                 C   s   |   | jddd¡ d S )NTrZ   F©rf   r   r2   r   r   r   ÚtestIfNotElseCondTrueOnNetû   s    z&TestControl.testIfNotElseCondTrueOnNetc                 C   s   |   | jddd¡ d S )NTrZ   rg   r2   r   r   r   ÚtestIfNotElseCondTrueOnBlobþ   s    z'TestControl.testIfNotElseCondTrueOnBlobc                 C   s   |   | jddd¡ d S )NFrK   ©rf   r   r2   r   r   r   ÚtestIfNotElseCondFalseOnNet  s    z'TestControl.testIfNotElseCondFalseOnNetc                 C   s   |   | jddd¡ d S )NFrK   Trj   r2   r   r   r   ÚtestIfNotElseCondFalseOnBlob  s    z(TestControl.testIfNotElseCondFalseOnBlobc                 C   sF   t  d| j| jf| j| jf¡}|  |¡ |  | jdf| jdfg¡ d S )NZmySwitchr   rZ   )r   ZSwitchr   r   r   r   r-   r$   r6   r   r   r   Ú
testSwitch  s    

ý
zTestControl.testSwitchc                 C   sF   t  d| j| jf| j| jf¡}|  |¡ |  | jdf| jdfg¡ d S )NZmySwitchNotrK   r   )r   Z	SwitchNotr   r   r   r   r-   r$   r6   r   r   r   ÚtestSwitchNot  s    

ý
zTestControl.testSwitchNotc                 C   s˜   t  d¡}t  d|¡}|  |¡ |  |dg¡ t  dd¡}t  d|¡}|  |¡ |  |ddg¡ t  ddg¡}t  d|¡}|  |¡ |  |ddg¡ d S )N)ÚaTÚboolT)ÚbFF)r   ZBoolNetr+   r-   r(   )r   Zbool_netr,   r   r   r   ÚtestBoolNet  s    



zTestControl.testBoolNetc                 C   sŒ   t  d| j| jgd¡}t  d| j| j|¡}|  |¡ |  |dfg¡ t  d| j| jgd¡}t  d| j| j|¡}|  |¡ |  |dfg¡ d S )Nr)   ÚOrÚcombineTÚAndF)r   ZCombineConditionsr   r   r+   r-   r$   )r   Zcombine_netr,   r   r   r   ÚtestCombineConditions)  s(    ÿý
ÿý
z!TestControl.testCombineConditionsc                 C   s|   t  d| j| jgd¡}t  d|¡}|  |¡ |  |dfg¡ t  d| j| jgd¡}t  d|¡}|  |¡ |  |dfg¡ d S )Nr)   rs   ÚmergeTru   F)r   ZMergeConditionNetsr   r   r+   r-   r$   )r   Z	merge_netr,   r   r   r   ÚtestMergeConditionNets>  s    ÿ
ÿ
z"TestControl.testMergeConditionNets)0Ú__name__Ú
__module__Ú__qualname__r   r$   r(   r-   r0   r3   r7   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rI   rM   rO   rR   rT   rV   rX   rY   r\   r]   r_   ra   rb   rd   re   rf   rh   ri   rk   rl   rm   rn   rr   rv   rx   Ú__classcell__r   r   r   r   r      sX   .
		r   )Zcaffe2.pythonr   r   r   r   ÚloggingÚ	getLoggerry   ÚloggerZTestCaser   r   r   r   r   Ú<module>   s   
