I think that you cannot do otherwise, but convert it by yourself :
cimport cython
from libc.stdlib cimport malloc, free
...
cdef double *anorms
cdef unsigned int i;
anorms = <double *>malloc(len(anorms2)*cython.sizeof(double))
if anorms is NULL:
raise MemoryError()
for i in xrange(len(anorms2)):
anorms[i] = anorms2[i]
return contr_hrr(len(acoefs),a.origin[0],a.origin[1],a.origin[2],anorms)
If you had been in C++, this would have been different because
The following coercions are available:
Python type => C++ type => Python type
bytes std::string bytes
iterable std::vector list
iterable std::list list
iterable std::set set
iterable (len 2) std::pair tuple (len 2)
If you could switch to C++, you would have a direct translation from List[float]
to vector<double>
:
from libcpp.vector cimport vector
def py_contr_hrr(vector[double] anorms2, ...):
...
return contr_hrr(len(acoefs),a.origin[0],a.origin[1],a.origin[2],anorms2)
And calling directly from Python side :
anorms2 = [12.0, 0.5, ...]
py_contr_hrr(anorms2, ....)
Source : http://docs.cython.org/src/userguide/wrapping_CPlusPlus.html#standard-library
But I don't know if it is an option that you can consider... It depends on your project's constraints, of course.
EDIT : I didn't know about Nikita
's way of doing (which is an elegant one, by the way), and I don't know ether which way is the best suitable concerning performances on big arrays.