a
    ³ÐOc7V  ã                   @   s`  d dl Z d dlZd dlZd dlZd dlZd dlZd dlmZ ddl	m
Z
 dadd„ Zdd„ Zd	d
„ ZG dd„ dƒZeƒ Zg d¢ZddgiZed dg ed< ed dg ed< dged< dged< ed ddg ed< ed ddg ed< ed ddg ed< ed ddg ed< ed dg ed< ed dg ed< ed dg ed< ed dg ed< ed ddg ed< ed g d¢ ed< ed dg ed< e ¡ jjdk�s¸e ¡ jjdk�r$ejdk�r$e ¡ e ¡ fd k�r$e g d!¢¡ ed g d"¢ ed#< ed# g d$¢ ed%< ed dd&g ed&< G d'd(„ d(ƒZG d)d*„ d*ƒZG d+d,„ d,ƒZG d-d.„ d.ƒZdS )/é    N)Útypeinfoé   )Úutilc                  C   sb   t  ¡ st d¡ tdu r^d} tj t¡}t  	dddd¡t  	dd¡t  	dd	¡g}t  
|| d
¡adS )z6
    Build the required testing extension module

    zNo C compiler availableNz¼
        config.add_extension('test_array_from_pyobj_ext',
                             sources=['wrapmodule.c', 'fortranobject.c'],
                             define_macros=[])
        ÚtestsÚsrcZarray_from_pyobjzwrapmodule.czfortranobject.czfortranobject.hZtest_array_from_pyobj_ext)r   Zhas_c_compilerÚpytestÚskipÚwrapÚosÚpathÚdirnameÚ__file__ZgetpathZbuild_module_distutils)Zconfig_codeÚdr   © r   ú]/var/www/html/gsl.tools/lib/python3.9/site-packages/numpy/f2py/tests/test_array_from_pyobj.pyÚsetup_module   s    


ýÿr   c                 C   s   t  | ¡d }t|ƒS )Né   )r	   Úarray_attrsÚflags2names)ÚarrÚflagsr   r   r   Ú
flags_info*   s    r   c                 C   s0   g }dD ]"}t | ƒtt|dƒ@ r| |¡ q|S )N)Ú
CONTIGUOUSÚFORTRANÚOWNDATAZ
ENSURECOPYZENSUREARRAYZALIGNEDZ
NOTSWAPPEDÚ	WRITEABLEZWRITEBACKIFCOPYZBEHAVEDZ
BEHAVED_ROZCARRAYZFARRAYr   )ÚabsÚgetattrr	   Úappend)r   ÚinfoZflagnamer   r   r   r   /   s
    r   c                   @   s@   e Zd Zg fdd„Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚIntentc                 C   sP   |d d … | _ d}|D ].}|dkr.|tjO }q|ttd| ¡  ƒO }q|| _d S )Nr   ÚoptionalZF2PY_INTENT_)Úintent_listr	   ZF2PY_OPTIONALr   Úupperr   )Úselfr"   r   Úir   r   r   Ú__init__F   s    zIntent.__init__c                 C   s&   |  ¡ }|dkrd}|  | j|g ¡S )NÚin_Úin)ÚlowerÚ	__class__r"   )r$   Únamer   r   r   Ú__getattr__P   s    zIntent.__getattr__c                 C   s   dd  | j¡ S )Nz
intent(%s)ú,)Újoinr"   ©r$   r   r   r   Ú__str__V   s    zIntent.__str__c                 C   s
   d| j  S )Nz
Intent(%r)©r"   r/   r   r   r   Ú__repr__Y   s    zIntent.__repr__c                 G   s   |D ]}|| j vr dS qdS )NFTr1   )r$   Únamesr+   r   r   r   Ú	is_intent\   s    
zIntent.is_intentc                 G   s   t | jƒt |ƒko| j|Ž S ©N)Úlenr"   r4   )r$   r3   r   r   r   Úis_intent_exactb   s    zIntent.is_intent_exactN)	Ú__name__Ú
__module__Ú__qualname__r&   r,   r0   r2   r4   r7   r   r   r   r   r    E   s   
r    )ÚBOOLÚBYTEÚUBYTEÚSHORTÚUSHORTÚINTÚUINTÚLONGÚULONGÚLONGLONGÚ	ULONGLONGÚFLOATÚDOUBLEÚCFLOATr;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   )rA   rF   rG   rG   rH   é   é   Úwin32)ÚDarwinÚarm)Ú
LONGDOUBLEÚCDOUBLEÚCLONGDOUBLE)rC   rF   rG   rN   rN   )rH   rO   rP   rP   rO   c                   @   sH   e Zd Zi Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dd„ Z
dS )ÚTypec                 C   sˆ   t |tjƒrD|}d }t ¡ D ]&\}}t |tƒs|j|ju r|} qDq| j | ¡ d ¡}|d urb|S t	 
| ¡}| |¡ || j| ¡ < |S r5   )Ú
isinstanceÚnpÚdtyper   ÚitemsÚtypeÚ_type_cacheÚgetr#   ÚobjectÚ__new__Ú_init)Úclsr+   Zdtype0Únr%   Úobjr   r   r   rZ   ©   s    

zType.__new__c                 C   sd   |  ¡ | _t| j }ttd| j ƒ| _| j|jks6J ‚t |j	¡| _|j	| _	|j
d | _|j| _d S )NZNPY_rJ   )r#   ÚNAMEr   r   r	   Útype_numÚnumrS   rT   rV   ÚbitsÚelsizeÚcharÚ	dtypechar)r$   r+   r   r   r   r   r[   ¹   s    

z
Type._initc                    s   ‡ fdd„t ˆ j D ƒS )Nc                    s   g | ]}ˆ   |¡‘qS r   ©r*   ©Ú.0Ú_mr/   r   r   Ú
<listcomp>Ä   ó    z#Type.cast_types.<locals>.<listcomp>)Ú
_cast_dictr_   r/   r   r/   r   Ú
cast_typesÃ   s    zType.cast_typesc                    s   ‡ fdd„t D ƒS )Nc                    s   g | ]}ˆ   |¡‘qS r   rf   rg   r/   r   r   rj   Ç   rk   z"Type.all_types.<locals>.<listcomp>)Ú_type_namesr/   r   r/   r   Ú	all_typesÆ   s    zType.all_typesc                 C   s:   t | j j}g }tD ] }t | j|k r| t|ƒ¡ q|S r5   ©r   r_   Ú	alignmentrn   r   rQ   ©r$   rb   Útypesr+   r   r   r   Úsmaller_typesÉ   s    zType.smaller_typesc                 C   sF   t | j j}g }tD ],}|| jkr$qt | j|kr| t|ƒ¡ q|S r5   rp   rr   r   r   r   Úequal_typesÑ   s    
zType.equal_typesc                 C   s:   t | j j}g }tD ] }t | j|kr| t|ƒ¡ q|S r5   rp   rr   r   r   r   Úlarger_typesÛ   s    zType.larger_typesN)r8   r9   r:   rW   rZ   r[   rm   ro   rt   ru   rv   r   r   r   r   rQ   ¦   s   

rQ   c                   @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚArrayc                 C   s(  || _ || _|| _t |¡| _|| _t |j	||j
|¡| _t| jtjƒsLJ ‚t | j¡| _t|ƒdkrü| j d¡r¸|j
tj@ s‚J ‚| jj
d r’J ‚| jj
d s¢J ‚| jd tj@ rüJ ‚nD|j
tj@ rÈJ ‚| jj
d sØJ ‚| jj
d rèJ ‚| jd tj@ süJ ‚|d u �rd | _d | _d S | d¡�rXt|tjƒ�s@J tt |ƒƒƒ‚t |¡j|Ž  ¡ | _nHtjtj||jd�j|Ž | j d¡�r„d�p†d	d
�| _| jj|k�s J ‚| jj| jj
d d� | jj
d �sÐJ ||fƒ‚t | j¡| _t|ƒdk�rp| j d¡�r6| jj
d �rJ ‚| jj
d �sJ ‚| jd tj@ �rpJ ‚n:| jj
d �sHJ ‚| jj
d �rZJ ‚| jd tj@ �spJ ‚| jd | jd k�sŠJ ‚| jd | jd k�s¤J ‚| jd dk�rö| jd | jd k�söJ t| jd | jd | j ¡ | j ¡ fƒƒ‚| jd dd … | jd dd … k�s J ‚| jd | jd k�szJ t| jd | jd td| jd  | jd  ƒt| jd ƒ|fƒƒ‚| d¡�r¤| jd d | j jk�sÖJ ‚n2| jd d | j jk�sÀJ ‚|   | j| j¡�sÖJ ‚t| jtjƒ�r$|jt!|jƒjk�r$| d¡�s$| jd dk�r$|  "¡ �s$J ‚d S )Nr   Úcr   r   r   Úcache©rT   ÚCÚF)Úorderr   ©Úwriter   é   é   é   éþÿÿÿr   Úcopy)#rV   ÚdimsÚintentr„   ÚdeepcopyZobj_copyr^   r	   Úcallr`   r   r   rR   rS   Úndarrayr   Úarr_attrr6   r4   ZF2PY_INTENT_Cr   ZpyarrZ
pyarr_attrÚreprÚarrayZreshapere   rT   ÚsetflagsÚtobytesr   rc   Ú	arr_equalrQ   Úhas_shared_memory)r$   Útypr…   r†   r^   r   r   r   r&   å   s„    
þü*ûzArray.__init__c                 C   s   |j |j krdS ||k ¡ S )NF)ÚshapeÚall)r$   Zarr1Zarr2r   r   r   r�   8  s    zArray.arr_equalc                 C   s
   t | jƒS r5   )Ústrr   r/   r   r   r   r0   =  s    zArray.__str__c                 C   s@   | j | ju rdS t| j tjƒs"dS t | j ¡}|d | jd kS )z6Check that created array shares data with input array.TFr   )r^   r   rR   rS   r‰   r	   r   rŠ   )r$   Zobj_attrr   r   r   r�   @  s    zArray.has_shared_memoryN)r8   r9   r:   r&   r�   r0   r�   r   r   r   r   rw   ä   s   Srw   c                   @   s   e Zd Zdd„ ZdS )Ú
