piiswrong commented on a change in pull request #8642: ctypes speed improvement URL: https://github.com/apache/incubator-mxnet/pull/8642#discussion_r150751615
########## File path: python/mxnet/base.py ########## @@ -213,7 +248,55 @@ def c_array(ctype, values): >>> x[1] 2.0 """ - return (ctype * len(values))(*values) + out = (ctype * len(values))() + out[:] = values + return out + + +def c_array_buf(ctype, buf): + """Create ctypes array from a Python buffer. + For primitive types, using the buffer created with array.array is faster + than a c_array call. + + Parameters + ---------- + ctype : ctypes data type + Data type of the array we want to convert to, such as mx_float. + + buf : buffer type + Data content. + + Returns + ------- + out : ctypes array + Created ctypes array. + + Examples + -------- + >>> x = mx.base.c_array_buf(mx.base.mx_float, array.array('i', [1, 2, 3])) + >>> print len(x) + 3 + >>> x[1] + 2.0 + """ + return (ctype * len(buf)).from_buffer(buf) + +def c_handle_array(objs): Review comment: I don't think these new functions are necessary. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services