ó
\c           @@  s  d  Z  d d l m Z d d l Z d d l Z d d l m Z m Z d d l	 Z	 d d l	 m
 Z
 m Z m Z d d l	 m Z d e f d	 „  ƒ  YZ d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   s  
    Dataset slicing test module.

    Tests all supported slicing operations, including read/write and
    broadcasting operations.  Does not test type conversion except for
    corner cases overlapping with slicing; for example, when selecting
    specific fields of a compound type.
i    (   t   absolute_importNi   (   t   utt   TestCase(   t   h5st   h5tt   h5d(   t   Filet   BaseSlicingc           B@  s   e  Z d  „  Z d „  Z RS(   c         C@  s   t  |  j ƒ  d ƒ |  _ d  S(   Nt   w(   R   t   mktempt   f(   t   self(    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyt   setUp!   s    c         C@  s   |  j  r |  j  j ƒ  n  d  S(   N(   R
   t   close(   R   (    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyt   tearDown$   s    	(   t   __name__t
   __module__R   R   (    (    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyR      s   	t   TestSingleElementc           B@  s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sM   
        Feature: Retrieving a single element works with NumPy semantics
    c         C@  s<   |  j  j d d d d ƒ} | d } |  j | t j ƒ d S(   s;    Single-element selection with [index] yields array scalar t   xi   t   dtypet   i1i    N(   i   (   R
   t   create_datasett   assertIsInstancet   npt   int8(   R   t   dsett   out(    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyt   test_single_index.   s    
c         C@  sO   |  j  j d d d d ƒ} | d } |  j | t j ƒ |  j | j d ƒ d S(	   s3    Single-element selection with [()] yields ndarray R   i   R   R   N(   i   (    (   i   (   R
   R   R   R   t   ndarrayt   assertEqualt   shape(   R   R   R   (    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyt   test_single_null4   s    
c         C@  sR   |  j  j d d d d d ƒ} | d } |  j | t j ƒ |  j | j d ƒ d S(	   s*    Slicing with [...] yields scalar ndarray R   R   R   R
   .N(    (    (   R
   R   R   R   R   R   R   (   R   R   R   (    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyt   test_scalar_index;   s    
c         C@  s?   |  j  j d d d d d ƒ} | d } |  j | t j ƒ d S(   s'    Slicing with [()] yields array scalar R   R   R   R   N(    (    (   R
   R   R   R   R   (   R   R   R   (    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyt   test_scalar_nullB   s    
c         C@  sx   t  j d d g ƒ } t  j d d | ƒ} |  j j d d d | ƒ} |  j | d	 | d	 ƒ |  j | d	 t  j ƒ d
 S(   s6    Compound scalar is numpy.void, not tuple (issue 135) t   at   i4t   bt   f8i   R   t   foot   datai    N(   R"   R#   (   R$   R%   (   i   (   i   (   R   R   t   onesR
   R   R   R   t   void(   R   t   dtt   vR   (    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyt   test_compoundH   s
    (   R   R   t   __doc__R   R   R    R!   R,   (    (    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyR   (   s   				t   TestObjectIndexc           B@  s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sH   
        Feature: numpy.object_ subtypes map to real Python objects
    c         C@  s[   |  j  j d d d t j d t j ƒ ƒ} |  j  j | d <|  j t | d ƒ t j ƒ d S(   s@    Indexing a reference dataset returns a h5py.Reference instance R   i   R   t   refi    N(   i   (   R
   R   t   h5pyt   special_dtypet	   ReferenceR/   R   t   type(   R   R   (    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyt   test_referenceV   s    *c         C@  sw   |  j  j d d
 ƒ } | j d } |  j  j d d d t j d t j ƒ ƒ} | | d <|  j t | d ƒ t j ƒ d	 S(   sL    Indexing a region reference dataset returns a h5py.RegionReference
        R   i
   .t   yi   R   R/   i    N(   i
   i
   (   i   (   R
   R   t	   regionrefR0   R1   t   RegionReferenceR   R3   (   R   t   dset1t   regreft   dset2(    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyt   test_regref\   s
    *
c         C@  s   t  j d t  j ƒ } t j d d | f g ƒ } |  j j d d d | ƒ} d |  j d	 j f | d
 <| d
 } |  j t	 | d ƒ t  j ƒ d S(   s>    Compound types of which a reference is an element work right R/   R"   t   iR$   R   i   R   i*   t   /i    N(   R"   R<   (   i   (
   R0   R1   R2   R   R   R
   R   R/   R   R3   (   R   t   reftypeR*   R   R   (    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyt   test_reference_fielde   s    
c         C@  s[   |  j  j d d d t j d t j ƒ ƒ} |  j  j | d <|  j t | d ƒ t j ƒ d S(   s:    Indexing returns a real Python object on scalar datasets R   R   R/   N(    (    (    (   R
   R   R0   R1   R2   R/   R   R3   (   R   R   (    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyt   test_scalarp   s    *c         C@  sO   |  j  j d d d t j d t ƒ ƒ} d | d <|  j t | d ƒ t ƒ d S(	   sJ    Indexing a byte string dataset returns a real python byte string
        R   i   R   t   vlens   Hello there!i    N(   i   (   R
   R   R0   R1   t   bytesR   R3   (   R   R   (    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyt   test_bytestrv   s    '
(   R   R   R-   R4   R;   R?   R@   RC   (    (    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyR.   P   s   					t   TestSimpleSlicingc           B@  s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   sQ   
        Feature: Simple NumPy-style slices (start:stop:step) are supported.
    c         C@  sL   t  |  j ƒ  d ƒ |  _ t j d ƒ |  _ |  j j d d |  j ƒ|  _ d  S(   NR   i
   R   R'   (   R   R	   R
   R   t   aranget   arrR   R   (   R   (    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyR   ƒ   s    c         C@  s   |  j  r |  j  j ƒ  n  d  S(   N(   R
   R   (   R   (    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyR   ˆ   s    	c         C@  s(   |  j  |  j d d !|  j d d !ƒ d S(   s0    Negative stop indexes work as they do in NumPy i   iþÿÿÿN(   t   assertArrayEqualR   RF   (   R   (    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyt   test_negative_stopŒ   s    c         C@  sz   |  j  j d d ƒ } t j d ƒ } | d d … d f | d d … d f <|  j t ƒ  | | d d … d f <Wd QXd S(	   s0   Assigning to a 1D slice of a 2D dataset
        t   x2i
   i   i   Ni    (   i
   i   (   i
   i   (   R
   R   R   t   zerost   assertRaisest	   TypeError(   R   R   R   (    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyt
   test_write   s
    &(   R   R   R-   R   R   RH   RM   (    (    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyRD   }   s
   			t   TestArraySlicingc           B@  s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s<   
        Feature: Array types are handled appropriately
    c         C@  s  t  j d ƒ } |  j j d d d | ƒ} |  j | j d ƒ |  j | j | ƒ | d } |  j | j t  j d ƒ ƒ |  j | j d ƒ | d } |  j | j t  j d ƒ ƒ |  j | j d ƒ | d	 d
 d	 … } |  j | j t  j d ƒ ƒ |  j | j d ƒ d S(   s;    Read arrays tack array dimensions onto end of shape tuple s   (3,)f8R   i
   R   .R%   i   i    i   i   N(   i
   (   i
   (   i
   i   (   i   (   i   i   (   R   R   R
   R   R   R   (   R   R*   R   R   (    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyt	   test_read    s    

c         C@  sN   t  j d ƒ } |  j j d d d | ƒ} |  j t ƒ  d | d <Wd QXd S(	   s@    Array fill from constant is not supported (issue 211).
        s   (3,)iR   i
   R   i*   .N(   i
   (   R   R   R
   R   RK   RL   (   R   R*   R   (    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyt   test_write_broadcast¶   s    c         C@  sv   t  j d ƒ } |  j j d d
 d | ƒ} t  j d d d g ƒ } | | d <| d } |  j t  j | | k ƒ ƒ d	 S(   sA    Write a single element to the array

        Issue 211.
        s   (3,)f8R   i
   R   i   i   g      @i   N(   i
   (   R   R   R
   R   t   arrayt
   assertTruet   all(   R   R*   R   R'   R   (    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyt   test_write_elementÀ   s    

c         C@  sÜ   t  j d ƒ } t  j d d | ƒ} t  j d d | ƒ} |  j j d d d | ƒ} | | d
 d
 d d … f <|  j | d
 d
 d d … f | ƒ | | d d d … d d	 … f <|  j | d d d … d d	 … f | ƒ d S(   s    Write slices to array type s   (3,)ii   R   i   i   R   i
   i	   i   i    i   i   i   N(   i   (   i   i   (   i
   i	   i   (   R   R   R(   R
   R   RG   (   R   R*   t   data1t   data2R   (    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyt   test_write_slicesÎ   s    #c         C@  sb   t  j d ƒ } |  j j d d d | ƒ} | d } | | d <|  j t  j | d | k ƒ ƒ d S(   sO    Read the contents of an array and write them back

        Issue 211.
        s   (3,)f8R   i
   R   .N(   i
   (   R   R   R
   R   RR   RS   (   R   R*   R   R   (    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyt   test_roundtripÞ   s
    

(   R   R   R-   RO   RP   RT   RW   RX   (    (    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyRN   š   s   		
		t   TestZeroLengthSlicingc           B@  s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s.   
        Slices resulting in empty arrays
    c      
   C@  s'  x t  d
 d d g ƒ D]	\ } } |  j j d | | d t j d d t | ƒ ƒ} |  j | j | ƒ | d } |  j	 | t j
 ƒ |  j | j | ƒ | } |  j	 | t j
 ƒ |  j | j | ƒ t | ƒ d k r | d	 d	 … d	 d … f } |  j	 | t j
 ƒ |  j | j d  d ƒ q q Wd	 S(   s]    Slice a dataset with a zero in its shape vector
            along the zero-length dimension i    i   i   i   s   x%dR   t   maxshape.N(   i    (   i    i   (   i    i   i   (   N(   i    i   (   t	   enumerateR
   R   R   t   intt   Nonet   lenR   R   R   R   (   R   R<   R   R   R   (    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyt    test_slice_zero_length_dimensionò   s    "2
c      
   C@  s§   x  t  d	 d
 d g ƒ D]‰ \ } } |  j j d | | d t j d d t | ƒ ƒ} |  j | j | ƒ | d  } |  j	 | t j
 ƒ |  j | j d | d ƒ q Wd S(   s_    Slice a dataset with a zero in its shape vector
            along a non-zero-length dimension i   i    i   i   s   x%dR   RZ   N(   i   i    (   i   i   i    (   i   i    i   (   N(   i   (   R[   R
   R   R   R\   R]   R^   R   R   R   R   (   R   R<   R   R   R   (    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyt   test_slice_other_dimension  s    "2
c      	   C@  s³   x¬ t  d
 d d g ƒ D]• \ } } |  j j d | d t j | t j ƒ d d t | ƒ ƒ} |  j | j	 | ƒ | d d !} |  j
 | t j ƒ |  j | j	 d | d ƒ q Wd	 S(   s5    Get a slice of length zero from a non-empty dataset i   i   i   i   s   x%dR'   RZ   i    N(   i   (   i   i   (   i   i   i   (   N(   i    (   R[   R
   R   R   RJ   R\   R]   R^   R   R   R   R   (   R   R<   R   R   R   (    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyt   test_slice_of_length_zero  s    ";(   R   R   R-   R_   R`   Ra   (    (    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyRY   ì   s   		
t   TestFieldNamesc           B@  sh   e  Z d  Z e j d d d g ƒ Z e j d d e ƒZ d	 „  Z d
 „  Z	 d „  Z
 d „  Z d „  Z RS(   s*   
        Field names for read & write
    R"   R
   R$   R<   t   ct   f4id   R   c         C@  sB   t  j |  ƒ |  j j d d d |  j ƒ|  _ |  j |  j d <d  S(   NR   id   R   .(   id   (   R   R   R
   R   R*   R   R'   (   R   (    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyR     s    !c         C@  sL   t  j r* |  j |  j d |  j d ƒ n  |  j |  j d |  j d ƒ d S(   s5    Test read with field selections (bytes and unicode) R"   u   aN(   t   sixt   PY2RG   R   R'   (   R   (    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyRO   $  s    	!c         C@  sc   |  j  |  j d |  j d ƒ d |  j d <|  j j ƒ  } d | d <|  j  |  j d | d ƒ d S(   s,    Unicode field names for for read and write u   aR"   i*   N(   RG   R   R'   t   copy(   R   R'   (    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyt   test_unicode_names+  s
    
c         C@  sã   |  j  j ƒ  } | d c d 9<| |  j d <|  j t j |  j d | k ƒ ƒ | d c d 9<| |  j d <|  j t j |  j d | k ƒ ƒ | d c d 9<| d c d 9<| |  j d	 <|  j t j |  j d | k ƒ ƒ d S(
   s"    Test write with field selections R"   i   .R$   i   i   Rc   N(   R"   Rc   (   R'   Rg   R   RR   R   RS   (   R   RV   (    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyRM   3  s    ##c         C@  sM   |  j  j ƒ  } d | d <d |  j d <|  j t j |  j d | k ƒ ƒ d S(   s4    Test write with non-compound source (single-field) g      ð?R$   .N(   R'   Rg   R   RR   R   RS   (   R   RV   (    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyt   test_write_noncompoundA  s    
(   R"   R
   (   R$   R<   (   Rc   Rd   (   id   (   R   R   R-   R   R   R*   R(   R'   R   RO   Rh   RM   Ri   (    (    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyRb     s   				(   R-   t
   __future__R    Re   t   numpyR   t   commonR   R   R0   R   R   R   R   R   R   R.   RD   RN   RY   Rb   (    (    (    s:   lib/python2.7/site-packages/h5py/tests/old/test_slicing.pyt   <module>   s   	(-R*