TestIntentc                 C   st   t tjjƒdksJ ‚tjj d¡s&J ‚tjj d¡r8J ‚tjj dd¡sLJ ‚tjj dd¡s`J ‚tj d¡rpJ ‚d S )Nzintent(in,out)rx   r(   )r”   r†   r'   Úoutrx   r4   r7   r/   r   r   r   Útest_in_outK  s    zTestIntent.test_in_outN)r8   r9   r:   r—   r   r   r   r   r•   J  s   r•   c                   @   s"  e Zd ZddgZg d¢g d¢gZejdded�dd	„ ƒZd
d„ Z	dd„ Z
ej dddg¡ej dddg¡ej dddg¡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?S )@ÚTestSharedMemoryr   r€   )r   r€   r�   )rI   r‚   r   TÚclass)ZautouseZscopeÚparamsc                    s"   t ˆ jƒˆ j_‡ fdd„ˆ j_d S )Nc                    s   t tˆ jƒ|||ƒS r5   )rw   rQ   Úparam)r$   r…   r†   r^   ©Úrequestr   r   Ú<lambda>[  s   ÿz-TestSharedMemory.setup_type.<locals>.<lambda>)rQ   r›   r\   rV   rŒ   )r$   r�   r   rœ   r   Ú
setup_typeX  s    zTestSharedMemory.setup_typec                 C   s$   |   dgtj| j¡}| ¡ r J ‚d S )Nr€   )rŒ   r†   r'   Únum2seqr�   ©r$   Úar   r   r   Útest_in_from_2seq^  s    z"TestSharedMemory.test_in_from_2seqc                 C   sx   | j  ¡ D ]h}tj| j|jd�}|  t| jƒgtj|¡}|j	| j j	krf| 
¡ srJ t| j j|jfƒƒ‚q
| 
¡ r
J ‚q
d S ©Nrz   )rV   rm   rS   rŒ   r    rT   r6   r†   r'   rc   r�   r‹   ©r$   Útr^   r¢   r   r   r   Útest_in_from_2casttypeb  s     z'TestSharedMemory.test_in_from_2casttyper   ÚwÚror}   r{   r|   ÚinpZ2seqZ23seqc                 C   sd   t | d| ƒ}tj|| jj|d�}|j|dkd� |  |j|dkrJtjj	pNtj|¡}| 
¡ s`J ‚dS )z5Test if intent(in) array can be passed without copiesra   ©rT   r}   r¨   r~   r{   N)r   rS   rŒ   rV   rT   r�   r’   r†   r'   rx   r�   )r$   r   r}   rª   Úseqr^   r¢   r   r   r   Útest_in_nocopyk  s    ÿzTestSharedMemory.test_in_nocopyc              
   C   s”   t j| j| jjd�}|  t| jƒgtj|¡}| ¡ s8J ‚z|  dgtj	j| j¡}W n4 t
