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

C++ PyArray_FROM_OTF函数代码示例

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

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



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

示例1: pyndf_new

// create a new NDF (simple) structure
static PyObject*
pyndf_new(NDF *self, PyObject *args)
{
	// use ultracam defaults
	const char *ftype = "_REAL";
	int ndim;
	PyObject* lb;
	PyObject* ub;
	if(!PyArg_ParseTuple(args, "siOO:pyndf_new", &ftype, &ndim, &lb, &ub))
		return NULL;
	if(ndim < 0 || ndim > 7)
		return NULL;
	// TODO: check for ftype here
	int status = SAI__OK;
	PyArrayObject* lower = (PyArrayObject*) PyArray_FROM_OTF(lb, NPY_UINT, NPY_IN_ARRAY | NPY_FORCECAST);
	PyArrayObject* upper = (PyArrayObject*) PyArray_FROM_OTF(ub, NPY_UINT, NPY_IN_ARRAY | NPY_FORCECAST);
	if (!lower || !upper)
		return NULL;
	if(PyArray_SIZE(lower) != ndim || PyArray_SIZE(upper) != ndim)
		return NULL;
        errBegin(&status);
	ndfNew(ftype,ndim,(int*)PyArray_DATA(lower),(int*)PyArray_DATA(upper),&self->_place,&self->_ndfid,&status); // placeholder annulled by this routine
	Py_DECREF(lower);
	Py_DECREF(upper);
	if (raiseNDFException(&status))
		return NULL;
	Py_RETURN_NONE;
}
开发者ID:timj,项目名称:starlink-pyndf,代码行数:29,代码来源:ndf.c


示例2: averageDirectionIndexed

static PyObject * averageDirectionIndexed(PyObject *dummy, PyObject *args)
{
  PyObject *arg1=NULL, *arg2=NULL;
  PyObject *arr1=NULL, *arr2=NULL;
  int *ind;
  float *vec, tol;
  if (!PyArg_ParseTuple(args, "OOf", &arg1, &arg2, &tol)) return NULL;
  arr1 = PyArray_FROM_OTF(arg1, NPY_FLOAT, NPY_INOUT_ARRAY);
  if (arr1 == NULL) return NULL;
  arr2 = PyArray_FROM_OTF(arg2, NPY_INT, NPY_INOUT_ARRAY);
  if (arr2 == NULL) goto fail;

  npy_intp * dims;
  int nvec,ndim;
  dims = PyArray_DIMS(arg1);
  ndim = dims[1];
  dims = PyArray_DIMS(arg2);
  nvec = dims[0];

  vec = (float *)PyArray_DATA(arr1);
  ind = (int *)PyArray_DATA(arr2);
  average_direction_indexed(vec,ndim,ind,nvec,tol);

  /* Clean up and return */
  Py_DECREF(arr1);
  Py_DECREF(arr2);
  Py_INCREF(Py_None);
  return Py_None;
 fail:
  Py_XDECREF(arr1);
  Py_XDECREF(arr2);
  return NULL;
}
开发者ID:BackupTheBerlios,项目名称:pyformex-svn,代码行数:33,代码来源:misc_module.c


示例3: pyspectro_HelloWorld

//http://www.tutorialspoint.com/python/python_further_extensions.htm
//https://docs.python.org/2/extending/extending.html
//http://dan.iel.fm/posts/python-c-extensions/
static PyObject* pyspectro_HelloWorld(PyObject* self, PyObject* args) {
	printf("compiled on %s %s\n", __DATE__, __TIME__);
	printf("Then Ben said something");
	PyObject *doublearr_obj, *intarr_obj;
	if(PyArg_ParseTuple(args, "OO", &doublearr_obj, &intarr_obj) == 0) {
		printf("error!\n");
		return NULL;
	}
	PyObject* doublearr = PyArray_FROM_OTF(doublearr_obj, NPY_DOUBLE, NPY_OUT_ARRAY);
	PyObject* intarr = PyArray_FROM_OTF(intarr_obj, NPY_UINT8, NPY_OUT_ARRAY);
	if(!doublearr || !intarr) {
		Py_XDECREF(doublearr);
		Py_XDECREF(intarr);
		return NULL;
	}
	int dN = (int)PyArray_DIM(doublearr, 0);
	int iN = (int)PyArray_DIM(intarr, 0);
	double* c_doublearr = (double*)PyArray_DATA(doublearr);
	unsigned char* c_intarr = (unsigned char*)PyArray_DATA(intarr);
	if(c_intarr[0] == 1) {
		PyErr_SetString(PyExc_IOError, "hello");
		return NULL;
	}
	for(int i = 0; i < dN; i++)
		c_doublearr[i] = dN - i;
	for(int i = 0; i < iN; i++)
		c_intarr[i] = dN - i;
	Py_DECREF(doublearr);
	Py_DECREF(intarr);
	Py_RETURN_NONE;
}
开发者ID:ColdMatter,项目名称:PhotonBEC,代码行数:34,代码来源:pyspectro.cpp


