~ubuntu-branches/ubuntu/precise/h5py/precise

« back to all changes in this revision

Viewing changes to h5py/h5a.pyx

  • Committer: Bazaar Package Importer
  • Author(s): Soeren Sonnenburg
  • Date: 2010-03-23 15:38:34 UTC
  • mfrom: (3.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20100323153834-ysfm9nsr8gdnkid3
Tags: 1.3.0-1
* New upstream version.
  - Remove quilt patches.
  - Bump standards version to 3.8.4 (no changes required).
  - Switch to dpkg-source 3.0 (quilt) format.

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
11
11
#-
12
12
 
13
 
__doc__=\
14
13
"""
15
14
    Provides access to the low-level HDF5 "H5A" attribute interface.
16
15
"""
18
17
include "config.pxi"
19
18
 
20
19
# Compile-time imports
21
 
from h5 cimport init_hdf5, SmartStruct, attr_rw, H5PY_READ, H5PY_WRITE
 
20
from h5 cimport init_hdf5, SmartStruct
22
21
from h5t cimport TypeID, typewrap, py_create
23
22
from h5s cimport SpaceID
24
23
from h5p cimport PropID, pdefault
25
24
from numpy cimport import_array, ndarray, PyArray_DATA
26
25
from utils cimport check_numpy_read, check_numpy_write, emalloc, efree
 
26
from _proxy cimport attr_rw
27
27
 
28
28
# Initialization
29
29
import_array()
30
30
init_hdf5()
31
31
 
32
 
# Runtime imports
33
 
from _sync import sync, nosync
34
 
 
35
32
# === General attribute operations ============================================
36
33
 
37
34
# --- create, create_by_name ---
38
35
 
39
36
IF H5PY_18API:
40
 
    @sync
 
37
    
41
38
    def create(ObjectID loc not None, char* name, TypeID tid not None,
42
39
        SpaceID space not None, *, char* obj_name='.', PropID lapl=None):
43
40
        """(ObjectID loc, STRING name, TypeID tid, SpaceID space, **kwds) => AttrID
55
52
                space.id, H5P_DEFAULT, H5P_DEFAULT, pdefault(lapl)))
56
53
 
57
54
ELSE:
58
 
    @sync
 
55
    
59
56
    def create(ObjectID loc not None, char* name, TypeID tid not None, 
60
57
        SpaceID space not None):
61
58
        """(ObjectID loc, STRING name, TypeID tid, SpaceID space) => AttrID
69
66
# --- open, open_by_name, open_by_idx ---
70
67
 
71
68
IF H5PY_18API:
72
 
    @sync
 
69
    
73
70
    def open(ObjectID loc not None, char* name=NULL, int index=-1, *,
74
71
        char* obj_name='.', int index_type=H5_INDEX_NAME, int order=H5_ITER_NATIVE,
75
72
        PropID lapl=None):
101
98
                H5P_DEFAULT, pdefault(lapl)))
102
99
 
103
100
ELSE:
104
 
    @sync
 
101
    
105
102
    def open(ObjectID loc not None, char* name=NULL, int index=-1):
106
103
        """(ObjectID loc, STRING name=, INT index=) => AttrID
107
104
 
120
117
# --- exists, exists_by_name ---
121
118
 
122
119
IF H5PY_18API:
123
 
    @sync
 
120
    
124
121
    def exists(ObjectID loc not None, char* name, *,
125
122
                char* obj_name=".", PropID lapl=None):
126
123
        """(ObjectID loc, STRING name, **kwds) => BOOL
142
139
            return 1
143
140
        return 0
144
141
 
145
 
    @sync
 
142
    
146
143
    def exists(ObjectID loc not None, char* name):
147
144
        """(ObjectID loc, STRING name) => BOOL
148
145
 
156
153
# --- rename, rename_by_name ---
157
154
 
158
155
IF H5PY_18API:
159
 
    @sync
 
156
    
160
157
    def rename(ObjectID loc not None, char* name, char* new_name, *,
161
158
        char* obj_name='.', PropID lapl=None):
162
159
        """(ObjectID loc, STRING name, STRING new_name, **kwds)
