@@ -220,51 +220,81 @@ def get_string(self, b):
220
220
221
221
def get_float64_array (self , func , * args ):
222
222
ptr = self .ffi .new ('double**' )
223
- cnt = self .ffi .new ('int32_t[2 ]' )
223
+ cnt = self .ffi .new ('int32_t[4 ]' )
224
224
func (ptr , cnt , * args )
225
225
res = np .frombuffer (self .ffi .buffer (ptr [0 ], cnt [0 ] * 8 ), dtype = np .float64 ).copy ()
226
226
self .lib .DSS_Dispose_PDouble (ptr )
227
+
228
+ if cnt [3 ] != 0 :
229
+ # If the last element is filled, we have a matrix. Otherwise, the
230
+ # matrix feature is disabled or the result is indeed a vector
231
+ return res .reshape ((cnt [2 ], cnt [3 ]))
232
+
227
233
return res
228
-
234
+
235
+
229
236
def get_float64_gr_array (self ):
230
237
ptr , cnt = self .gr_float64_pointers
238
+ if cnt [3 ] != 0 :
239
+ return np .frombuffer (self .ffi .buffer (ptr [0 ], cnt [0 ] * 8 ), dtype = np .float64 ).copy ().reshape ((cnt [2 ], cnt [3 ]))
240
+
231
241
return np .frombuffer (self .ffi .buffer (ptr [0 ], cnt [0 ] * 8 ), dtype = np .float64 ).copy ()
232
242
233
243
def get_int32_array (self , func , * args ):
234
244
ptr = self .ffi .new ('int32_t**' )
235
- cnt = self .ffi .new ('int32_t[2 ]' )
245
+ cnt = self .ffi .new ('int32_t[4 ]' )
236
246
func (ptr , cnt , * args )
237
247
res = np .frombuffer (self .ffi .buffer (ptr [0 ], cnt [0 ] * 4 ), dtype = np .int32 ).copy ()
238
248
self .lib .DSS_Dispose_PInteger (ptr )
249
+
250
+ if cnt [3 ] != 0 :
251
+ # If the last element is filled, we have a matrix. Otherwise, the
252
+ # matrix feature is disabled or the result is indeed a vector
253
+ return res .reshape ((cnt [2 ], cnt [3 ]))
254
+
239
255
return res
240
256
257
+
241
258
def get_ptr_array (self , func , * args ):
242
259
ptr = self .ffi .new ('void***' )
243
- cnt = self .ffi .new ('int32_t[2 ]' )
260
+ cnt = self .ffi .new ('int32_t[4 ]' )
244
261
func (ptr , cnt , * args )
245
262
res = np .frombuffer (self .ffi .buffer (ptr [0 ], cnt [0 ] * np .dtype (np .uintp ).itemsize ), dtype = np .uintp ).copy ()
246
263
self .lib .DSS_Dispose_PPointer (ptr )
247
264
return res
248
265
249
266
def get_int32_gr_array (self ):
250
267
ptr , cnt = self .gr_int32_pointers
268
+ if cnt [3 ] != 0 :
269
+ return np .frombuffer (self .ffi .buffer (ptr [0 ], cnt [0 ] * 4 ), dtype = np .int32 ).copy ().reshape ((cnt [2 ], cnt [3 ]))
270
+
251
271
return np .frombuffer (self .ffi .buffer (ptr [0 ], cnt [0 ] * 4 ), dtype = np .int32 ).copy ()
252
272
273
+
253
274
def get_int8_array (self , func , * args ):
254
275
ptr = self .ffi .new ('int8_t**' )
255
- cnt = self .ffi .new ('int32_t[2 ]' )
276
+ cnt = self .ffi .new ('int32_t[4 ]' )
256
277
func (ptr , cnt , * args )
257
278
res = np .frombuffer (self .ffi .buffer (ptr [0 ], cnt [0 ] * 1 ), dtype = np .int8 ).copy ()
258
279
self .lib .DSS_Dispose_PByte (ptr )
280
+
281
+ if cnt [3 ] != 0 :
282
+ # If the last element is filled, we have a matrix. Otherwise, the
283
+ # matrix feature is disabled or the result is indeed a vector
284
+ return res .reshape ((cnt [2 ], cnt [3 ]))
285
+
259
286
return res
260
287
261
288
def get_int8_gr_array (self ):
262
289
ptr , cnt = self .gr_int8_pointers
290
+ if cnt [3 ] != 0 :
291
+ return np .frombuffer (self .ffi .buffer (ptr [0 ], cnt [0 ] * 1 ), dtype = np .int8 ).copy ().reshape ((cnt [2 ], cnt [3 ]))
292
+
263
293
return np .frombuffer (self .ffi .buffer (ptr [0 ], cnt [0 ] * 1 ), dtype = np .int8 ).copy ()
264
294
265
295
def get_string_array (self , func , * args ):
266
296
ptr = self .ffi .new ('char***' )
267
- cnt = self .ffi .new ('int32_t[2 ]' )
297
+ cnt = self .ffi .new ('int32_t[4 ]' )
268
298
func (ptr , cnt , * args )
269
299
if not cnt [0 ]:
270
300
res = []
@@ -283,7 +313,7 @@ def get_string_array(self, func, *args):
283
313
284
314
def get_string_array2 (self , func , * args ): # for compatibility with OpenDSSDirect.py
285
315
ptr = self .ffi .new ('char***' )
286
- cnt = self .ffi .new ('int32_t[2 ]' )
316
+ cnt = self .ffi .new ('int32_t[4 ]' )
287
317
func (ptr , cnt , * args )
288
318
289
319
if not cnt [0 ]:
@@ -308,7 +338,7 @@ def get_string_array2(self, func, *args): # for compatibility with OpenDSSDirect
308
338
309
339
def get_float64_array2 (self , func , * args ):
310
340
ptr = self .ffi .new ('double**' )
311
- cnt = self .ffi .new ('int32_t[2 ]' )
341
+ cnt = self .ffi .new ('int32_t[4 ]' )
312
342
func (ptr , cnt , * args )
313
343
if not cnt [0 ]:
314
344
res = []
@@ -324,7 +354,7 @@ def get_float64_gr_array2(self):
324
354
325
355
def get_int32_array2 (self , func , * args ):
326
356
ptr = self .ffi .new ('int32_t**' )
327
- cnt = self .ffi .new ('int32_t[2 ]' )
357
+ cnt = self .ffi .new ('int32_t[4 ]' )
328
358
func (ptr , cnt , * args )
329
359
if not cnt [0 ]:
330
360
res = None
@@ -340,7 +370,7 @@ def get_int32_gr_array2(self):
340
370
341
371
def get_int8_array2 (self , func , * args ):
342
372
ptr = self .ffi .new ('int8_t**' )
343
- cnt = self .ffi .new ('int32_t[2 ]' )
373
+ cnt = self .ffi .new ('int32_t[4 ]' )
344
374
func (ptr , cnt , * args )
345
375
if not cnt [0 ]:
346
376
res = None
0 commit comments