y† } zt|ƒ d¡sr‚ W Y d }~nd }~0 0 tdƒ‚d S )Nrz   r€   z6failed to initialize intent(inout|inplace|cache) arrayz,intent(inout) should have failed on sequence)rS   rŒ   r    rV   rT   r6   r†   Úinoutr�   r'   Ú	TypeErrorr”   Ú
startswithÚSystemError)r$   r^   r¢   Úmsgr   r   r   Útest_inout_2seqw  s    ÿz TestSharedMemory.test_inout_2seqc              
   C   sÒ   t j| j| jjdd�}t| jƒt| jd ƒf}|  |tjj|¡}| 	¡ sLJ ‚t j| j| jjdd�}t| jƒt| jd ƒf}z|  |tjj|¡}W n4 t
yÄ } zt|ƒ d¡s°‚ W Y d }~nd }~0 0 tdƒ‚d S )Nr|   r«   r   r{   z(failed to initialize intent(inout) arrayz2intent(inout) should have failed on improper array)rS   rŒ   Únum23seqrV   rT   r6   r†   r'   r®   r�   Ú
ValueErrorr”   r°   r±   )r$   r^   r’   r¢   r²   r   r   r   Útest_f_inout_23seq…  s     ÿÿz#TestSharedMemory.test_f_inout_23seqc                 C   sP   t j| j| jjd�}t| jƒt| jd ƒf}|  |tjjj	|¡}| 
¡ sLJ ‚d S ©Nrz   r   )rS   rŒ   r´   rV   rT   r6   r†   r'   rx   r®   r�   ©r$   r^   r’   r¢   r   r   r   Útest_c_inout_23seq—  s    z#TestSharedMemory.test_c_inout_23seqc                 C   sL   | j  ¡ D ]<}tj| j|jd�}|  t| jƒgtjj	|¡}| 
¡ r
J ‚q
d S r¤   )rV   rm   rS   rŒ   r    rT   r6   r†   r'   r„   r�   r¥   r   r   r   Útest_in_copy_from_2casttype�  s    z,TestSharedMemory.test_in_copy_from_2casttypec                 C   s6   |   t| jƒt| jd ƒgtj| j¡}| ¡ r2J ‚d S ©Nr   )rŒ   r6   r´   r†   r'   r�   r¡   r   r   r   Útest_c_in_from_23seq£  s
    þz%TestSharedMemory.test_c_in_from_23seqc                 C   sV   | j  ¡ D ]F}tj| j|jd�}|  t| jƒt| jd ƒgtj|¡}| 	¡ r
