[Numpy-discussion] How to call methods from a class with custom matrices parameters with numpy arrays ?
Thu Apr 19 03:09:57 CDT 2007
> You should give ctypes a try, I find it much better than swig most
> of the time for wrapping. You can find some doc here:
> Basically, once you get your dll/so with a function foo(double *a,
> int n), you can call it directly in numpy by passing directly a numpy
> array. The catch is that the layout of the array should be exactly the
> same than your function expects (most of the time a contiguous array),
> but there are numpy functions which enforce that. As long as you are not
> calling thousand of function with small arrays, the wrapping is pretty
> efficient in my experience.
Thanks for the fast answer ;)
I was wondering if ctypes would fit better, but in this case, I have to make
the wrapper myself, I suppose ?
Here is the basic prototype of what I have - it's a cost function I want to
optimize with optimizers I proposed on scipy recently - :
CostFunction(const MatrixType& points, ...)
const MatrixType gradient(const Matrixtype& parameters)
So I have to create a function that takes a numpy array and that returns and
instance of my cost function, this is pretty simple to do, the matrix can be
constructed from its two dimensions and a pointer, but for the gradient
method, I have trouble seeing how to do wrap it :(
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Numpy-discussion