
    d^(                     b    d Z ddlZddlZddlmZ ddlmZ ddlm	Z	m
Z
 dZ G d d	e          ZdS )
z!Here is defined the CArray class.    N   )Atom)Array)correct_byteorderSizeTypez1.1c                   B     e Zd ZdZdZ	 	 	 	 d
 fd	Zd Zd Zd	 Z xZ	S )CArraya  This class represents homogeneous datasets in an HDF5 file.

    The difference between a CArray and a normal Array (see
    :ref:`ArrayClassDescr`), from which it inherits, is that a CArray
    has a chunked layout and, as a consequence, it supports compression.
    You can use datasets of this class to easily save or load arrays to
    or from disk, with compression support included.

    CArray includes all the instance variables and methods of Array.
    Only those with different behavior are mentioned here.

    Parameters
    ----------
    parentnode
        The parent :class:`Group` object.

        .. versionchanged:: 3.0
           Renamed from *parentNode* to *parentnode*.

    name : str
        The name of this node in its parent group.
    atom
       An `Atom` instance representing the *type* and *shape* of
       the atomic objects to be saved.

    shape
       The shape of the new array.

    title
       A description for this node (it sets the ``TITLE`` HDF5
       attribute on disk).

    filters
       An instance of the `Filters` class that provides
       information about the desired I/O filters to be applied
       during the life of this object.

    chunkshape
       The shape of the data chunk to be read or written in a
       single HDF5 I/O operation.  Filters are applied to those
       chunks of data.  The dimensionality of `chunkshape` must
       be the same as that of `shape`.  If ``None``, a sensible
       value is calculated (which is recommended).

    byteorder
        The byteorder of the data *on disk*, specified as 'little'
        or 'big'.  If this is not specified, the byteorder is that
        of the platform.

    track_times
        Whether time data associated with the leaf are recorded (object
        access time, raw data modification time, metadata change time, object
        birth time); default True.  Semantics of these times depend on their
        implementation in the HDF5 library: refer to documentation of the
        H5O_info_t data structure.  As of HDF5 1.8.15, only ctime (metadata
        change time) is implemented.

        .. versionadded:: 3.4.3

    Examples
    --------

    See below a small example of the use of the `CArray` class.
    The code is available in ``examples/carray1.py``::

        import numpy as np
        import tables as tb

        fileName = 'carray1.h5'
        shape = (200, 300)
        atom = tb.UInt8Atom()
        filters = tb.Filters(complevel=5, complib='zlib')

        h5f = tb.open_file(fileName, 'w')
        ca = h5f.create_carray(h5f.root, 'carray', atom, shape,
                               filters=filters)

        # Fill a hyperslab in ``ca``.
        ca[10:60, 20:70] = np.ones((50, 50))
        h5f.close()

        # Re-open a read another hyperslab
        h5f = tb.open_file(fileName)
        print(h5f)
        print(h5f.root.carray[8:12, 18:22])
        h5f.close()

    The output for the previous script is something like::

        carray1.h5 (File) ''
        Last modif.: 'Thu Apr 12 10:15:38 2007'
        Object Tree:
        / (RootGroup) ''
        /carray (CArray(200, 300), shuffle, zlib(5)) ''

        [[0 0 0 0]
         [0 0 0 0]
         [0 0 1 1]
         [0 0 1 1]]

    CARRAYN Tc           	      0   || _         	 d | _        	 d| _        	 d | _        	 |d ux| _        }	 || _        	 d| _        	 || _        	 d | _        	 d | _	        	 d | _
        	 d | _        	 d | _        	 d | _        	 d | _        	 d| _        	 d | _        	 |rWt#          |t$                    st'          dt)          |          z            |t'          d          	 t+          |          }n-# t,          $ r  t-          dt)          |          z            w xY wt+          d |D                       | _        |	 t+          |          }n-# t,          $ r  t-          dt)          |          z            w xY wt/          |          t/          |          k    rt'          d	| d
