• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ PyArray_ContiguousFromObject函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中PyArray_ContiguousFromObject函数的典型用法代码示例。如果您正苦于以下问题:C++ PyArray_ContiguousFromObject函数的具体用法?C++ PyArray_ContiguousFromObject怎么用?C++ PyArray_ContiguousFromObject使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了PyArray_ContiguousFromObject函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: _Bas_bspeval

static PyObject * _Bas_bspeval(PyObject *self, PyObject *args)
{
    int d, mc, nc, nu, dim[2];
    double **ctrlmat, **pntmat;
    PyObject *input_ctrl, *input_k, *input_u;
    PyArrayObject *ctrl, *k, *u, *pnt;
    if(!PyArg_ParseTuple(args, "iOOO", &d, &input_ctrl, &input_k, &input_u))
        return NULL;
    ctrl = (PyArrayObject *) PyArray_ContiguousFromObject(input_ctrl, PyArray_DOUBLE, 2, 2);
    if(ctrl == NULL)
        return NULL;
    k = (PyArrayObject *) PyArray_ContiguousFromObject(input_k, PyArray_DOUBLE, 1, 1);
    if(k == NULL)
        return NULL;
    u = (PyArrayObject *) PyArray_ContiguousFromObject(input_u, PyArray_DOUBLE, 1, 1);
    if(u == NULL)
        return NULL;
    mc = ctrl->dimensions[0];
    nc = ctrl->dimensions[1];
    nu = u->dimensions[0];
    dim[0] = mc;
    dim[1] = nu;
    pnt = (PyArrayObject *) PyArray_FromDims(2, dim, PyArray_DOUBLE);
    ctrlmat = vec2mat(ctrl->data, mc, nc);
    pntmat = vec2mat(pnt->data, mc, nu);
    _bspeval(d, ctrlmat, mc, nc, (double *)k->data, k->dimensions[0], (double *)u->data, nu, pntmat);
    free(pntmat);
    free(ctrlmat);
    Py_DECREF(ctrl);
    Py_DECREF(k);
    Py_DECREF(u);
    return PyArray_Return(pnt);
}
开发者ID:alexbw,项目名称:PyNURBS,代码行数:33,代码来源:_Bas.c


示例2: _Bas_bspdeval

static PyObject * _Bas_bspdeval(PyObject *self, PyObject *args)
{
	int d, mc, nc, n;
	npy_intp dim[2];
	double u, **ctrlmat, **pntmat;
	PyObject *input_ctrl, *input_k;
	PyArrayObject *ctrl, *k, *pnt;
	if(!PyArg_ParseTuple(args, "iOOdi", &d, &input_ctrl, &input_k, &u, &n))
		return NULL;
	ctrl = (PyArrayObject *) PyArray_ContiguousFromObject(input_ctrl, PyArray_DOUBLE, 2, 2);
	if(ctrl == NULL)
		return NULL;
	k = (PyArrayObject *) PyArray_ContiguousFromObject(input_k, PyArray_DOUBLE, 1, 1);
	if(k == NULL)
		return NULL;
	mc = ctrl->dimensions[0];
	nc = ctrl->dimensions[1];
	dim[0] = mc;
	dim[1] = n + 1;

	pnt = (PyArrayObject *) PyArray_SimpleNew(2, dim, PyArray_DOUBLE);
	ctrlmat = vec2mat(ctrl->data, mc, nc);
	pntmat = vec2mat(pnt->data, mc, n + 1);
	_bspdeval(d, ctrlmat, mc, nc, (double *)k->data, k->dimensions[0], u, n, pntmat);
	free(pntmat);
	free(ctrlmat);
	Py_DECREF(ctrl);
	Py_DECREF(k);
	return PyArray_Return(pnt);
}
开发者ID:adocherty,项目名称:polymode,代码行数:30,代码来源:_Bas.c


示例3: PyArray_ContiguousFromObject