示例4: dtw_extension

static PyObject* dtw_extension(PyObject *dummy, PyObject *args) {
    PyObject *arg1 = NULL;
    PyObject *arr1 = NULL;
    PyObject *arg2 = NULL;
    PyObject *arr2 = NULL;

    if (!PyArg_ParseTuple(args, "OO", &arg1, &arg2)) {
      return NULL;
    }

    arr1 = PyArray_FROM_OTF(arg1, NPY_DOUBLE, NPY_ARRAY_IN_ARRAY);
    if (arr1 == NULL) {
      return NULL;
    }
    arr2 = PyArray_FROM_OTF(arg2, NPY_DOUBLE, NPY_ARRAY_IN_ARRAY);
    if (arr2 == NULL) {
      return NULL;
    }

    // Number of dimensions
    int nd1 = PyArray_NDIM((PyArrayObject*)arr1);
    int arr_type1 = PyArray_TYPE((PyArrayObject*)arr1);
    npy_intp *dims1 = PyArray_DIMS((PyArrayObject*)arr1);
    int nd2 = PyArray_NDIM((PyArrayObject*)arr2);
    int arr_type2 = PyArray_TYPE((PyArrayObject*)arr2);
    npy_intp *dims2 = PyArray_DIMS((PyArrayObject*)arr2);
    int r = 0;
    npy_double **input1 = NULL;
    r = PyArray_AsCArray((PyObject**)&arr1, (void**)&input1, dims1, nd1, PyArray_DescrFromType(arr_type1));
    if (r < 0) {
      PyErr_SetString(PyExc_RuntimeError, "Could not convert input to C array");
      return NULL;
    }
    npy_double **input2 = NULL;
    r = PyArray_AsCArray((PyObject**)&arr2, (void**)&input2, dims2, nd2, PyArray_DescrFromType(arr_type2));
    if (r < 0) {
      PyErr_SetString(PyExc_RuntimeError, "Could not convert input to C array");
      return NULL;
    }

    // DTW
    matrix_t mat_a = { input1, dims1[0], dims1[1] };
    matrix_t mat_b = { input2, dims2[0], dims2[1] };
    double dist = dtw_distance(&mat_a, &mat_b);
    PyObject *value = PyFloat_FromDouble(dist);
    if (value == NULL) {
      PyErr_SetString(PyExc_RuntimeError, "Could not convert double to object");
      return NULL;
    }
    Py_DECREF(arr1);
    Py_DECREF(arr2);

    PyArray_Free(arr1, (void*)input1);
    PyArray_Free(arr2, (void*)input2);

    return value;
}
开发者ID:Meyenhofer,项目名称:pattern-recognition-2016,代码行数:57,代码来源:dtwextension.c


示例5: evaluate_baseline_uvw_ha_dec