J ‚q
d S r·   )
rV   rm   rS   rŒ   r´   rT   r6   r†   r'   r�   r¥   r   r   r   Útest_in_from_23casttype©  s    ÿz(TestSharedMemory.test_in_from_23casttypec                 C   st   | j  ¡ D ]d}tj| j|jdd�}|  t| jƒt| jd ƒgtj|¡}|j	| j j	krb| 
¡ snJ ‚q
| 
¡ r
J ‚q
d S ©Nr|   r«   r   )rV   rm   rS   rŒ   r´   rT   r6   r†   r'   rc   r�   r¥   r   r   r   Útest_f_in_from_23casttype°  s    ÿz*TestSharedMemory.test_f_in_from_23casttypec                 C   st   | j  ¡ D ]d}tj| j|jd�}|  t| jƒt| jd ƒgtjj	|¡}|j
| j j
krb| ¡ snJ ‚q
| ¡ r
J ‚q
d S r·   )rV   rm   rS   rŒ   r´   rT   r6   r†   r'   rx   rc   r�   r¥   r   r   r   Útest_c_in_from_23casttypeº  s    ÿz*TestSharedMemory.test_c_in_from_23casttypec                 C   sZ   | j  ¡ D ]J}tj| j|jdd�}|  t| jƒt| jd ƒgtjj	|¡}| 
¡ r
J ‚q
d S r¾   )rV   rm   rS   rŒ   r´   rT   r6   r†   r'   r„   r�   r¥   r   r   r   Útest_f_copy_in_from_23casttypeÄ  s    þz/TestSharedMemory.test_f_copy_in_from_23casttypec                 C   sZ   | j  ¡ D ]J}tj| j|jd�}|  t| jƒt| jd ƒgtjj	j
|¡}| ¡ r
J ‚q
d S r·   )rV   rm   rS   rŒ   r´   rT   r6   r†   r'   rx   r„   r�   r¥   r   r   r   Útest_c_copy_in_from_23casttypeÌ  s    þz/TestSharedMemory.test_c_copy_in_from_23casttypec                 C   s@  | j  ¡ D �].}|j| j jkr q
tj| j|jd�}t| jƒf}|  |tj	j
j|¡}| ¡ s^J ‚|  |tj	j|¡}| ¡ s|J ‚tj| j|jdd�}|  |tj	j
j|¡}| ¡ s°J ‚|  |tj	j|¡}| ¡ sØJ t|jƒƒ‚z |  |tj	j|d d d… ¡}W n8 t�y0 } zt|ƒ d¡�s‚ W Y d }~q
d }~0 0 tdƒ‚q
d S )Nrz   r|   r«   éÿÿÿÿú(failed to initialize intent(cache) arrayz8intent(cache) should have failed on multisegmented array)rV   ro   rc   rS   rŒ   r    rT   r6   r†   r'   rx   ry   r�   r‹   rµ   r”   r°   r±   )r$   r¦   r^   r’   r¢   r²   r   r   r   Útest_in_cache_from_2casttypeÔ  s0     ÿÿz-TestSharedMemory.test_in_cache_from_2casttypec                 C   s–   | j  ¡ D ]†}|j| j jkrq
tj| j|jd�}t| jƒf}z|  |tj	j
|¡ W n4 ty† } zt|ƒ d¡sr‚ W Y d }~q
d }~0 0 tdƒ‚q
d S )Nrz   rÄ   z1intent(cache) should have failed on smaller array)rV   ro   rc   rS   rŒ   r    rT   r6   r†   r'   ry   rµ   r”   r°   r±   )r$   r¦   r^   r’   r²   r   r   r   Ú$test_in_cache_from_2casttype_failureñ  s    ÿÿz5TestSharedMemory.test_in_cache_from_2casttype_failurec              
   C   s¨   d}|   |tjjd ¡}|jj|ks&J ‚d}|   |tjjd ¡}|jj|ksLJ ‚d}z|   |tjjd ¡}W n4 tyš } zt|ƒ d¡s†‚ W Y d }~nd }~0 0 t	dƒ‚d S )N©r€   ©r€   r�   ©rÃ   r�   ú2failed to create intent(cache|hide)|optional arrayz8intent(cache) should have failed on undefined dimensions)
