MCPcopy Create free account
hub / github.com/antmachineintelligence/mtgbmcode / c_float_array

Function c_float_array

python-package/lightgbmmt/basic.py:264–282  ·  view source on GitHub ↗

Get pointer of float numpy array / list.

(data)

Source from the content-addressed store, hash-verified

262
263
264def 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
285def c_int_array(data):

Callers 7

inner_predictMethod · 0.85
__pred_for_cscMethod · 0.85
__init_from_np2dMethod · 0.85
__init_from_list_np2dMethod · 0.85
__init_from_csrMethod · 0.85
__init_from_cscMethod · 0.85
set_fieldMethod · 0.85

Calls 6

is_1d_listFunction · 0.85
is_numpy_1d_arrayFunction · 0.85
typeEnum · 0.85
arrayMethod · 0.80
formatMethod · 0.80

Tested by

no test coverage detected