@@ -19,7 +19,7 @@ Line # Hits Time Per Hit % Time Line Contents
19
19
==============================================================
20
20
137 def compress(source, char* cname, int clevel, int shuffle):
21
21
138 """Compress data in a numpy array.
22
- 139
22
+ 139
23
23
140 Parameters
24
24
141 ----------
25
25
142 source : array-like
@@ -30,33 +30,33 @@ Line # Hits Time Per Hit % Time Line Contents
30
30
147 Compression level.
31
31
148 shuffle : int
32
32
149 Shuffle filter.
33
- 150
33
+ 150
34
34
151 Returns
35
35
152 -------
36
36
153 dest : bytes-like
37
37
154 Compressed data.
38
- 155
38
+ 155
39
39
156 """
40
- 157
40
+ 157
41
41
158 cdef:
42
42
159 char *source_ptr
43
43
160 char *dest_ptr
44
44
161 Py_buffer source_buffer
45
45
162 size_t nbytes, cbytes, itemsize
46
46
163 200 506 2.5 0.2 array.array char_array_template = array.array('b', [])
47
47
164 array.array dest
48
- 165
48
+ 165
49
49
166 # setup source buffer
50
50
167 200 458 2.3 0.2 PyObject_GetBuffer(source, &source_buffer, PyBUF_ANY_CONTIGUOUS)
51
51
168 200 119 0.6 0.0 source_ptr = <char *> source_buffer.buf
52
- 169
52
+ 169
53
53
170 # setup destination
54
54
171 200 239 1.2 0.1 nbytes = source_buffer.len
55
55
172 200 103 0.5 0.0 itemsize = source_buffer.itemsize
56
56
173 200 2286 11.4 0.8 dest = array.clone(char_array_template, nbytes + BLOSC_MAX_OVERHEAD,
57
57
174 zero=False)
58
58
175 200 129 0.6 0.0 dest_ptr = <char *> dest.data.as_voidptr
59
- 176
59
+ 176
60
60
177 # perform compression
61
61
178 200 1734 8.7 0.6 if _get_use_threads():
62
62
179 # allow blosc to use threads internally
@@ -67,24 +67,24 @@ Line # Hits Time Per Hit % Time Line Contents
67
67
184 cbytes = blosc_compress(clevel, shuffle, itemsize, nbytes,
68
68
185 source_ptr, dest_ptr,
69
69
186 nbytes + BLOSC_MAX_OVERHEAD)
70
- 187
70
+ 187
71
71
188 else:
72
72
189 with nogil:
73
73
190 cbytes = blosc_compress_ctx(clevel, shuffle, itemsize, nbytes,
74
74
191 source_ptr, dest_ptr,
75
75
192 nbytes + BLOSC_MAX_OVERHEAD, cname,
76
76
193 0, 1)
77
- 194
77
+ 194
78
78
195 # release source buffer
79
79
196 200 616 3.1 0.2 PyBuffer_Release(&source_buffer)
80
- 197
80
+ 197
81
81
198 # check compression was successful
82
82
199 200 120 0.6 0.0 if cbytes <= 0:
83
83
200 raise RuntimeError('error during blosc compression: %d' % cbytes)
84
- 201
84
+ 201
85
85
202 # resize after compression
86
86
203 200 1896 9.5 0.6 array.resize(dest, cbytes)
87
- 204
87
+ 204
88
88
205 200 186 0.9 0.1 return dest
89
89
90
90
*******************************************************************************
@@ -100,19 +100,19 @@ Line # Hits Time Per Hit % Time Line Contents
100
100
==============================================================
101
101
75 def decompress(source, dest):
102
102
76 """Decompress data.
103
- 77
103
+ 77
104
104
78 Parameters
105
105
79 ----------
106
106
80 source : bytes-like
107
107
81 Compressed data, including blosc header.
108
108
82 dest : array-like
109
109
83 Object to decompress into.
110
- 84
110
+ 84
111
111
85 Notes
112
112
86 -----
113
113
87 Assumes that the size of the destination buffer is correct for the size of
114
114
88 the uncompressed data.
115
- 89
115
+ 89
116
116
90 """
117
117
91 cdef:
118
118
92 int ret
@@ -122,7 +122,7 @@ Line # Hits Time Per Hit % Time Line Contents
122
122
96 array.array source_array
123
123
97 Py_buffer dest_buffer
124
124
98 size_t nbytes
125
- 99
125
+ 99
126
126
100 # setup source buffer
127
127
101 200 573 2.9 0.2 if PY2 and isinstance(source, array.array):
128
128
102 # workaround fact that array.array does not support new-style buffer
@@ -134,13 +134,13 @@ Line # Hits Time Per Hit % Time Line Contents
134
134
108 200 112 0.6 0.0 release_source_buffer = True
135
135
109 200 144 0.7 0.1 PyObject_GetBuffer(source, &source_buffer, PyBUF_ANY_CONTIGUOUS)
136
136
110 200 98 0.5 0.0 source_ptr = <char *> source_buffer.buf
137
- 111
137
+ 111
138
138
112 # setup destination buffer
139
139
113 200 552 2.8 0.2 PyObject_GetBuffer(dest, &dest_buffer,
140
140
114 PyBUF_ANY_CONTIGUOUS | PyBUF_WRITEABLE)
141
141
115 200 100 0.5 0.0 dest_ptr = <char *> dest_buffer.buf
142
142
116 200 84 0.4 0.0 nbytes = dest_buffer.len
143
- 117
143
+ 117
144
144
118 # perform decompression
145
145
119 200 1856 9.3 0.8 if _get_use_threads():
146
146
120 # allow blosc to use threads internally
@@ -149,12 +149,12 @@ Line # Hits Time Per Hit % Time Line Contents
149
149
123 else:
150
150
124 with nogil:
151
151
125 ret = blosc_decompress_ctx(source_ptr, dest_ptr, nbytes, 1)
152
- 126
152
+ 126
153
153
127 # release buffers
154
154
128 200 754 3.8 0.3 if release_source_buffer:
155
155
129 200 326 1.6 0.1 PyBuffer_Release(&source_buffer)
156
156
130 200 165 0.8 0.1 PyBuffer_Release(&dest_buffer)
157
- 131
157
+ 131
158
158
132 # handle errors
159
159
133 200 128 0.6 0.1 if ret <= 0:
160
160
134 raise RuntimeError('error during blosc decompression: %d' % ret)
0 commit comments