rŒ   r†   ry   Úhider   r’   rµ   r”   r°   r±   ©r$   r’   r¢   r²   r   r   r   Útest_cache_hidden  s"    ÿÿz"TestSharedMemory.test_cache_hiddenc              
   C   sh  d}|   |tjd ¡}|jj|ks$J ‚| |jtj|| jj	d�¡sDJ ‚d}|   |tjd ¡}|jj|kshJ ‚| |jtj|| jj	d�¡sˆJ ‚|jj
d r |jj
d r¤J ‚d}|   |tjjd ¡}|jj|ksÊJ ‚| |jtj|| jj	d�¡sêJ ‚|jj
d �s|jj
d �s
J ‚d}z|   |tjd ¡}W n8 t�yZ } zt|ƒ d¡�sF‚ W Y d }~nd }~0 0 tdƒ‚d S )	NrÇ   rz   rÈ   r   r   rÉ   rÊ   z7intent(hide) should have failed on undefined dimensions)rŒ   r†   rË   r   r’   r�   rS   ÚzerosrV   rT   r   rx   rµ   r”   r°   r±   rÌ   r   r   r   Útest_hidden  s2        ÿÿzTestSharedMemory.test_hiddenc                 C   s  d}|   |tjd ¡}|jj|ks$J ‚| |jtj|| jj	d�¡sDJ ‚d}|   |tjd ¡}|jj|kshJ ‚| |jtj|| jj	d�¡sˆJ ‚|jj
d r |jj
d r¤J ‚d}|   |tjjd ¡}|jj|ksÊJ ‚| |jtj|| jj	d�¡sêJ ‚|jj
d �s|jj
d �s
J ‚d S )NrÇ   rz   rÈ   r   r   )rŒ   r†   r!   r   r’   r�   rS   rÎ   rV   rT   r   rx   )r$   r’   r¢   r   r   r   Útest_optional_none2  s       z#TestSharedMemory.test_optional_nonec                 C   s@   | j }t|ƒf}|  |tj|¡}|jj|ks0J ‚| ¡ r<J ‚d S r5   )r    r6   rŒ   r†   r!   r   r’   r�   r¸   r   r   r   Útest_optional_from_2seqD  s
    