// =============================================================================
int Epetra_NumPyVector::SumIntoMyValues(int blockOffset, PyObject * values,
					PyObject * indices)
{
  PyArrayObject * myValues  = NULL;
  PyArrayObject * myIndices = NULL;
  int lenValues;
  int lenIndices;
  int result;
  myValues  = (PyArrayObject *)
    PyArray_ContiguousFromObject(values,PyArray_DOUBLE,0,0);
  if (!myValues) goto fail;
  myIndices = (PyArrayObject *)
    PyArray_ContiguousFromObject(indices,PyArray_INT,0,0);
  if (!myIndices) goto fail;
  lenValues  = (int) PyArray_MultiplyList(myValues->dimensions,  myValues->nd );
  lenIndices = (int) PyArray_MultiplyList(myIndices->dimensions, myIndices->nd);
  if (lenValues != lenIndices)
  {
    PyErr_Format(PyExc_ValueError,
		 "Sequence lengths are %d and %d, but must be of same length",
		 lenValues, lenIndices);
    goto fail;
  }
  result = Epetra_Vector::SumIntoMyValues(lenValues, blockOffset,
					  (double *) myValues->data,
					  (int    *) myIndices->data);
  Py_DECREF(myValues );
  Py_DECREF(myIndices);
  return result;
 fail:
  Py_XDECREF(myValues );
  Py_XDECREF(myIndices);
  return -1;
}
开发者ID:cakeisalie,项目名称:oomphlib_003,代码行数:35,代码来源:Epetra_NumPyVector.cpp


示例4: _fasttrips_set_bump_wait

static PyObject *
_fasttrips_set_bump_wait(PyObject* self, PyObject *args)
{
    PyObject *input1, *input2;
    if (!PyArg_ParseTuple(args, "OO", &input1, &input2)) {
        return NULL;
    }
    PyArrayObject *pyo;

    // bump wait index: trip id, stop sequence, stop id
    pyo             = (PyArrayObject*)PyArray_ContiguousFromObject(input1, NPY_INT32, 2, 2);
    if (pyo == NULL) return NULL;
    int* bw_index = (int*)PyArray_DATA(pyo);
    int num_bw    = PyArray_DIMS(pyo)[0];
    assert(3 == PyArray_DIMS(pyo)[1]);

    // bump wait data: arrival time
    pyo             = (PyArrayObject*)PyArray_ContiguousFromObject(input2, NPY_DOUBLE, 1, 1);
    if (pyo == NULL) return NULL;
    double* bw_times= (double*)PyArray_DATA(pyo);
    int num_times   = PyArray_DIMS(pyo)[0];
    assert(num_times == num_bw);

    pathfinder.setBumpWait(bw_index, bw_times, num_bw);
    Py_RETURN_NONE;
}
开发者ID:bhargavasana,项目名称:fast-trips,代码行数:26,代码来源:fasttrips.cpp


示例5: _Bas_bspdegelev

static PyObject * _Bas_bspdegelev(PyObject *self, PyObject *args)
{
	int d, mc, nc, nk, t, nh;
	npy_intp dim[2];
	double **ctrlmat, **icmat;
	PyObject *input_ctrl, *input_k;
	PyArrayObject *ctrl, *k, *ic, *ik;
	if(!PyArg_ParseTuple(args, "iOOi", &d, &input_ctrl, &input_k, &t))
		return NULL;
	ctrl = (PyArrayObject *) PyArray_ContiguousFromObject(input_ctrl, PyArray_DOUBLE, 2, 2);
	if(ctrl == NULL)
		return NULL;
	k = (PyArrayObject *) PyArray_ContiguousFromObject(input_k, PyArray_DOUBLE, 1, 1);
	if(k == NULL)
		return NULL;
	mc = ctrl->dimensions[0];
	nc = ctrl->dimensions[1];
	nk = k->dimensions[0];
	dim[0] = mc;
	dim[1] = nc*(t + 1);
	ic = (PyArrayObject *) PyArray_SimpleNew(2, dim, PyArray_DOUBLE);
	
	ctrlmat = vec2mat(ctrl->data, mc, nc);
	icmat = vec2mat(ic->data, mc, nc*(t + 1));
	dim[0] = (t + 1)*nk;
	ik = (PyArrayObject *) PyArray_SimpleNew(1, dim, PyArray_DOUBLE);

	_bspdegelev(d, ctrlmat, mc, nc, (double *)k->data, nk, t, &nh, icmat, (double *)ik->data);
	free(icmat);
	free(ctrlmat);
	Py_DECREF(ctrl);
	Py_DECREF(k);
	return Py_BuildValue("(OOi)", (PyObject *)ic, (PyObject *)ik, nh);
}
开发者ID:adocherty,项目名称:polymode,代码行数:34,代码来源:_Bas.c