static PyObject* evaluate_baseline_uvw_ha_dec(PyObject* self, PyObject* args)
{
    /* Read input arguments */
    PyObject *x_ecef_o=NULL, *y_ecef_o=NULL, *z_ecef_o=NULL;
    double ha, dec;
    if (!PyArg_ParseTuple(args, "O!O!O!dd", &PyArray_Type, &x_ecef_o,
        &PyArray_Type, &y_ecef_o, &PyArray_Type, &z_ecef_o, &ha, &dec))
        return NULL;

    /*  Convert Python objects to array of specified built-in data-type.*/
    int typenum = NPY_DOUBLE;
    int requirements = NPY_ARRAY_IN_ARRAY;
    PyObject *x_ecef_=NULL, *y_ecef_=NULL, *z_ecef_=NULL;
    x_ecef_ = PyArray_FROM_OTF(x_ecef_o, typenum, requirements);
    if (!x_ecef_) goto fail;
    y_ecef_ = PyArray_FROM_OTF(y_ecef_o, typenum, requirements);
    if (!y_ecef_) goto fail;
    z_ecef_ = PyArray_FROM_OTF(z_ecef_o, typenum, requirements);
    if (!z_ecef_) goto fail;

    /* Extract dimensions and pointers. */
    /* TODO(BM) Require input arrays be 1D, and check dimension consistency.
     * int nd = PyArray_NDIM(x_ecef_); */
    npy_intp* dims = PyArray_DIMS((PyArrayObject*)x_ecef_);
    double* x_ecef = (double*)PyArray_DATA((PyArrayObject*)x_ecef_);
    double* y_ecef = (double*)PyArray_DATA((PyArrayObject*)y_ecef_);
    double* z_ecef = (double*)PyArray_DATA((PyArrayObject*)z_ecef_);

    /* Create New arrays for baseline coordinates. */
    int n   = dims[0];
    npy_intp nb  = (n * (n - 1)) / 2;
    PyObject* uu_ = PyArray_SimpleNew(1, &nb, NPY_DOUBLE);
    PyObject* vv_ = PyArray_SimpleNew(1, &nb, NPY_DOUBLE);
    PyObject* ww_ = PyArray_SimpleNew(1, &nb, NPY_DOUBLE);
    double* uu  = (double*)PyArray_DATA((PyArrayObject*)uu_);
    double* vv  = (double*)PyArray_DATA((PyArrayObject*)vv_);
    double* ww  = (double*)PyArray_DATA((PyArrayObject*)ww_);

    /* Call function to evaluate baseline uvw */
    uvwsim_evaluate_baseline_uvw_ha_dec(uu, vv, ww, n, x_ecef, y_ecef, z_ecef,
                                        ha, dec);

    /* Decrement references to local array objects. */
    Py_DECREF(x_ecef_);
    Py_DECREF(y_ecef_);
    Py_DECREF(z_ecef_);

    /* Return baseline coordinates. */
    return Py_BuildValue("NNN", uu_, vv_, ww_);

fail:
    Py_XDECREF(x_ecef_);
    Py_XDECREF(y_ecef_);
    Py_XDECREF(z_ecef_);
    return NULL;
}
开发者ID:SKA-ScienceDataProcessor,项目名称:uvwsim,代码行数:56,代码来源:pyuvwsim.c


示例6: evaluate_station_uvw

static PyObject* evaluate_station_uvw(PyObject* self, PyObject* args)
{
    /* Read input arguments */
    PyObject *x_ecef_o=NULL, *y_ecef_o=NULL, *z_ecef_o=NULL;
    double ra0, dec0, mjd;
    if (!PyArg_ParseTuple(args, "O!O!O!ddd", &PyArray_Type, &x_ecef_o,
        &PyArray_Type, &y_ecef_o, &PyArray_Type, &z_ecef_o,
        &ra0, &dec0, &mjd)) return NULL;

    /*  Convert Python objects to array of specified built-in data-type.*/
    int typenum = NPY_DOUBLE;
    int requirements = NPY_ARRAY_IN_ARRAY;
    PyObject *x_ecef_=NULL, *y_ecef_=NULL, *z_ecef_=NULL;
    x_ecef_ = PyArray_FROM_OTF(x_ecef_o, typenum, requirements);
    if (!x_ecef_) goto fail;
    y_ecef_ = PyArray_FROM_OTF(y_ecef_o, typenum, requirements);
    if (!y_ecef_) goto fail;
    z_ecef_ = PyArray_FROM_OTF(z_ecef_o, typenum, requirements);
    if (!z_ecef_) goto fail;

    /* Extract dimensions and pointers. */
    /* TODO Require input arrays be 1D, and check dimension consistency.
     * int nd = PyArray_NDIM(x_ecef_); */
    npy_intp* dims = PyArray_DIMS((PyArrayObject*)x_ecef_);
    double* x_ecef = (double*)PyArray_DATA((PyArrayObject*)x_ecef_);
    double* y_ecef = (double*)PyArray_DATA((PyArrayObject*)y_ecef_);
    double* z_ecef = (double*)PyArray_DATA((PyArrayObject*)z_ecef_);

    /* Create New arrays for station coordinates. */
    npy_intp n = dims[0];
    PyObject* u_ = PyArray_SimpleNew(1, &n, NPY_DOUBLE);
    PyObject* v_ = PyArray_SimpleNew(1, &n, NPY_DOUBLE);
    PyObject* w_ = PyArray_SimpleNew(1, &n, NPY_DOUBLE);
    double* u  = (double*)PyArray_DATA((PyArrayObject*)u_);
    double* v  = (double*)PyArray_DATA((PyArrayObject*)v_);
    double* w  = (double*)PyArray_DATA((PyArrayObject*)w_);

    /* Call function to evaluate station uvw */
    uvwsim_evaluate_station_uvw(u, v, w, n, x_ecef, y_ecef, z_ecef, ra0, dec0,
        mjd);

    /* Decrement references to local array objects. */
    Py_DECREF(x_ecef_);
    Py_DECREF(y_ecef_);
    Py_DECREF(z_ecef_);

    /* Return station uvw coordinates. */
    return Py_BuildValue("NNN", u_, v_, w_);

fail:
    Py_XDECREF(x_ecef_);
    Py_XDECREF(y_ecef_);
    Py_XDECREF(z_ecef_);
    return NULL;
}
开发者ID:SKA-ScienceDataProcessor,项目名称:uvwsim,代码行数:55,代码来源:pyuvwsim.c


