@@ -211,19 +211,28 @@ def param_provider_get_double_array(
211
211
n = name .decode ('utf-8' )
212
212
c = reader .current ()
213
213
214
- if n in c :
215
- o = c [n ]
216
- if isinstance (o , list ):
217
- o = np .ascontiguousarray (o )
218
- if not isinstance (o , np .ndarray ) or o .dtype != np .double or not o .flags .c_contiguous :
219
- return - 1
220
-
221
- n_elem [0 ] = ctypes .c_int (o .size )
222
- val [0 ] = o .ctypes .data_as (ctypes .POINTER (ctypes .c_double ))
223
- log_print (f"GET array [double] { n } : { o } " )
224
- return 0
214
+ if n not in c :
215
+ log_print (f"Parameter { n } not found." )
216
+ return - 1
217
+
218
+ o = c [n ]
225
219
226
- return - 1
220
+ # Ensure object is a properly aligned numpy array
221
+ if isinstance (o , list ): # Convert lists to numpy arrays
222
+ o = np .array (o , dtype = np .double )
223
+ c [n ] = o # Update the reader's storage
224
+
225
+ # Validate the array
226
+ if not isinstance (o , np .ndarray ) or o .dtype != np .double or not o .flags .c_contiguous :
227
+ log_print (f"Error: Parameter { n } is not a contiguous double array." )
228
+ return - 1
229
+
230
+ # Provide array data to the caller
231
+ n_elem [0 ] = ctypes .c_int (o .size )
232
+ val [0 ] = np .ctypeslib .as_ctypes (o )
233
+
234
+ log_print (f"GET array [double] { n } : { o } " )
235
+ return 0
227
236
228
237
229
238
def param_provider_get_int_array (
@@ -254,19 +263,28 @@ def param_provider_get_int_array(
254
263
n = name .decode ('utf-8' )
255
264
c = reader .current ()
256
265
257
- if n in c :
258
- o = c [n ]
259
- if isinstance (o , list ):
260
- o = np .ascontiguousarray (o )
261
- if not isinstance (o , np .ndarray ) or o .dtype != int or not o .flags .c_contiguous :
262
- return - 1
266
+ if n not in c :
267
+ log_print (f"Parameter { n } not found." )
268
+ return - 1
263
269
264
- n_elem [0 ] = ctypes .c_int (o .size )
265
- val [0 ] = o .ctypes .data_as (ctypes .POINTER (ctypes .c_int ))
266
- log_print (f"GET array [int] { n } : { o } " )
267
- return 0
270
+ o = c [n ]
268
271
269
- return - 1
272
+ # Ensure object is a properly aligned numpy array
273
+ if isinstance (o , list ): # Convert lists to numpy arrays
274
+ o = np .array (o , dtype = np .double )
275
+ c [n ] = o # Update the reader's storage
276
+
277
+ # Validate the array
278
+ if not isinstance (o , np .ndarray ) or o .dtype != np .int32 or not o .flags .c_contiguous :
279
+ log_print (f"Error: Parameter { n } is not a contiguous int array." )
280
+ return - 1
281
+
282
+ # Provide array data to the caller
283
+ n_elem [0 ] = ctypes .c_int (o .size )
284
+ val [0 ] = np .ctypeslib .as_ctypes (o )
285
+
286
+ log_print (f"GET array [int] { n } : { o } " )
287
+ return 0
270
288
271
289
272
290
# %% Array items
0 commit comments