Fix performance of c_array in python core.py (#2786)

This commit is contained in:
Sam O 2017-11-29 11:12:49 -08:00 committed by Tianqi Chen
parent 9fbeeea46e
commit 602b34ab91

View File

@ -159,6 +159,8 @@ def c_str(string):
def c_array(ctype, values):
"""Convert a python string to c array."""
if isinstance(values, np.ndarray) and values.dtype.itemsize == ctypes.sizeof(ctype):
return (ctype * len(values)).from_buffer_copy(values)
return (ctype * len(values))(*values)