o
    cd
                     @   sB   d Z ddlZddlmZ dd Zdd ZG d	d
 d
Zdd ZdS )z7
    Implements a portion of the selection operations.
    N   )h5sc                    s   t |dkr	 }n$ jdu rtdt fdd|D r!tdt fdd|D }t |d	kr@|j|d  d }||fS |}||fS )
z Returns a 2-tuple containing:

    1. Output dataset dtype
    2. Dtype containing HDF5-appropriate description of destination
    r   Nz+Field names only allowed for compound typesc                 3   s    | ]}| j vV  qd S N)names).0xdataset_dtype 4lib/python3.10/site-packages/h5py/_hl/selections2.py	<genexpr>   s    zread_dtypes.<locals>.<genexpr>z#Field does not appear in this type.c                    s   g | ]}| j | d  fqS )r   )fields)r   namer   r
   r   
<listcomp>"   s    zread_dtypes.<locals>.<listcomp>   )lenr   
ValueErroranynpZdtyper   )r	   r   Zformat_dtypeZoutput_dtyper
   r   r   read_dtypes   s   
r   c                 C   sP   | j dkr	td|dkrd}n|tfkrd}ntd|  }|  ||fS )z Returns a 2-tuple containing:

    1. Output dataset shape
    2. HDF5 dataspace containing source selection.

    Works for scalar datasets.
    r
   z1Illegal selection function for non-scalar datasetN-Illegal slicing argument for scalar dataspace)shapeRuntimeErrorEllipsisr   Z	get_space
select_all)ZdsidargsZ	out_shapeZsource_spacer
   r
   r   read_selections_scalar.   s   
	
r   c                   @   s    e Zd ZdZdd Zdd ZdS )ScalarReadSelectionz5
        Implements slicing for scalar datasets.
    c                 C   sB   |dkrd | _ n|tfkrd| _ ntdttj| _|| _d S )Nr
   r   )Zmshaper   r   r   ZcreateZSCALARmspacefspace)selfr   r   r
   r
   r   __init__P   s   

zScalarReadSelection.__init__c                 c   s    | j   | j| j fV  d S r   )r   r   r   )r    r
   r
   r   __iter__[   s   
zScalarReadSelection.__iter__N)__name__
__module____qualname____doc__r!   r"   r
   r
   r
   r   r   J   s    r   c                 C   s   | j dkr
t| |S t )zn Top-level dispatch function for reading.

    At the moment, only supports reading from scalar datasets.
    r
   )r   r   NotImplementedError)r   r   r
   r
   r   select_read_   s   

r(   )	r&   Znumpyr    r   r   r   r   r(   r
   r
   r
   r   <module>   s   	