示例7: PyErr_SetString

PyObject *punwrap2D_Unwrap2D(PyObject *self, PyObject *args) {
  PyObject *op1, *op2;
  PyArrayObject *phsArray, *mskArray, *retArray;
  float *wr_phs, *uw_phs;
  BYTE *bmask;
  int typenum_phs, typenum_msk, ndim;
  npy_intp *dims;
  PyArray_Descr *dtype_phs;

  if(!PyArg_ParseTuple(args, "OO", &op1, &op2)) {
    PyErr_SetString(PyExc_Exception,"Unwrap2D: Couldn't parse the arguments");
    return NULL;
  }
  if(op1==NULL || op2==NULL) {
    PyErr_SetString(PyExc_Exception,"Unwrap2D: Arguments not read correctly");
    return NULL;
  }
  
  typenum_phs = PyArray_TYPE(op1);
  typenum_msk = PyArray_TYPE(op2);
  ndim = PyArray_NDIM(op1);
  dims = PyArray_DIMS(op2);
  /* This stuff is technically enforced in punwrap/__init__.py */
  if(typenum_phs != PyArray_FLOAT) {
    PyErr_SetString(PyExc_Exception, "Unwrap2D: I can only handle single-precision floating point numbers");
    return NULL;
  }
  if(typenum_msk != PyArray_UBYTE) {
    PyErr_SetString(PyExc_Exception, "Unwrap2D: The mask should be type uint8");
    return NULL;
  }
  if(ndim != 2) {
    PyErr_SetString(PyExc_Exception, "Unwrap2D: I can only unwrap 2D arrays");
    return NULL;
  }

  dtype_phs = PyArray_DescrFromType(typenum_phs);
  /* increasing references here */
  phsArray = (PyArrayObject *)PyArray_FROM_OTF(op1, typenum_phs, NPY_IN_ARRAY);
  mskArray = (PyArrayObject *)PyArray_FROM_OTF(op2, typenum_msk, NPY_IN_ARRAY);
  /* create a new, empty ndarray with floats */
  retArray = (PyArrayObject *)PyArray_SimpleNewFromDescr(ndim, dims, dtype_phs);
  wr_phs = (float *)PyArray_DATA(phsArray);
  uw_phs = (float *)PyArray_DATA(retArray);
  bmask = (BYTE *)PyArray_DATA(mskArray);

  phase_unwrap_2D(wr_phs, uw_phs, bmask, (int) dims[0], (int) dims[1]);

  Py_DECREF(phsArray);
  Py_DECREF(mskArray);
  return PyArray_Return(retArray);
    
}
开发者ID:FacundoGFlores,项目名称:golsoft,代码行数:53,代码来源:unwrap_phase.c


示例8: PyArray_FROM_OTF

static PyObject *hc_cut(PyObject *self, PyObject *args, PyObject *keywds)
{
  /* Inputs */
  PyObject *ia = NULL; PyObject *ia_a = NULL;
  PyObject *ib = NULL; PyObject *ib_a = NULL;
  PyObject *height = NULL; PyObject *height_a = NULL;
  double t;
  
  npy_intp n;
   
  long *ia_c;
  long *ib_c;
  double *height_c;

  PyObject *cmap = NULL;
  npy_intp cmap_dims[1];
  long *cmap_c;
  

  static char *kwlist[] = {"ia", "ib", "height", "t", NULL};
  if (!PyArg_ParseTupleAndKeywords(args, keywds, "OOOd", kwlist,
				   &ia, &ib, &height, &t))
    return NULL;

  ia_a = PyArray_FROM_OTF(ia, NPY_LONG, NPY_IN_ARRAY);
  if (ia_a == NULL) return NULL;
  
  ib_a = PyArray_FROM_OTF(ib, NPY_LONG, NPY_IN_ARRAY);
  if (ib_a == NULL) return NULL;
  
  height_a = PyArray_FROM_OTF(height, NPY_DOUBLE, NPY_IN_ARRAY);
  if (height_a == NULL) return NULL;
  
  n = PyArray_DIM(height_a, 0);
  
  ia_c = (long *) PyArray_DATA(ia_a);
  ib_c = (long *) PyArray_DATA(ib_a);
  height_c = (double *) PyArray_DATA(height_a);
 
  cmap_dims[0] = n;
  cmap = PyArray_SimpleNew(1, cmap_dims, NPY_LONG);
  cmap_c = (long *) PyArray_DATA(cmap);

  cutree((long) n, ia_c, ib_c, height_c, t, cmap_c);
  
  Py_DECREF(ia_a);
  Py_DECREF(ib_a);
  Py_DECREF(height_a);

  return Py_BuildValue("N", cmap);
}
开发者ID:Arafatk,项目名称:mlpy,代码行数:51,代码来源:hc.c


