o
    cd                     @   sR   d dl Zd dlZd dlmZ ddlmZmZ G dd dejZG dd deZdS )	    N)h5t   )TestCaseutc                   @   s    e Zd ZdZdd Zdd ZdS )TestCompoundzG
        Feature: Compound types can be created from Python dtypes
    c                 C   s   t dtjfdg}tj|dd}|d|d}}| |tj | |tj	 | |
dd | |
dtj  dS )zL Reference types are correctly stored in compound types (issue 144)
        a)b<f4T)Zlogicalr   r   N)npdtypeh5pyZ	ref_dtyper   	py_createZget_member_typeassertEqualZSTD_REF_OBJZ
IEEE_F32LEZget_member_offsetZget_size)selfdttidt1t2 r   3lib/python3.10/site-packages/h5py/tests/test_h5t.pytest_ref   s   zTestCompound.test_refc                 C   s   d}g dg dg dd}t |}ttj|}t|d |d |d D ]\}}}|t|tr7|	d	n||t
| q&| |j| | |jj| d S )
N   )f1f2Zf3)r	   z<i4<f8)r         )namesformatsoffsetsr   r   r   utf8)r
   r   r   createZCOMPOUNDzipinsert
isinstancestrencoder   r   itemsize)r   sizeZ	type_dictZexpected_dtyper   nameoffsetr   r   r   r   test_out_of_order_offsets#   s"   
z&TestCompound.test_out_of_order_offsetsN)__name__
__module____qualname____doc__r   r+   r   r   r   r   r      s    r   c                   @   s   e Zd ZdZdd ZdS )TestTypeFloatIDzTest TypeFloatID.c              	   C   s6  |    }d}d}d}d}d}d}tjg dg dg d	g d
gtjd}tjg dg dg dg dgtjd}	tj|}
tj	|}t
j }|ddddd |d |d |  tj|
|||}|tjjtjj| ~t
j }|ddddd |d |d |  tj|
|||}|tjjtjj|	 ~t
j }|ddddd |d |d |  tj|
|||}|tjjtjj|	 ~t
j }|ddddd |d |d |  tj|
|||}|tjjtjj|	 ~tj|
|t
j|}|tjjtjj|	 ~~~
t|d}|| dd }tj|| | |jtd || dd }tj||	 | |jtd || }z| |jtd W n ty~   | |jtd Y nw || }| |jtd || }| |jtj dS )z@Custom floats are correctly promoted to standard floats on read.s   DS1s   DS2s   DS3s   DS4s   DS5)      )a  g>g];>=gq=gg=g  `ӽgZF  >)r3   gϽ >g;c  =笃>g4-  >gt  =g4  =)r3   g]  >g;'>g  (>g% (=gi  h=g  ݽ)r3   gSdݽgjg@  H>g?>g6  0>g<  >)r   )r3   g[_>gؽg  8=gT p  =g =g4'ӽ)r3   g&1  =g3  
>g/=gI/>gX>g׽)r3   gb9  P>g43?	>g   >gcE/=g[>g(e   =)r3   g[~=r4   g(e   =g׺ 0=g   >g~,=   	      r      5         
   i  rNr	   z<f2r   )Zmktempr&   r
   ZarrayZfloat32r   Zh5fr!   Zh5sZcreate_simpler   Z
IEEE_F16LEcopyZ
set_fieldsZset_sizeZ	set_ebiaslockZh5dwriteZALLZNATIVE_LDOUBLEZFileZtestingZassert_array_equalr   r   AttributeErrorZ
longdouble)r   Ztest_filenameZdatasetZdataset2Zdataset3Zdataset4Zdataset5ZdimsZwdataZwdata2ZfidZspaceZmytypeZdsetZmytype2Zmytype3Zmytype4fvaluesr   r   r   test_custom_float_promotion>   s   













z+TestTypeFloatID.test_custom_float_promotionN)r,   r-   r.   r/   rD   r   r   r   r   r0   ;   s    r0   )	Znumpyr
   r   r   commonr   r   r   r0   r   r   r   r   <module>   s   	)