示例6: create_graph

static PyObject *
create_graph(PyObject *self, PyObject *args)
{
    int id, twoway;
	PyObject *input1, *input2, *input3, *input4;
	// this is node ids, node xys, edge ids, and edge weights
	if (!PyArg_ParseTuple(args, "iOOOOi", &id, &input1, &input2,
											&input3, &input4, &twoway))
											return NULL;

	PyArrayObject *pyo;
	pyo = (PyArrayObject*)PyArray_ContiguousFromObject(input1,
														NPY_INT32, 1, 1);
	if (pyo == NULL) return NULL;
    int *nodeids = (int*)PyArray_DATA(pyo);
    int numnodes = PyArray_DIMS(pyo)[0];

	pyo = (PyArrayObject*)PyArray_ContiguousFromObject(input2,
														NPY_FLOAT32, 2, 2);
	if (pyo == NULL) return NULL;
    float *nodexy = (float*)PyArray_DATA(pyo);
    assert(numnodes == PyArray_DIMS(pyo)[0]);
    assert(2 == PyArray_DIMS(pyo)[1]);

	pyo = (PyArrayObject*)PyArray_ContiguousFromObject(input3,
														NPY_INT32, 2, 2);
	if (pyo == NULL) return NULL;
    int *edges = (int*)PyArray_DATA(pyo);
    int numedges = PyArray_DIMS(pyo)[0];
    assert(2 == PyArray_DIMS(pyo)[1]);

	pyo = (PyArrayObject*)PyArray_ContiguousFromObject(input4,
														NPY_FLOAT32, 1, 2);
	if (pyo == NULL) return NULL;
    float *edgeweights = (float*)PyArray_DATA(pyo);
    int numimpedances = 1;
	if(PyArray_NDIM(pyo) == 1) assert(numedges == PyArray_DIMS(pyo)[0]);
    else {
        numimpedances = PyArray_DIMS(pyo)[0];
		assert(numedges == PyArray_DIMS(pyo)[1]);
	}

    if(id>=sas.size()) return NULL;

    std::shared_ptr<MTC::accessibility::Accessibility> sa = sas[id];

    for(int i = 0 ; i < numimpedances ; i++) {
        std::shared_ptr<MTC::accessibility::Graphalg>
            ptr(new MTC::accessibility::Graphalg);
        sa->ga.push_back(ptr);
        sa->ga[i]->Build(nodeids, nodexy, numnodes, edges,
            edgeweights+(numedges*i), numedges, twoway);
    }

    sa->numnodes = sa->ga[0]->numnodes;

    Py_RETURN_NONE;
}
开发者ID:amos5,项目名称:pandana,代码行数:58,代码来源:pyaccesswrap.cpp


示例7: delaunay

/* Process python arguments and call Delaunay implementation method. */
static PyObject*
delaunay(PyObject *self, PyObject *args)
{
    PyObject* xarg;
    PyObject* yarg;
    PyArrayObject* xarray;
    PyArrayObject* yarray;
    PyObject* ret;
    int npoints;
    const double* x;
    const double* y;

    if (!PyArg_ParseTuple(args, "OO", &xarg, &yarg)) {
        PyErr_SetString(PyExc_ValueError, "expecting x and y arrays");
        return NULL;
    }

    xarray = (PyArrayObject*)PyArray_ContiguousFromObject(xarg, NPY_DOUBLE,
                                                          1, 1);
    yarray = (PyArrayObject*)PyArray_ContiguousFromObject(yarg, NPY_DOUBLE,
                                                          1, 1);
    if (xarray == 0 || yarray == 0 ||
        PyArray_DIM(xarray,0) != PyArray_DIM(yarray, 0)) {
        Py_XDECREF(xarray);
        Py_XDECREF(yarray);
        PyErr_SetString(PyExc_ValueError,
                        "x and y must be 1D arrays of the same length");
        return NULL;
    }

    npoints = PyArray_DIM(xarray, 0);

    if (npoints < 3) {
        Py_XDECREF(xarray);
        Py_XDECREF(yarray);
        PyErr_SetString(PyExc_ValueError,
                        "x and y arrays must have a length of at least 3");
        return NULL;
    }

    x = (const double*)PyArray_DATA(xarray);
    y = (const double*)PyArray_DATA(yarray);

    if (!at_least_3_unique_points(npoints, x, y)) {
        Py_XDECREF(xarray);
        Py_XDECREF(yarray);
        PyErr_SetString(PyExc_ValueError,
                        "x and y arrays must consist of at least 3 unique points");
        return NULL;
    }

    ret = delaunay_impl(npoints, x, y, Py_VerboseFlag == 0);

    Py_XDECREF(xarray);
    Py_XDECREF(yarray);
    return ret;
}
开发者ID:RealGeeks,项目名称:matplotlib,代码行数:58,代码来源:qhull_wrap.c