示例9: PyArray_FROM_OTF

static PyObject *chi2_chi2(PyObject *self, PyObject *args)
{
    double m, b;
    PyObject *x_obj, *y_obj, *yerr_obj;

    /* Parse the input tuple */
    if (!PyArg_ParseTuple(args, "ddOOO", &m, &b, &x_obj, &y_obj,
                                         &yerr_obj))
        return NULL;

    /* Interpret the input objects as numpy arrays. */
    PyObject *x_array = PyArray_FROM_OTF(x_obj, NPY_DOUBLE, NPY_IN_ARRAY);
    PyObject *y_array = PyArray_FROM_OTF(y_obj, NPY_DOUBLE, NPY_IN_ARRAY);
    PyObject *yerr_array = PyArray_FROM_OTF(yerr_obj, NPY_DOUBLE,
                                            NPY_IN_ARRAY);

    /* If that didn't work, throw an exception. */
    if (x_array == NULL || y_array == NULL || yerr_array == NULL) {
        Py_XDECREF(x_array);
        Py_XDECREF(y_array);
        Py_XDECREF(yerr_array);
        return NULL;
    }

    /* How many data points are there? */
    int N = (int)PyArray_DIM(x_array, 0);

    /* Get pointers to the data as C-types. */
    double *x    = (double*)PyArray_DATA(x_array);
    double *y    = (double*)PyArray_DATA(y_array);
    double *yerr = (double*)PyArray_DATA(yerr_array);

    /* Call the external C function to compute the chi-squared. */
    double value = chi2(m, b, x, y, yerr, N);

    /* Clean up. */
    Py_DECREF(x_array);
    Py_DECREF(y_array);
    Py_DECREF(yerr_array);

    if (value < 0.0) {
        PyErr_SetString(PyExc_RuntimeError,
                    "Chi-squared returned an impossible value.");
        return NULL;
    }

    /* Build the output tuple */
    PyObject *ret = Py_BuildValue("d", value);
    return ret;
}
开发者ID:achimnol,项目名称:pykorea-cext-examples,代码行数:50,代码来源:_chi2.c


示例10: tofile_iint32

static PyObject * tofile_iint32(PyObject *dummy, PyObject *args)
{
  PyObject *arg1=NULL, *arg2=NULL, *arg3=NULL;
  PyObject *arr1=NULL, *arr2=NULL;
  FILE *fp;
  char *fmt; /* single element format */

  if (!PyArg_ParseTuple(args, "OOOs", &arg1, &arg2, &arg3, &fmt)) return NULL;
  arr1 = PyArray_FROM_OTF(arg1, NPY_INT, NPY_IN_ARRAY);
  if (arr1 == NULL) return NULL;
  arr2 = PyArray_FROM_OTF(arg2, NPY_INT, NPY_IN_ARRAY);
  if (arr2 == NULL) goto fail;
  fp = PyFile_AsFile(arg3);
  if (!fp) goto fail;

  int *val;
  val = (int *)PyArray_DATA(arr2);
  npy_intp * dims;
  dims = PyArray_DIMS(arg2);
  int nr,nc;
  nr = dims[0];
  nc = dims[1];

  int *ind;
  ind = (int *)PyArray_DATA(arr1);
  dims = PyArray_DIMS(arg1);
  if (dims[0] != nr) goto fail;

  int i,j;
  for (i=0; i<nr; i++) {
    fprintf(fp,"%i ",*(ind++));
    for (j=0; j<nc; j++) {
      fprintf(fp,fmt,*(val++));
    }
    fprintf(fp,"\n");
  }

  /* Clean up and return */
  Py_DECREF(arr1);
  Py_DECREF(arr2);
  Py_INCREF(Py_None);
  return Py_None;

 fail:
  Py_XDECREF(arr1);
  Py_XDECREF(arr2);
  return NULL;
}
开发者ID:BackupTheBerlios,项目名称:pyformex-svn,代码行数:48,代码来源:misc_module.c


示例11: Py_convert_shape

