How to declare a double ** from C with numpy.ndpointer for ctypes python call? -


i wonder howto use ndpointer double **.

consider matrix of vertex[100000][3] , function in c like:

double dist(double **vertex) 

to call function c, need create following matrix of pointer:

  double **b=(double **)malloc(sizeof(double)*100000);   (i=0;i<100000;i++)   {       b[i]=(double*)malloc(sizeof(double)*3);   } 

if use ctypes call dist function python, need like:

import numpy np import ctypes vertex_np=np.reshape(np.random.randn(nb_millions*3e6),(nb_millions*1e6,3)) pt=ctypes.pointer(ct.c_double) vertex_pt= (pt*len(vertex_np))(*[row.ctypes.data_as(pt) row in vertex_np]) result=lib.dist(ctypes.pointer(vertex_pt)) 

the problem loop create vertex_pt...

how can avoid loop use of ndpointer numpy.ctypeslib ? [how declare pointer of pointer numpy.ctypeslib.ndpointer?]

thanks help

-baco

edit - bad/low solution:

the way found avoid loop modify declaration of dist with:

double dist(double (*vertex)[3]) 

and can use ndpointer in python code:

lib.dist.argtypes = [np.ctypeslib.ndpointer(ndim=2,shape=(100000,3))] result=lib.dist(vertex_np) 


Comments