示例8: PyCMOR_zfactor

static PyObject *
  PyCMOR_zfactor(PyObject *self,PyObject *args)
{
  int ierr,zvar_id;
  int itmp;
  int axis_id;
  char *name; 
  char *units; 
  int ndims;
  char type;
  int *axes_ids;
  void *values,*bounds;
  PyObject *axes_obj,*values_obj,*bounds_obj;
  PyArrayObject *axes=NULL, *values_array=NULL, *bounds_array=NULL;

  /* HUGE assumtion here is that the data is contiguous! */
  if (!PyArg_ParseTuple(args,"issiOcOO",&axis_id,&name,&units,&ndims,&axes_obj,&type,&values_obj,&bounds_obj))
    return NULL;

  if (axes_obj == Py_None) {
    axes_ids = NULL;
  }
  else {
    if (ndims>1) {
      axes =(PyArrayObject *) PyArray_ContiguousFromObject(axes_obj,PyArray_NOTYPE,1,0);
      axes_ids = (void *)axes->data;
    }
    else {
      itmp = (int) PyInt_AsLong(axes_obj);
      axes_ids = &itmp;
    }
  }


  if (values_obj == Py_None) {
    values = NULL;
  }
  else {
    values_array =(PyArrayObject *) PyArray_ContiguousFromObject(values_obj,PyArray_NOTYPE,1,0);
    values = (void *)values_array->data;
  }

  if (bounds_obj == Py_None) {
    bounds = NULL;
  }
  else {
    bounds_array =(PyArrayObject *) PyArray_ContiguousFromObject(bounds_obj,PyArray_NOTYPE,1,0);
    bounds = (void *)bounds_array->data;
  }
  
  ierr = cmor_zfactor(&zvar_id,axis_id, name, units, ndims, axes_ids, type, values, bounds);
  if (axes!=NULL) {Py_DECREF(axes);}
  if (values_array!=NULL) {Py_DECREF(values_array);}
  if (bounds_array!=NULL) {Py_DECREF(bounds_array);}
  if (ierr != 0 ) return NULL;
  return Py_BuildValue("i",zvar_id);
}
开发者ID:AZed,项目名称:uvcdat,代码行数:57,代码来源:_cmormodule.c


示例9: PyArray_ContiguousFromObject