static PyObject* Py_convert_shape(
	PyObject*	self,
	PyObject*	args)
{
	PyObject*	landmarks_obj;
	int		format;

	if (!PyArg_ParseTuple(args, "Oi:convert_shape", &landmarks_obj, &format))
		return NULL;

	PyArrayObject* landmarks_array = (PyArrayObject*)
			PyArray_FROM_OTF(landmarks_obj, NPY_FLOAT, NPY_ARRAY_IN_ARRAY);
	if (landmarks_array == NULL)
	{
		PyErr_SetString(PyExc_TypeError, landmark_error);
		return NULL;
	}

	if (PyArray_NDIM(landmarks_array) != 2)
	{
		PyErr_SetString(PyExc_TypeError, landmark_dim_error);
		return NULL;
	}

	PyObject* retArray = PyArray_Copy(landmarks_array);
	Py_DECREF(landmarks_array);
	float* landmarks = (float*)PyArray_DATA((PyArrayObject*)retArray);
	stasm_convert_shape(landmarks, format);

	return retArray;
}
开发者ID:ananya77041,项目名称:PyStasm,代码行数:31,代码来源:py_wrapper.cpp


示例12: pyspectro_readavsspectrum

static PyObject* pyspectro_readavsspectrum(PyObject* self, PyObject* args) {
	PyObject *spectrum_obj;
	unsigned int timeout;
	long hDevice;
	if(PyArg_ParseTuple(args, "Oil", &spectrum_obj, &timeout, &hDevice) == 0)
		return NULL;
	PyObject* spectrum = PyArray_FROM_OTF(spectrum_obj, NPY_DOUBLE, NPY_OUT_ARRAY);
	if(!spectrum) {
		Py_XDECREF(spectrum);
		return NULL;
	}
	//int N = (int)PyArray_DIM(spectrum, 0);
	double* c_spectrum = (double*)PyArray_DATA(spectrum);

	int err;
	unsigned int timestamp = 0;
	if((err = fReadAVSSpectrum(hDevice, c_spectrum, &timestamp, timeout)) != 0) {
		Py_DECREF(spectrum);
		char line[512];
		snprintf(line, sizeof(line), "ReadAVSSpectrum(): %d\n", err);
		PyErr_SetString(PyExc_IOError, line);
		return NULL;
	}
	Py_DECREF(spectrum);
	return Py_BuildValue("i", timestamp);
}
开发者ID:ColdMatter,项目名称:PhotonBEC,代码行数:26,代码来源:pyspectro.cpp


示例13: PyArray_FROM_OTF

static PyObject *wrap_logicle_scale(PyObject *self, PyObject *args) {
    double t, w, m, a;
    PyObject *x;

    // parse the input args tuple
    if (!PyArg_ParseTuple(args, "ddddO", &t, &w, &m, &a, &x)) {
        return NULL;
    }

    // read the numpy array
    PyObject *x_array = PyArray_FROM_OTF(x, NPY_DOUBLE, NPY_IN_ARRAY);

    // throw exception if the array doesn't exist
    if (x_array == NULL) {
        Py_XDECREF(x_array);
        return NULL;
    }

    // get length of input array
    int n = (int)PyArray_DIM(x_array, 0);

    // get pointers to the data as C-type
    double *xc    = (double*)PyArray_DATA(x_array);

    // now we can call our function!
    logicle_scale(t, w, m, a, xc, n);

    return x_array;
}
开发者ID:whitews,项目名称:FlowUtils,代码行数:29,代码来源:_logicle.c


示例14: PyArray_to_image

/*
 * Returns image data from a PyObject representing a numpy array.
 *
 * In:		array_obj	-	Numpy array with image data
 * Out:		width		-	Image width
 * Out:		height		-	Image height
 *
 * Returns:	char* pointing to the array data;
 * 			NULL if array is invalid
 */
const char* PyArray_to_image(
	PyObject*	array_obj,
	int* 		width,
	int*		height)
{
	PyArrayObject* img_array = (PyArrayObject*)
		PyArray_FROM_OTF(array_obj, NPY_UINT8, NPY_ARRAY_IN_ARRAY);

	if (img_array == NULL)
	{
		PyErr_SetString(PyExc_TypeError, imarray_error);
		return NULL;
	}

	if (PyArray_NDIM(img_array) != 2)
	{
		PyErr_SetString(PyExc_TypeError, imarray_dim_error);
		return NULL;
	}

	*height = (int)PyArray_DIM(img_array, 0);
	*width = (int)PyArray_DIM(img_array, 1);
	const char* img_data = PyArray_BYTES(img_array);

	Py_DECREF(img_array);

	return img_data;
}
开发者ID:ananya77041,项目名称:PyStasm,代码行数:38,代码来源:py_wrapper.cpp


示例15: pymappedndf_numpytondf

