Get pointer of float numpy array / list.
(data)
| 262 | |
| 263 | |
| 264 | def c_float_array(data): |
| 265 | """Get pointer of float numpy array / list.""" |
| 266 | if is_1d_list(data): |
| 267 | data = np.array(data, copy=False) |
| 268 | if is_numpy_1d_array(data): |
| 269 | data = convert_from_sliced_object(data) |
| 270 | assert data.flags.c_contiguous |
| 271 | if data.dtype == np.float32: |
| 272 | ptr_data = data.ctypes.data_as(ctypes.POINTER(ctypes.c_float)) |
| 273 | type_data = C_API_DTYPE_FLOAT32 |
| 274 | elif data.dtype == np.float64: |
| 275 | ptr_data = data.ctypes.data_as(ctypes.POINTER(ctypes.c_double)) |
| 276 | type_data = C_API_DTYPE_FLOAT64 |
| 277 | else: |
| 278 | raise TypeError("Expected np.float32 or np.float64, met type({})" |
| 279 | .format(data.dtype)) |
| 280 | else: |
| 281 | raise TypeError("Unknown type({})".format(type(data).__name__)) |
| 282 | return (ptr_data, type_data, data) # return `data` to avoid the temporary copy is freed |
| 283 | |
| 284 | |
| 285 | def c_int_array(data): |
no test coverage detected