static PyObject *colfwt(PyObject *self, PyObject *args) {
    PyObject *pyX, *pylp, *pyhp, *pylambda;
    PyArrayObject *X, *Y, *lp, *hp;

    int D, columns, N, pwr, lambda, Coarsest_level = 1;
    char *msg;


    /* process the parameters */
    if (!PyArg_ParseTuple(args, "OOOO", &pyX, &pylp, &pyhp, &pylambda))
        return NULL;

    /* Make Numeric array from general sequence types (no cost if already Numeric)*/
    X = (PyArrayObject *)
        PyArray_ContiguousFromObject(pyX, PyArray_DOUBLE, 0, 0);

    lp = (PyArrayObject *)
         PyArray_ContiguousFromObject(pylp, PyArray_NOTYPE, 0, 0);

    hp = (PyArrayObject *)
         PyArray_ContiguousFromObject(pyhp, PyArray_NOTYPE, 0, 0);


    D = lp->dimensions[0];
    if (X -> nd == 2) {
        N = X->dimensions[0];                //Rows in matrix
        columns = X->dimensions[1];
    } else if (X -> nd == 1) {
        N = X->dimensions[0];                //Elements in 1d vector
        columns = 1;
    } else {
        msg = "Input array must have dimension 1 or 2";
        PyErr_SetString(PyExc_ValueError, msg); //raise ValueError
        return NULL;
    }

    //Make Y a Numeric array same dims as X
    Y = (PyArrayObject *) PyArray_FromDims(X -> nd, X -> dimensions, X -> descr -> type_num);

    if (PyInt_Check(pylambda)) {
        lambda = PyInt_AsLong(pylambda);
        pwr = pow(2,lambda);
        Coarsest_level = max((int) (N/ (float) pwr), 1);
    }

    _colfwt ((double *) X -> data, N, columns,
             (double *) lp -> data, (double *) hp -> data,
             D, Coarsest_level, (double *) Y -> data);


    return PyArray_Return(Y);
}
开发者ID:uniomni,项目名称:CV,代码行数:52,代码来源:fwt_ext.c


示例10: PyArg_ParseTuple

static PyObject *UtilsC_maximization_beta(PyObject *self, PyObject *args){
    PyObject *q_Z,*Z_tilde,*graph;
    PyArrayObject *q_Zarray,*Z_tildearray,*grapharray;
    npy_float64 beta,gamma,Gr,gradientStep;
    int j,J,K,k,ni,maxNeighbours,nn,MaxItGrad;
    PyArg_ParseTuple(args, "dOOiiOdiid", &beta,&q_Z,&Z_tilde,&J,&K,&graph,&gamma,&maxNeighbours,&MaxItGrad,&gradientStep);
    q_Zarray = (PyArrayObject *) PyArray_ContiguousFromObject(q_Z,PyArray_FLOAT64,2,2); 
    Z_tildearray = (PyArrayObject *) PyArray_ContiguousFromObject(Z_tilde,PyArray_FLOAT64,2,2); 
    grapharray = (PyArrayObject *) PyArray_ContiguousFromObject(graph,PyArray_INT,2,2); 
    npy_float64 tmp2[K],Emax,Sum,tmp,Pzmi;
    
    Gr = gamma; 
    ni = 0;
    while( (ni<MaxItGrad) && (fabs(Gr) > eps) ){
        Gr = gamma;
        for (j=0;j<J;j++){
            Emax = 0;
            for (k=0;k<K;k++){
                tmp2[k] = 0;
                nn = 0;
                while(GetValueInt(grapharray,j,nn) != -1 && nn<maxNeighbours) {
                    tmp2[k] += beta * GetValue(Z_tildearray,k,GetValueInt(grapharray,j,nn));
                    nn++;
                }
                if (tmp2[k] > Emax) Emax = tmp2[k];
            }
            Sum = 0;
            for (k=0;k<K;k++){
                Sum += exp(tmp2[k] - Emax);
            }
            for (k=0;k<K;k++){
                tmp = 0;
                nn = 0;
                while(GetValueInt(grapharray,j,nn) != -1 && nn<maxNeighbours) {
                    tmp += GetValue(Z_tildearray,k,GetValueInt(grapharray,j,nn));
                    nn++;
                }
                Pzmi = exp(beta * tmp - Emax) / (Sum + eps);
                Gr += tmp * ( Pzmi - GetValue(q_Zarray,k,j) );
            }
        }
        beta -= gradientStep*Gr;
        ni++;
    }
    if (eps > beta) beta = 0.01;
    Py_DECREF(grapharray);
    Py_DECREF(q_Zarray);
    Py_DECREF(Z_tildearray);
    Py_INCREF(Py_None);
    return Py_BuildValue("d", beta);
}
开发者ID:ainafp,项目名称:pyhrf,代码行数:51,代码来源:moduleC_bold.c


示例11: chiSquare