// this copies a block of memory from a numpy array to a memory address
static PyObject*
pymappedndf_numpytondf(NDFMapped *self, PyObject *args)
{
	PyObject *npy, *ptrobj;
	PyArrayObject *npyarray;
	npy_intp el;
	size_t bytes;

	if(!PyArg_ParseTuple(args, "O:pyndfmapped_numpytondf",&npy))
		return NULL;
	void *ptr = self->_pntr;
	el = self->nelem;
	if (el <= 0 || ptr == NULL) {
          PyErr_SetString( PyExc_ValueError,
                           "ndf.mapped object does not have mapped pointer or element count");
          return NULL;
        }

        int npytype = ndftype2numpy( self->type, &bytes );
        if (npytype == 0) return NULL;
        npyarray = (PyArrayObject*) PyArray_FROM_OTF(npy, npytype, NPY_IN_ARRAY | NPY_FORCECAST);
        if (!npyarray) return NULL;

        /* Verify the number of elements */
        if ( PyArray_Size(npyarray) != el ) {
          PyErr_Format( PyExc_ValueError,
                        "Number of elements in numpy array (%zu) differs from number of elements mapped (%zu)",
                        (size_t)PyArray_Size(npyarray), (size_t)el );
          Py_DECREF(npyarray);
          return NULL;
        }
        memcpy(ptr,PyArray_DATA(npyarray),el*bytes);
	Py_DECREF(npyarray);
	Py_RETURN_NONE;
}
开发者ID:timj,项目名称:starlink-pyndf,代码行数:36,代码来源:ndf.c


示例16: omp_dbscan_wrapper

static PyObject *
omp_dbscan_wrapper(PyObject *self, PyObject *args, PyObject *kwargs)
{
    const char *kw[] = {"samples", "min_samples", "eps", "threads", 0};
    const char *fmt = "O|ldl";
    PyObject *samples_src = 0; // this will have a borrowed reference
    PyArrayObject *samples_np = 0;
    PyArrayObject *clusters_np = 0;
    long int min_samples = 5;
    double eps = 0.5;
    long int threads = 1;

    
    if (!PyArg_ParseTupleAndKeywords(args, kwargs, fmt,
                                     const_cast<char**>(kw), // yuk!
                                     &samples_src, &min_samples,
                                     &eps, &threads)) {
        return NULL;
    }

    int type = NPY_CFLOAT; // this is due to the type used by the dbscan code
    int requirements = NPY_ARRAY_IN_ARRAY|NPY_ARRAY_FORCECAST;
    samples_np = (PyArrayObject*)PyArray_FROM_OTF(samples_src, type,
                                                  requirements);
                     
                                                  
    if (!samples_np) {
        return PyErr_NoMemory();
    }

    if (2 != PyArray_NDIM(samples_np)) {
        PyErr_SetString(PyExc_ValueError,
                        "omp_dbscan expects a 2 dimensional sample array");
        Py_XDECREF(samples_np);
        return NULL;
    }

    float *data = (float *)PyArray_DATA(samples_np);
    npy_intp outer_dim = PyArray_DIMS(samples_np)[0];
    npy_intp inner_dim = PyArray_DIMS(samples_np)[1];
    clusters_np = (PyArrayObject*)PyArray_EMPTY(1, &outer_dim, NPY_INTP, 0);
    npy_intp *data_out = (npy_intp*)PyArray_DATA(clusters_np);

    dbsa::ClusteringAlgo dbs;
    dbs.set_dbscan_params(eps, min_samples);
    Py_BEGIN_ALLOW_THREADS
        long int old_threads = omp_get_num_threads();
        omp_set_num_threads(threads);

        dbsa::set_samples_from_buffer(dbs, data, outer_dim, inner_dim);
        dbs.build_kdtree();
        run_dbscan_algo_uf(dbs);
        dbsa::pack_results(dbs, data_out);
        omp_set_num_threads(old_threads);
    Py_END_ALLOW_THREADS

    Py_XDECREF(samples_np);
    
    return (PyObject*)clusters_np;
}
开发者ID:ContinuumIO,项目名称:parallel_dbscan,代码行数:60,代码来源:parallel_multicore_dbscan_module.cpp


示例17: PyArray_FROM_OTF

static PyObject *web_calc_substellar(PyObject *self, PyObject *args)
{
    double phase;
    PyObject *c_obj;

    /* Parse the input tuple */
    if (!PyArg_ParseTuple(args, "dO", &phase,&c_obj))
        return NULL;

    PyObject *c_array = PyArray_FROM_OTF(c_obj, NPY_DOUBLE, NPY_IN_ARRAY);

    /* If that didn't work, throw an exception. */
    if (c_array == NULL) {
        Py_XDECREF(c_array);
        return NULL;
    }

    double *c    = (double*)PyArray_DATA(c_array);

    /* Call the external C function to compute the area. */
    double *output = calc_substellar(phase,c);

    PyObject *ret = Py_BuildValue("[d,d]",output[0],output[1]);

    Py_DECREF(c_array);

    return ret;
}
开发者ID:lkreidberg,项目名称:SPIDERMAN,代码行数:28,代码来源:_web.c