172
169
        H5Arename_by_name(loc.id, obj_name, name, new_name, pdefault(lapl))
173
170
 
174
171
IF H5PY_18API:
175
 
    @sync
 
172
    
176
173
    def delete(ObjectID loc not None, char* name=NULL, int index=-1, *,
177
174
        char* obj_name='.', int index_type=H5_INDEX_NAME, int order=H5_ITER_NATIVE,
178
175
        PropID lapl=None):
200
197
            raise TypeError("Exactly one of index or name must be specified.")
201
198
 
202
199
ELSE:
203
 
    @sync
 
200
    
204
201
    def delete(ObjectID loc not None, char* name):
205
202
        """(ObjectID loc, STRING name)
206
203
 
208
205
        """
209
206
        H5Adelete(loc.id, name)
210
207
 
211
 
@sync
 
208
 
212
209
def get_num_attrs(ObjectID loc not None):
213
210
    """(ObjectID loc) => INT
214
211
 
242
239
        def _hash(self):
243
240
            return hash((self.corder_valid, self.corder, self.cset, self.data_size))
244
241
 
245
 
    @sync
 
242
    
246
243
    def get_info(ObjectID loc not None, char* name=NULL, int index=-1, *,
247
244
                char* obj_name='.', PropID lapl=None,
248
245
                int index_type=H5_INDEX_NAME, int order=H5_ITER_NATIVE):
307
304
            return 1
308
305
        return 0
309
306
 
310
 
    @sync
 
307
    
311
308
    def iterate(ObjectID loc not None, object func, int index=0, *,
312
309
        int index_type=H5_INDEX_NAME, int order=H5_ITER_NATIVE, bint info=0):
313
310
        """(ObjectID loc, CALLABLE func, INT index=0, **kwds) => <Return value from func>
360
357
            return 1
361
358
        return 0
362
359
 
363
 
    @sync
 
360
    
364
361
    def iterate(ObjectID loc not None, object func, int index=0):
365
362
        """(ObjectID loc, CALLABLE func, INT index=0) => <Return value from func>
366
363
 
421
418
            tid = self.get_type()
422
419
            return tid.py_dtype()
423
420
 
424
 
    @sync
 
421
    
425
422
    def _close(self):
426
423
        """()
427
424
 
431
428
        """
432
429
        H5Aclose(self.id)
433
430
 
434
 
    @sync
 
431
    
435
432
    def read(self, ndarray arr not None):
436
433
        """(NDARRAY arr)
437
434
 
452
449
 
453
450
            mtype = py_create(arr.dtype)
454
451
 
455
 
            attr_rw(self.id, mtype.id, PyArray_DATA(arr), H5PY_READ)
 
452
            attr_rw(self.id, mtype.id, PyArray_DATA(arr), 1)
456
453
 
457
454
        finally:
458
455
            if space_id:
459
456
                H5Sclose(space_id)
460
457
 
461
 
    @sync
 
458
    
462
459
    def write(self, ndarray arr not None):
463
460
        """(NDARRAY arr)
464
461
 
478
475
            check_numpy_read(arr, space_id)
479
476
            mtype = py_create(arr.dtype)
480
477
 
481
 
            attr_rw(self.id, mtype.id, PyArray_DATA(arr), H5PY_WRITE)
 
478
            attr_rw(self.id, mtype.id, PyArray_DATA(arr), 0)
482
479
 
483
480
        finally:
484
481
            if space_id:
485
482
                H5Sclose(space_id)
486
483
 
487
 
    @sync
 
484
    
488
485
    def get_name(self):
489
486
        """() => STRING name
490
487
 
505
502
 
506
503
        return strout
507
504
 
508
 
    @sync
 
505
    
509
506
    def get_space(self):
510
507
        """() => SpaceID
511
508
 
513
510
        """
514
511
        return SpaceID(H5Aget_space(self.id))
515
512
 
516
 
    @sync
 
513
    
517
514
    def get_type(self):
518
515
        """() => TypeID
519
516
 
522
519
        return typewrap(H5Aget_type(self.id))
523
520
 
524
521
    IF H5PY_18API:
525
 
        @sync
 
522
        
526
523
        def get_storage_size(self):
527
524
            """() => INT
528
525