double chiSquare(python::object resArr) {
  PyObject *matObj = resArr.ptr();
  if (!PyArray_Check(matObj)) {
    throw_value_error("Expecting a Numeric array object");
  }
  PyArrayObject *copy;
  copy = (PyArrayObject *)PyArray_ContiguousFromObject(
      matObj, ((PyArrayObject *)matObj)->descr->type_num, 2, 2);
  long int rows = (long int)((PyArrayObject *)matObj)->dimensions[0];
  long int cols = (long int)((PyArrayObject *)matObj)->dimensions[1];
  double res = 0.0;
  if (((PyArrayObject *)matObj)->descr->type_num == PyArray_DOUBLE) {
    double *data = (double *)copy->data;
    res = ChiSquare(data, rows, cols);
  } else if (((PyArrayObject *)matObj)->descr->type_num == PyArray_FLOAT) {
    float *data = (float *)copy->data;
    res = ChiSquare(data, rows, cols);
  } else if (((PyArrayObject *)matObj)->descr->type_num == PyArray_INT) {
    int *data = (int *)copy->data;
    res = ChiSquare(data, rows, cols);
  } else if (((PyArrayObject *)matObj)->descr->type_num == PyArray_LONG) {
    long int *data = (long int *)copy->data;
    res = ChiSquare(data, rows, cols);
  } else {
    throw_value_error(
        "Numeric array object of type int or long or float or double");
  }
  Py_DECREF(copy);
  return res;
}
开发者ID:DoliathGavid,项目名称:rdkit,代码行数:30,代码来源:rdInfoTheory.cpp


示例12: PyArray_ContiguousFromObject

static PyObject *send_array(PyObject *self, PyObject *args) {
  PyObject *input;
  PyArrayObject *x;
  int destination, tag, err;
  MPI_Datatype mpi_type;
  
  /* process the parameters */
  if (!PyArg_ParseTuple(args, "Oii", &input, &destination, &tag))
    return NULL;
    
  /* Make Numeric array from general sequence type (no cost if already Numeric)*/    
  x = (PyArrayObject *)
    PyArray_ContiguousFromObject(input, PyArray_NOTYPE, 0, 0);
    
  /* Input check and determination of MPI type */          
  mpi_type = type_map(x);
  if (!mpi_type) return NULL;
    
  /* call the MPI routine */
  err = MPI_Send(x->data, x->dimensions[0], mpi_type, destination, tag,\
           MPI_COMM_WORLD);
	   
  Py_DECREF(x); 	   
	   
  return Py_BuildValue("i", err);
}
开发者ID:TaikiKato,项目名称:pypar,代码行数:26,代码来源:mpi.c


示例13: creategrid

static PyObject * 
creategrid(PyObject *self, PyObject *args)
{
npy_intp dimensions[1];

int i,j, n;
double** input_params;
double* data;
PyObject *input;
PyArrayObject *input_arr, *result;

if (!PyArg_ParseTuple(args, "O", &input))
	return NULL;
input_arr = (PyArrayObject *)PyArray_ContiguousFromObject(input, PyArray_DOUBLE, 2, 2);

n=input_arr->dimensions[0];

input_params = (double**)malloc(sizeof(double*)*n);
for (i=0; i<n; i++)
	{
	input_params[i] = (double *)malloc(sizeof(double)*3);
	for (j=0; j<3; j++)
		input_params[i][j] = *(double *)(input_arr->data+ i*input_arr->strides[0] + j*input_arr->strides[1]);
	}

int size;
data = creategrid_c(n, input_params, &size);
dimensions[0] = size*n;
result = (PyArrayObject *)PyArray_SimpleNewFromData(1, dimensions, PyArray_DOUBLE, (char*)data);
return PyArray_Return(result);
}
开发者ID:drsm79,项目名称:guppy,代码行数:31,代码来源:functiongenerator.c


示例14: computeMean