示例18: pyndf_xnew

// create a new NDF extension
static PyObject*
pyndf_xnew(NDF *self, PyObject *args)
{
	int ndim = 0;
	const char *xname, *type;
	PyObject *dim;
	if(!PyArg_ParseTuple(args, "ss|iO:pyndf_xnew", &xname, &type, &ndim, &dim))
		return NULL;
	int status = SAI__OK;
	HDSLoc *loc = NULL;
	// perform checks if we're not making an extension header
	if(ndim != 0) {
		// check for HDS types
		if (!checkHDStype(type))
			return NULL;
		// need dims if it's not an ext
		if(ndim < 1 || dim == NULL)
			return NULL;
		PyArrayObject *npydim = (PyArrayObject*) PyArray_FROM_OTF(dim,NPY_INT,NPY_IN_ARRAY|NPY_FORCECAST);
		if (PyArray_SIZE(npydim) != ndim)
			return NULL;
                errBegin(&status);
		ndfXnew(self->_ndfid,xname,type,ndim,(int*)PyArray_DATA(npydim),&loc,&status);
		Py_DECREF(npydim);
	} else {
		// making an ext/struct
                errBegin(&status);
		ndfXnew(self->_ndfid,xname,type,0,0,&loc,&status);
	}
        if (raiseNDFException(&status)) return NULL;
	PyObject* pobj = NpyCapsule_FromVoidPtr(loc, PyDelLoc);
	return Py_BuildValue("O",pobj);
}
开发者ID:timj,项目名称:starlink-pyndf,代码行数:34,代码来源:ndf.c


示例19: pyspectro_getlambda

//takes a numpy array of doubles of size pixelNum
static PyObject* pyspectro_getlambda(PyObject* self, PyObject* args) {
		
	PyObject *lambda_obj;
	long hDevice;
	if(PyArg_ParseTuple(args, "Ol", &lambda_obj, &hDevice) == 0){
		return NULL;
	}
	
	PyObject* lambda = PyArray_FROM_OTF(lambda_obj, NPY_DOUBLE, NPY_OUT_ARRAY);
	
	if(!lambda) {
		Py_XDECREF(lambda);
		return NULL;
	}
	
	
	double* c_lambda = (double*)PyArray_DATA(lambda);
	
	int err;
	if((err = fGetLambda(hDevice, c_lambda)) != 0) {
		Py_DECREF(lambda);
		char line[512];
		snprintf(line, sizeof(line), "GetLambda(): %d\n", err);
		PyErr_SetString(PyExc_IOError, line);
		return NULL;
	}
	
	//int N = (int)PyArray_DIM(lambda, 0);
	//for(int i = 0; i < N; i++)
	//	c_lambda[i] = 532.0;
	
	Py_DECREF(lambda);
	Py_RETURN_NONE;
	
}
开发者ID:ColdMatter,项目名称:PhotonBEC,代码行数:36,代码来源:pyspectro.cpp


示例20: pydat_new

// make a new primitive
static PyObject*
pydat_new(HDSObject *self, PyObject *args)
{
    PyObject *dimobj;
    const char *type, *name;
    int ndim;
    if(!PyArg_ParseTuple(args, "ssiO:pydat_new", &name, &type, &ndim, &dimobj))
        return NULL;
    HDSLoc* loc = HDS_retrieve_locator(self);
    if(!checkHDStype(type))
        return NULL;
    int status = SAI__OK;
    errBegin(&status);
    if (ndim > 0) {
        PyArrayObject *npydim = (PyArrayObject*) PyArray_FROM_OTF(dimobj,NPY_INT,NPY_IN_ARRAY|NPY_FORCECAST);
        hdsdim *dims = (hdsdim*)PyArray_DATA(npydim);
        datNew(loc,name,type,ndim,dims,&status);
        Py_DECREF(npydim);
    } else {
        datNew(loc,name,type,0,0,&status);
    }
    if (raiseHDSException(&status))
        return NULL;
    Py_RETURN_NONE;
}
开发者ID:trmrsh,项目名称:starlink-pyndf,代码行数:26,代码来源:hds.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ PyArray_SIZE函数代码示例发布时间:2022-05-30
下一篇:
C++ PyArray_DescrFromType函数代码示例发布时间: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