| d          t1          |          dk     rt'          d          t+          d |D                       | _        t3          t4          |                               ||||||	|
           d S )NTFzHatom parameter should be an instance of tables.Atom and you passed a %s.z"you must specify a non-empty shapez8`shape` parameter must be a sequence and you passed a %sc              3   4   K   | ]}t          |          V  d S Nr   .0ss     -lib/python3.11/site-packages/tables/carray.py	<genexpr>z"CArray.__init__.<locals>.<genexpr>   s(      ::qx{{::::::    z=`chunkshape` parameter must be a sequence and you passed a %szthe shape (z) and chunkshape (z) ranks must be equal.r   z1chunkshape parameter cannot have zero-dimensions.c              3   4   K   | ]}t          |          V  d S r   r   r   s     r   r   z"CArray.__init__.<locals>.<genexpr>   s(      *K*K18A;;*K*K*K*K*K*Kr   )atomshapeextdim
_v_version_v_new_v_new_title
_v_convert_v_chunkshape_start_stop_step
_nrowsread_startb_stopb_row_initlistarr
isinstancer   
ValueErrortypetuple	TypeErrorlenminsuperr   __init__)self
parentnodenamer   r   titlefilters
chunkshape	byteorder_logtrack_timesnew	__class__s               r   r1   zCArray.__init__{   s    		 
,5 / ,,c?!&D'H 5
5
2G./	2
M* 	LdD)) -  "D!%d", - - - } !EFFFEe E E E !68<U!D E E EE ::E:::::DJ%B!&z!2!2JJ  B B B#.04Z0@0@AB B BB u::Z00$ &L5 &L &L)3&L &L &L M M M__q(($ &8 9 9 9%**K*K
*K*K*K%K%K" 	eT##Jc7$-t[	B 	B 	B 	B 	Bs   C' '*D5E *E/c                     t          | j                  dk     rt          d          |                     | j                  S )z+Create a new array in file (specific part).r   z,shape parameter cannot have zero-dimensions.)r/   r   r*   _g_create_commonnrows)r2   s    r   	_g_createzCArray._g_create   sG     tz??Q>@ @ @ $$TZ000r   c                    t           | _        | j        +|                     || j        | j        j                  | _        |                                 | _        | j	        )t          | j        j        t          j	                  | _	        	 |                     | j                  | _        n%# t           $ r |                     d            w xY w| j        S )z)Create a new array in file (common part).Nr   )flush)	obversionr   r   _calc_chunkshaperowsizer   size_calc_nrowsinbuf
nrowsinbufr8   r   r+   sys_create_carrayr   _v_objectid	Exceptionclose)r2   expectedrowss     r   r>   zCArray._g_create_common   s     $%!%!6!6dlDIN"< "<D //11>!.ty~s}MMDN	  $2243DEED 	 	 	JJQJ	
 s   	B) )"Cc
           
         |                      |||          \  }}}| j        }t          | j                  }t	          t          |||                    ||<   | j        }d | j        D             }d| _        t          ||| j	        |||||	          }t          ||||z            D ]n}|||z  z   }||k    r|}t          |||          ||<   ||z
  |z  }||z   }|||         k    r||         }|                     t          |                    |||<   od| _        t          j        | j        t                    | j	        j        z  }||fS )z2Private part of Leaf.copy() for each kind of leaf.c                 0    g | ]}t          d |d          S )r   r   )slice)r   dims     r   
<listcomp>z-CArray._g_copy_with_stats.<locals>.<listcomp>   s$    999s%3""999r   F)r   r   r5   r6   r7   r9   T)dtype)_process_range_readmaindimlistr   r.   rangerH   r   r	   r   rQ   __getitem__r,   npprodr   rF   )r2   groupr4   startstopstepr5   r6   r7   r9   kwargsrV   r   rH   slicesobjectstart2stop2start3stop3nbytess                        r   _g_copy_with_statszCArray._g_copy_with_stats   s    #66udDIId,TZ  U5$5566g_
99dj999  t$)5#W!# # # E4
):;; 	C 	CFTJ..Et||#FE488F7Oun-FZ'EuW~%%g $(#3#3E&MM#B#BF6%<  8444ty~Er   )NNr   NNNTT)
__name__
__module____qualname____doc__
_c_classidr1   r@   r>   rh   __classcell__)r<   s   @r   r	   r	      s        d dN J #'#',0(,	NB NB NB NB NB NB`1 1 1     6'  '  '  '  '  '  ' r   r	   )rl   rI   numpyrZ   r   r   arrayr   utilsr   r   rC   r	    r   r   <module>rs      s    ' ' 



                 . . . . . . . .
 	E  E  E  E  E U E  E  E  E  E r   