static PyObject * computeMean(PyObject *obj, PyObject *args)
{
    PyObject *oimage;
    PyArrayObject *image;
    int status=0;
    int numGoodPixels;
    float clipmin, clipmax, mean, stddev, minValue, maxValue;

    if (!PyArg_ParseTuple(args,"Off:computeMean",&oimage, &clipmin, &clipmax))
	    return NULL;

    image = (PyArrayObject *)PyArray_ContiguousFromObject(oimage, NPY_FLOAT32, 1, 2);

    if (!image) return NULL;

    mean = 0;
    stddev = 0;
    numGoodPixels = 0;
    minValue = 0;
    maxValue = 0;

    status = computeMean_((float *)PyArray_DATA(image), PyArray_Size((PyObject*)image),
			  clipmin, clipmax,
			  &numGoodPixels, &mean, &stddev, &minValue, &maxValue);
    Py_XDECREF(image);

    return Py_BuildValue("iffff",numGoodPixels,mean,stddev,minValue,maxValue);
}
开发者ID:jhunkeler,项目名称:stsci.imagestats,代码行数:28,代码来源:computeMean.c


示例15: PyArray_ContiguousFromObject

static PyObject *send_array(PyObject *self, PyObject *args) {
  PyObject *input;
  PyArrayObject *x;
  int destination, tag, error, count;
  MPI_Datatype mpi_type;
  
  /* process the parameters */
  if (!PyArg_ParseTuple(args, "Oii", &input, &destination, &tag))
    return NULL;
    
  /* Make Numpy array from general sequence type (no cost if already Numpy). */
  x = (PyArrayObject *)
    PyArray_ContiguousFromObject(input, NPY_NOTYPE, 0, 0);
    
  /* Input check and determination of MPI type */          
  mpi_type = type_map(x, &count);
  if (!mpi_type) return NULL;
    
  /* call the MPI routine */
  error = MPI_Send(x->data, count, mpi_type, destination, tag,
		   MPI_COMM_WORLD);
  Py_DECREF(x); 	   
  
  if (error != 0) {
    rank_raise_mpi_runtime(error, "MPI_Send");
    return NULL;
  }  
   
  Py_INCREF(Py_None);
  return (Py_None);
}
开发者ID:congma,项目名称:pypar,代码行数:31,代码来源:mpiext.c


示例16: PyInt_AsLong

// Static helper functions
// =============================================================================
double * Epetra_NumPySerialDenseVector::getArray(PyObject * pyObject)
{
  // If tmp_array is NULL, build a PyArrayObject from the pyObject
  if (tmp_array == NULL)
  {
    // If pyObject is an int, build an array of that length
    if (PyInt_Check(pyObject))
    {
      npy_intp dimensions[ ] = {(npy_intp) PyInt_AsLong(pyObject)};
      tmp_array = (PyArrayObject*)
	PyArray_SimpleNew(1,dimensions,PyArray_DOUBLE);
    }
    // Else try to build a contiguous PyArrayObject from the pyObject
    else
    {
      tmp_array = (PyArrayObject *)
	PyArray_ContiguousFromObject(pyObject,PyArray_DOUBLE,0,0);
    }
  }

  // If these fail, clean up and throw a PythonException
  if (!tmp_array)
  {
    cleanup();
    throw PythonException();
  }
  return (double*)(tmp_array->data);
}
开发者ID:coyigg,项目名称:trilinos,代码行数:30,代码来源:Epetra_NumPySerialDenseVector.cpp


示例17: infoGain

double infoGain(python::object resArr) {
  PyObject *matObj = resArr.ptr();
  if (!PyArray_Check(matObj)) {
    throw_value_error("Expecting a Numeric array object");
  }
  PyArrayObject *copy;
  copy = (PyArrayObject *)PyArray_ContiguousFromObject(
      matObj, PyArray_DESCR((PyArrayObject *)matObj)->type_num, 2, 2);
  long int rows = (long int)PyArray_DIM((PyArrayObject *)matObj, 0);
  long int cols = (long int)PyArray_DIM((PyArrayObject *)matObj, 1);
  double res = 0.0;
  if (PyArray_DESCR((PyArrayObject *)matObj)->type_num == NPY_DOUBLE) {
    double *data = (double *)PyArray_DATA(copy);
    res = InfoEntropyGain(data, rows, cols);
  } else if (PyArray_DESCR((PyArrayObject *)matObj)->type_num == NPY_FLOAT) {
    float *data = (float *)PyArray_DATA(copy);
    res = InfoEntropyGain(data, rows, cols);
  } else if (PyArray_DESCR((PyArrayObject *)matObj)->type_num == NPY_INT) {
    int *data = (int *)PyArray_DATA(copy);
    res = InfoEntropyGain(data, rows, cols);
  } else if (PyArray_DESCR((PyArrayObject *)matObj)->type_num == NPY_LONG) {
    long int *data = (long int *)PyArray_DATA(copy);
    res = InfoEntropyGain(data, rows, cols);
  } else {
    throw_value_error(
        "Numeric array object of type int or long or float or double");
  }
  Py_DECREF(copy);
  return res;
}
开发者ID:Richard-Hall,项目名称:rdkit,代码行数:30,代码来源:rdInfoTheory.cpp