z(TestSharedMemory.test_optional_from_2seqc                 C   sx   | j }t|ƒt|d ƒf}|  |tj|¡}|jj|ks:J ‚| ¡ rFJ ‚|  |tjj|¡}|jj|kshJ ‚| ¡ rtJ ‚d S r»   )	r´   r6   rŒ   r†   r!   r   r’   r�   rx   r¸   r   r   r   Útest_optional_from_23seqK  s    z)TestSharedMemory.test_optional_from_23seqc                 C   sä   t j| j| jjd�}|jd s(|jd s,J ‚|j}|  |tj|¡}|d d |j	d d ksnJ t
||j	fƒƒ‚d|j	d d< |d d |j	d d   kr°t jd| jjd�ks¶n J ‚|j	|u sÄJ ‚|jd sÒJ ‚|jd ràJ ‚d S ©Nrz   r   r   r   r€   é6   )rS   rŒ   r´   rV   rT   r   r’   r†   Úinplacer   r‹   r¸   r   r   r   Útest_inplaceV  s    ,:zTestSharedMemory.test_inplacec                 C   s@  | j  ¡ D �].}|| j u rq
tj| j|jd�}|jj |j ks@J ‚|jj | j j usTJ ‚|jd sh|jd slJ ‚|j}|  |tj	|¡}|d d |j
d d ks®J t||j
fƒƒ‚d|j
d d< |d d |j
d d   krðtjd| j jd�ksön J ‚|j
|u �sJ ‚|jd �sJ ‚|jd �r&J ‚|jj | j j u s
J ‚q
d S rÓ   )rV   rm   rS   rŒ   r´   rT   r   r’   r†   rÕ   r   r‹   )r$   r¦   r^   r’   r¢   r   r   r   Útest_inplace_from_casttypeb  s$    
,$ÿz+TestSharedMemory.test_inplace_from_casttypeN)!r8   r9   r:   r    r´   r   Zfixturern   rŸ   r£   r§   ÚmarkZparametrizer­   r³   r¶   r¹   rº   r¼   r½   r¿   rÀ   rÁ   rÂ   rÅ   rÆ   rÍ   rÏ   rÐ   rÑ   rÒ   rÖ   r×   r   r   r   r   r˜   T  s:   
		

r˜   )r
   Úsysr„   Úplatformr   ÚnumpyrS   Znumpy.core.multiarrayr   Ú r   r	   r   r   r   r    r†   rn   rl   ZintprT   ÚitemsizeZclongdoublerq   ÚsystemÚ	processorÚextendrQ   rw   r•   r˜   r   r   r   r   Ú<module>   sV   !


$ÿþ>f
