@@ -110,11 +110,11 @@ cdef class {{name}}Vector:
110
110
cdef:
111
111
ndarray ao
112
112
cnp.npy_intp shape[1]
113
- if self.external_view_exists :
114
- raise ValueError("Vector.to_array() can only be called once")
115
-
116
- self.data.data = <{{arg}}*> realloc(self.data.data, self.data.n * sizeof({{arg}}))
117
- self.data.m = self.data.n
113
+ if self.data.m != self.data.n :
114
+ if self.external_view_exists:
115
+ raise ValueError("Vector.to_array() can only be called once")
116
+ self.data.data = <{{arg}}*> realloc(self.data.data, self.data.n * sizeof({{arg}}))
117
+ self.data.m = self.data.n
118
118
self.external_view_exists = True
119
119
shape[0] = self.data.n
120
120
ao = cnp.PyArray_SimpleNewFromData(1, shape, {{idtype}}, <void*>self.data.data)
@@ -181,24 +181,17 @@ cdef class StringVector:
181
181
ndarray ao
182
182
size_t n
183
183
object val
184
- if self.external_view_exists:
185
- raise ValueError("Vector.to_array() can only be called once")
186
-
187
184
ao = np.empty(self.data.n, dtype=np.object)
188
185
for i in range(self.data.n):
189
186
val = self.data.data[i]
190
187
ao[i] = val
191
- self.data.m = self.data.n
192
188
self.external_view_exists = True
193
189
return ao
194
190
195
191
cdef inline void append(self, char * x):
196
192
197
193
if needs_resize(self.data):
198
- if self.external_view_exists:
199
- raise ValueError("external reference but Vector.resize() needed")
200
194
self.resize()
201
-
202
195
append_data_string(self.data, x)
203
196
204
197
@@ -233,10 +226,11 @@ cdef class ObjectVector:
233
226
self.n += 1
234
227
235
228
def to_array(self):
236
- if self.external_view_exists:
237
- raise ValueError("Vector.to_array() can only be called once")
238
- self.ao.resize(self.n, refcheck=False)
239
- self.m = self.n
229
+ if self.m != self.n:
230
+ if self.external_view_exists:
231
+ raise ValueError("Vector.to_array() can only be called once")
232
+ self.ao.resize(self.n, refcheck=False)
233
+ self.m = self.n
240
234
self.external_view_exists = True
241
235
return self.ao
242
236
0 commit comments