示例18: array_pack

int array_pack(void *vr, PyObject *obj, long nitems, PP_types tc)
   {

#ifdef HAVE_PY_NUMERIC
    PyArrayObject *arr;
    PP_numpy_map *entry;

    if (tc > 0 && tc < PP_NUM_TYPES) {
        entry = tc_to_entry[tc];
    } else {
        entry = NULL;
    }
    if (entry == NULL) {
        /* XXX set error */
        return -1;
    }

    arr = (PyArrayObject *)
        PyArray_ContiguousFromObject(obj, entry->type_num, 0, 0);
    if (arr == NULL)
        return -1;

    memcpy(vr, arr->data, nitems * arr->descr->elsize);

    Py_DECREF(arr);
#endif

    return 0;}
开发者ID:sabrown256,项目名称:pactnew,代码行数:28,代码来源:pparrays.c


示例19: _VERBOSE

Py::Object Triangulation::set_mask(const Py::Tuple &args)
{
    _VERBOSE("Triangulation::set_mask");
    args.verify_length(1);

    Py_XDECREF(_mask);
    _mask = 0;
    if (args[0] != Py::None())
    {
        _mask = (PyArrayObject*)PyArray_ContiguousFromObject(
                    args[0].ptr(), PyArray_BOOL, 1, 1);
        if (_mask == 0 || PyArray_DIM(_mask,0) != PyArray_DIM(_triangles,0)) {
            Py_XDECREF(_mask);
            throw Py::ValueError(
                "mask must be a 1D array with the same length as the triangles array");
        }
    }

    // Clear derived fields so they are recalculated when needed.
     Py_XDECREF(_edges);
    _edges = 0;
    Py_XDECREF(_neighbors);
    _neighbors = 0;
    _boundaries.clear();

    return Py::None();
}
开发者ID:ChrisBeaumont,项目名称:matplotlib,代码行数:27,代码来源:_tri.cpp


示例20: infoEntropy

double infoEntropy(python::object resArr) {
  PyObject *matObj = resArr.ptr();
  if (!PyArray_Check(matObj)) {
    throw_value_error("Expecting a Numeric array object");
  }
  PyArrayObject *copy;
  copy = (PyArrayObject *)PyArray_ContiguousFromObject(
      matObj, ((PyArrayObject *)matObj)->descr->type_num, 1, 1);
  double res = 0.0;
  // we are expecting a 1 dimensional array
  long int ncols = (long int)((PyArrayObject *)matObj)->dimensions[0];
  CHECK_INVARIANT(ncols > 0, "");
  if (((PyArrayObject *)matObj)->descr->type_num == PyArray_DOUBLE) {
    double *data = (double *)copy->data;
    res = InfoEntropy(data, ncols);
  } else if (((PyArrayObject *)matObj)->descr->type_num == PyArray_FLOAT) {
    float *data = (float *)copy->data;
    res = InfoEntropy(data, ncols);
  } else if (((PyArrayObject *)matObj)->descr->type_num == PyArray_INT) {
    int *data = (int *)copy->data;
    res = InfoEntropy(data, ncols);
  } else if (((PyArrayObject *)matObj)->descr->type_num == PyArray_LONG) {
    long int *data = (long int *)copy->data;
    res = InfoEntropy(data, ncols);
  }
  Py_DECREF(copy);
  return res;
}
开发者ID:DoliathGavid,项目名称:rdkit,代码行数:28,代码来源:rdInfoTheory.cpp



注:本文中的PyArray_ContiguousFromObject函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ PyArray_DATA函数代码示例发布时间:2022-05-30
下一篇:
C++ PyArray_Check函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap