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

C++ PyArray_TYPE函数代码示例

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

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



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

示例1: 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


示例2: 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


示例3: PyErr_SetString

static PyObject *inverse_subtraction_inplace(PyObject *self, PyObject *args)
{
  PyObject* a = NULL;
  PyObject* b = NULL;
  npy_intp sz = 0, i;
  npy_complex64* tmp_sp = NULL;
  npy_complex64* a_data_sp = NULL;
  npy_float32* b_data_sp = NULL;
  npy_complex128* tmp_dp = NULL;
  npy_complex128* a_data_dp = NULL;
  npy_float64* b_data_dp = NULL;
  double c;
  if (!PyArg_ParseTuple(args, "OOd", &a, &b, &c))
    return NULL;
  if (!(PyArray_Check(a) && PyArray_Check(b)))
    {
      PyErr_SetString(PyExc_TypeError,"arguments must be array objects");
      return NULL;
    }
  sz = PyArray_SIZE(a);

  if (sz != PyArray_SIZE(b))
    {
      PyErr_SetString(PyExc_TypeError,"argument sizes must be equal");
      return NULL;
    }
  if ((PyArray_TYPE(a) == PyArray_COMPLEX64) && (PyArray_TYPE(b) == PyArray_FLOAT32))
    {
      a_data_sp = (npy_complex64*)PyArray_DATA(a);
      b_data_sp = (npy_float32*)PyArray_DATA(b);
      for (i=0; i<sz; ++i)
	{
	  tmp_sp = a_data_sp + i;
	  tmp_sp->real = b_data_sp[i] - tmp_sp->real * c; 
	}
    }
  else if ((PyArray_TYPE(a) == PyArray_COMPLEX128) && (PyArray_TYPE(b) == PyArray_FLOAT64))
    {
      a_data_dp = (npy_complex128*)PyArray_DATA(a);
      b_data_dp = (npy_float64*)PyArray_DATA(b);
      for (i=0; i<sz; ++i)
	{
	  tmp_dp = a_data_dp + i;
	  tmp_dp->real = b_data_dp[i] - tmp_dp->real * c; 
	}
    }
  else
    {
      PyErr_SetString(PyExc_TypeError,"argument types must be complex64 and float32");
      return NULL;
    }
  return Py_BuildValue("");
}
开发者ID:pearu,项目名称:iocbio,代码行数:53,代码来源:ops_ext.c


示例4: PyArray_DIMS

// ========================================================================
// class vec<double>
//
// constructor from a python array
vec<double>::vec(array& boost_array)
{	// get array info
	PyArrayObject* py_array_p=reinterpret_cast<PyArrayObject*>(boost_array.ptr());
	npy_intp* dims_ptr = PyArray_DIMS(py_array_p);
	int length    = dims_ptr[0];

	// check array info
	PYCPPAD_ASSERT(
		PyArray_NDIM(py_array_p) == 1 ,
		"array is not a vector"
	);
	PYCPPAD_ASSERT( 
		length >= 0 , 
		"array length is <= zero"
	);

	// set private data
	length_    = static_cast<size_t>( length );
	if( PyArray_TYPE(py_array_p) == NPY_DOUBLE )
	{	pointer_ = static_cast<double*>( 
			PyArray_DATA(py_array_p)
		);
		allocated_ = false;
	}
	else if( PyArray_TYPE(py_array_p) == NPY_INT )
	{	pointer_   = CPPAD_TRACK_NEW_VEC(length, pointer_);
		int* data = 	static_cast<int*>( 
			PyArray_DATA(py_array_p)
		);
		for(size_t i = 0; i < length_; i++)
			pointer_[i] = static_cast<double>( data[i] );
		allocated_ = true;
	}
	else if( PyArray_TYPE(py_array_p) == NPY_LONG )
	{	pointer_   = CPPAD_TRACK_NEW_VEC(length, pointer_);
		long* data = 	static_cast<long*>( 
			PyArray_DATA(py_array_p)
		);
		for(size_t i = 0; i < length_; i++)
			pointer_[i] = static_cast<double>( data[i] );
		allocated_ = true;
	}
	else	PYCPPAD_ASSERT(
		0,
		"expected an array with int or float elements"
	);
	return;
}
开发者ID:b45ch1,项目名称:pycppad,代码行数:52,代码来源:vector.cpp


示例5: Py_gstrf

static PyObject *
Py_gstrf(PyObject *self, PyObject *args, PyObject *keywds)
{
    /* default value for SuperLU parameters*/
    int N, nnz;
    PyArrayObject *rowind, *colptr, *nzvals;
    SuperMatrix A;
    PyObject *result;
    PyObject *option_dict = NULL;
    int type;
    int ilu = 0;

    static char *kwlist[] = {"N","nnz","nzvals","colind","rowptr",
                             "options", "ilu",
                             NULL};

    int res = PyArg_ParseTupleAndKeywords(
        args, keywds, "iiO!O!O!|Oi", kwlist, 
        &N, &nnz,
        &PyArray_Type, &nzvals,
        &PyArray_Type, &rowind,
        &PyArray_Type, &colptr,
        &option_dict,
        &ilu);

    if (!res)
        return NULL;

    if (!_CHECK_INTEGER(colptr) || !_CHECK_INTEGER(rowind)) {
        PyErr_SetString(PyExc_TypeError,
                        "rowind and colptr must be of type cint");
        return NULL;
    }

    type = PyArray_TYPE(nzvals);
    if (!CHECK_SLU_TYPE(type)) {
        PyErr_SetString(PyExc_TypeError,
                        "nzvals is not of a type supported by SuperLU");
        return NULL;
    }

    if (NCFormat_from_spMatrix(&A, N, N, nnz, nzvals, rowind, colptr,
                               type)) {
        goto fail;
    }

    result = newSciPyLUObject(&A, option_dict, type, ilu);
    if (result == NULL) {
        goto fail;
    }

    /* arrays of input matrix will not be freed */  
    Destroy_SuperMatrix_Store(&A);
    return result;
  
fail:
    /* arrays of input matrix will not be freed */
    Destroy_SuperMatrix_Store(&A); 
    return NULL;
}
开发者ID:87,项目名称:scipy,代码行数:60,代码来源:_superlumodule.c


示例6: check_double_image

static double* 
check_double_image(PyObject* image, size_t *nrows, size_t *ncols)
{
    double* ptr=NULL;
    npy_intp *dims=NULL;
    if (!PyArray_Check(image)) {
        PyErr_SetString(PyExc_ValueError,
                        "image must be a 2D numpy array of type 64-bit float");
        return NULL;
    }
    if (2 != PyArray_NDIM((PyArrayObject*)image)) {
        PyErr_Format(PyExc_ValueError,
                     "image must be a 2D numpy array of type 64-bit float");
        return NULL;
    }
    if (NPY_DOUBLE != PyArray_TYPE((PyArrayObject*)image)) {
        PyErr_Format(PyExc_ValueError,
                     "image must be a 2D numpy array of type 64-bit float");
        return NULL;
    }

    ptr = PyArray_DATA((PyArrayObject*)image);
    dims = PyArray_DIMS((PyArrayObject*)image);

    *nrows = dims[0];
    *ncols = dims[1];
    return ptr;
}
开发者ID:esheldon,项目名称:gmix_image,代码行数:28,代码来源:gmix_em_pywrap.c


示例7: check_object

static int
check_object(PyObject *ob, int t, char *obname,
                        char *tname, char *funname)
{
    if (!PyArray_Check(ob)) {
        PyErr_Format(LapackError,
                     "Expected an array for parameter %s in lapack_lite.%s",
                     obname, funname);
        return 0;
    }
    else if (!PyArray_IS_C_CONTIGUOUS((PyArrayObject *)ob)) {
        PyErr_Format(LapackError,
                     "Parameter %s is not contiguous in lapack_lite.%s",
                     obname, funname);
        return 0;
    }
    else if (!(PyArray_TYPE((PyArrayObject *)ob) == t)) {
        PyErr_Format(LapackError,
                     "Parameter %s is not of type %s in lapack_lite.%s",
                     obname, tname, funname);
        return 0;
    }
    else if (PyArray_ISBYTESWAPPED((PyArrayObject *)ob)) {
        PyErr_Format(LapackError,
                     "Parameter %s has non-native byte order in lapack_lite.%s",
                     obname, funname);
        return 0;
    }
    else {
        return 1;
    }
}
开发者ID:7924102,项目名称:numpy,代码行数:32,代码来源:lapack_litemodule.c


示例8: gse_checksum

static PyObject* gse_checksum(PyObject *dummy, PyObject *args) {
        
    int checksum, length, i;
    PyObject *array = NULL;
    PyArrayObject *carray = NULL;
    int *data;

    if (!PyArg_ParseTuple(args, "O", &array )) {
        PyErr_SetString(GSEError, "usage checksum(array)" );
        return NULL;
    }
    if (!PyArray_Check(array)) {
        PyErr_SetString(GSEError, "Data must be given as NumPy array." );
        return NULL;
    }
    if (PyArray_TYPE(array) != NPY_INT32) {
        PyErr_SetString(GSEError, "Data must be 32-bit integers.");
        return NULL;
    }
    
    carray = PyArray_GETCONTIGUOUS((PyArrayObject*)array);
    length = PyArray_SIZE(carray);
    data = (int*)PyArray_DATA(carray);
    
    checksum = 0;
    for (i=0; i<length; i++) {
        checksum += data[i] % MODULUS;
        checksum %= MODULUS;
    }
    
    return Py_BuildValue("i", abs(checksum));
}
开发者ID:josephwinston,项目名称:pyrocko,代码行数:32,代码来源:gse2_ext.c


示例9: Image_setData

/* setData */
PyObject *
Image_setData(PyObject *obj, PyObject *args, PyObject *kwargs)
{
    ImageObject *self = (ImageObject*) obj;
    PyArrayObject * arr = NULL;

    if (self != NULL && PyArg_ParseTuple(args, "O", &arr))
    {
        try
        {
            ImageGeneric & image = Image_Value(self);
            DataType dt = npyType2Datatype(PyArray_TYPE(arr));
            int nd = PyArray_NDIM(arr);
            //Setup of image
            image.setDatatype(dt);
            ArrayDim adim;
            adim.ndim = (nd == 4 ) ? PyArray_DIM(arr, 0) : 1;
            adim.zdim = (nd > 2 ) ? PyArray_DIM(arr, nd - 3) : 1;
            adim.ydim = PyArray_DIM(arr, nd - 2);
            adim.xdim = PyArray_DIM(arr, nd - 1);

            MULTIDIM_ARRAY_GENERIC(image).resize(adim, false);
            void *mymem = image().getArrayPointer();
            void * data = PyArray_DATA(arr);
            memcpy(mymem, data, adim.nzyxdim * gettypesize(dt));
            Py_RETURN_NONE;
        }
        catch (XmippError &xe)
        {
            PyErr_SetString(PyXmippError, xe.msg.c_str());
        }
    }
    return NULL;
}//function Image_setData
开发者ID:juannavascalvente,项目名称:scipion,代码行数:35,代码来源:python_image.cpp


示例10: PyTesseract_set_image

static PyObject* PyTesseract_set_image(PyTesseract *self, PyObject *array) {
	if (!PyArray_Check(array)) {
		PyErr_SetString(PyExc_TypeError, "Image must be a NumPy array");
		return NULL;
	}

	PyArrayObject *np_array = (PyArrayObject *)array;
	npy_intp *shape = PyArray_DIMS(np_array);
	int dimension_count = PyArray_NDIM(np_array);
	int channels = 0;
	switch (dimension_count) {
		case 2:
			channels = 1;
			break;
		case 3:
			channels = (int)shape[2];
			break;
		default:
			PyErr_SetString(PyExc_TypeError, "Invalid array format");
			return NULL;
	}
	int bytes_per_channel = 0;
	switch (PyArray_TYPE(np_array)) {
		case NPY_BYTE:
		case NPY_UBYTE:
			bytes_per_channel = 1;
			break;
		case NPY_SHORT:
		case NPY_USHORT:
			bytes_per_channel = 2;
			break;
		case NPY_FLOAT:
			bytes_per_channel = 4;
			break;
		case NPY_DOUBLE:
			bytes_per_channel = 8;
			break;
		default:
			PyErr_SetString(PyExc_TypeError, "Invalid array format");
			return NULL;
	}

	int rows = (int)shape[0];
	int cols = (int)shape[1];

	Py_INCREF(array);
	self->image = array;
	int bytes_per_pixel = bytes_per_channel * channels;

	self->tess->SetImage((unsigned char *)PyArray_BYTES(np_array), cols, rows, bytes_per_pixel, bytes_per_pixel * cols);

	PyTesseract_invalidate_iterators(self);
	if (self->page) {
		delete self->page;
		self->page = NULL;
	}

	Py_INCREF(Py_None);
	return Py_None;
}
开发者ID:gpjt,项目名称:tesserpy,代码行数:60,代码来源:tesserpy.cpp


示例11: td_py_get_eltype

td_tag_t td_py_get_eltype(void *v)
{
    if (PyArray_Check( (PyObject *) v)){
        PyArrayObject *arr = (PyArrayObject *)v;
        return numpy_type_to_td(PyArray_TYPE(v));
    }
    return TD_UNKNOWN;
}
开发者ID:gvidaver,项目名称:xlang,代码行数:8,代码来源:td_python.c


示例12: write_coords

static PyObject* write_coords(PyObject* self, PyObject* args)
{
    oskar_MeasurementSet* h = 0;
    PyObject *capsule = 0;
    PyObject *obj[] = {0, 0, 0};
    PyArrayObject *uu = 0, *vv = 0, *ww = 0;
    int start_row = 0, num_baselines = 0;
    double exposure_sec = 0.0, interval_sec = 0.0, time_stamp = 0.0;
    if (!PyArg_ParseTuple(args, "OiiOOOddd", &capsule,
            &start_row, &num_baselines, &obj[0], &obj[1], &obj[2],
            &exposure_sec, &interval_sec, &time_stamp))
        return 0;
    if (!(h = (oskar_MeasurementSet*) get_handle(capsule, name))) return 0;

    /* Make sure input objects are arrays. Convert if required. */
    uu = (PyArrayObject*) PyArray_FROM_OF(obj[0], NPY_ARRAY_IN_ARRAY);
    vv = (PyArrayObject*) PyArray_FROM_OF(obj[1], NPY_ARRAY_IN_ARRAY);
    ww = (PyArrayObject*) PyArray_FROM_OF(obj[2], NPY_ARRAY_IN_ARRAY);
    if (!uu || !vv || !ww)
        goto fail;

    /* Check dimensions. */
    if (num_baselines != (int) PyArray_SIZE(uu) ||
            num_baselines != (int) PyArray_SIZE(vv) ||
            num_baselines != (int) PyArray_SIZE(ww))
    {
        PyErr_SetString(PyExc_RuntimeError, "Input data dimension mismatch.");
        goto fail;
    }

    /* Write the coordinates. */
    Py_BEGIN_ALLOW_THREADS
    if (PyArray_TYPE(uu) == NPY_DOUBLE)
        oskar_ms_write_coords_d(h, start_row, num_baselines,
                (const double*)PyArray_DATA(uu),
                (const double*)PyArray_DATA(vv),
                (const double*)PyArray_DATA(ww),
                exposure_sec, interval_sec, time_stamp);
    else
        oskar_ms_write_coords_f(h, start_row, num_baselines,
                (const float*)PyArray_DATA(uu),
                (const float*)PyArray_DATA(vv),
                (const float*)PyArray_DATA(ww),
                exposure_sec, interval_sec, time_stamp);
    Py_END_ALLOW_THREADS

    Py_XDECREF(uu);
    Py_XDECREF(vv);
    Py_XDECREF(ww);
    return Py_BuildValue("");

fail:
    Py_XDECREF(uu);
    Py_XDECREF(vv);
    Py_XDECREF(ww);
    return 0;
}
开发者ID:OxfordSKA,项目名称:OSKAR,代码行数:57,代码来源:oskar_measurement_set_lib.c


示例13: to_td_val

static void to_td_val(td_val_t *out, PyObject *pVal)
{
    PyObject *pStr;
    td_array_t *arr;
    PyArrayObject *pArr;
    td_tag_t tag = py_type_to_td(pVal);
    switch (tag) {
    case TD_INT32:
        out->tag = TD_INT32;
        if (PyInt_Check(pVal))
            out->int32_val = PyInt_AS_LONG(pVal);
        else
            out->int32_val = PyLong_AsLong(pVal);
        break;
    case TD_UINT32:
        out->tag = TD_UINT32;
        out->uint32_val = PyLong_AsUnsignedLong(pVal);
        break;
    case TD_INT64:
        out->tag = TD_INT64;
        out->int64_val = PyLong_AsLongLong(pVal);
        break;
    case TD_UINT64:
        out->tag = TD_UINT64;
        out->uint64_val = PyLong_AsUnsignedLongLong(pVal);
        break;
    case TD_DOUBLE:
        out->tag = TD_DOUBLE;
        out->double_val = PyFloat_AsDouble(pVal);
        break;
    case TD_UTF8:
        pStr = pVal;
        if (PyUnicode_Check(pStr)) pStr = PyUnicode_AsUTF8String(pStr);
        size_t len = PyString_Size(pStr);
        char* data = malloc((len+1)*sizeof(char));
        strcpy(PyString_AsString(pStr), data);
        td_string_t *obj = malloc(sizeof(td_string_t));
        obj->length = len;
        obj->data = (void*) data;
        out->tag = TD_UTF8;
        out->object = (void*) obj;
        break;
    case TD_ARRAY:
        arr = (td_array_t *)malloc(sizeof(td_array_t));
        pArr = (PyArrayObject *) pVal;
        arr->data = PyArray_DATA(pArr);
        arr->length = PyArray_SIZE(pArr);
        arr->eltype = numpy_type_to_td(PyArray_TYPE(pArr));
        arr->ndims = PyArray_NDIM(pArr);
        break;
    default:
        out->tag = TD_OBJECT;
        out->owner = td_env_python(NULL, NULL);
        out->object = pVal;
    }
}
开发者ID:aterrel,项目名称:xlang,代码行数:56,代码来源:td_python.c


示例14: _fff_vector_sync_with_PyArrayIter

/* Fetch vector data from an iterator (view or copy) */ 
void _fff_vector_sync_with_PyArrayIter(fff_vector* y, const PyArrayIterObject* it, npy_intp axis) 
{
  if (y->owner) {
    PyArrayObject* ao = (PyArrayObject*) it->ao; 
    COPY_BUFFER(y, PyArray_ITER_DATA(it), PyArray_STRIDE(ao, axis),
		PyArray_TYPE(ao), PyArray_ITEMSIZE(ao));
  }
  else 
    y->data = (double*) PyArray_ITER_DATA(it); 
  
  return; 
}
开发者ID:FNNDSC,项目名称:nipy,代码行数:13,代码来源:fffpy.c


示例15: fff_array_fromPyArray

fff_array* fff_array_fromPyArray(const PyArrayObject* x) 
{
  fff_array* y;
  fff_datatype datatype; 
  unsigned int nbytes; 
  size_t dimX = 1, dimY = 1, dimZ = 1, dimT = 1; 
  size_t offX = 0, offY = 0, offZ = 0, offT = 0; 
  size_t ndims = (size_t)PyArray_NDIM(x);

  /* Check that the input array has less than four dimensions */ 
  if (ndims > 4) {
    FFF_ERROR("Input array has more than four dimensions", EINVAL);
    return NULL;
  }
  /* Check that the input array is aligned */ 
  if (! PyArray_ISALIGNED(x)) {
    FFF_ERROR("Input array is not aligned", EINVAL);
    return NULL;
  }
  /* Match the data type */
  datatype = fff_datatype_fromNumPy(PyArray_TYPE(x)); 
  if (datatype == FFF_UNKNOWN_TYPE) { 
    FFF_ERROR("Unrecognized data type", EINVAL);
    return NULL;    
  }
  
  /* Dimensions and offsets */ 
  nbytes = fff_nbytes(datatype); 
  dimX = PyArray_DIM(x, 0);
  offX = PyArray_STRIDE(x, 0)/nbytes;
  if (ndims > 1) {
    dimY = PyArray_DIM(x, 1);
    offY = PyArray_STRIDE(x, 1)/nbytes;
    if (ndims > 2) {
      dimZ = PyArray_DIM(x, 2);
      offZ = PyArray_STRIDE(x, 2)/nbytes;
      if (ndims > 3) {
	dimT = PyArray_DIM(x, 3);
	offT = PyArray_STRIDE(x, 3)/nbytes;
      }
    }
  }

  /* Create array (not owner) */ 
  y = (fff_array*)malloc(sizeof(fff_array)); 
  *y = fff_array_view(datatype, 
		      (void*) PyArray_DATA(x), 
		      dimX, dimY, dimZ, dimT, 
		      offX, offY, offZ, offT);
  
  return y;
}
开发者ID:FNNDSC,项目名称:nipy,代码行数:52,代码来源:fffpy.c


示例16: local_histogram

void local_histogram(double* H, 
		     unsigned int clamp, 
		     PyArrayIterObject* iter, 
		     const unsigned int* size)
{
  PyArrayObject *block, *im = iter->ao; 
  PyArrayIterObject* block_iter; 
  unsigned int i, left, right, center, halfsize, dim, offset=0; 
  npy_intp block_dims[3];

  UPDATE_ITERATOR_COORDS(iter); 

  /* Compute block corners */ 
  for (i=0; i<3; i++) {
    center = iter->coordinates[i];
    halfsize = size[i]/2; 
    dim = PyArray_DIM(im, i);
  
    /* Left handside corner */ 
    if (center<halfsize)
      left = 0; 
    else
      left = center-halfsize; 

    /* Right handside corner (plus one)*/ 
    right = center+halfsize+1; 
    if (right>dim) 
      right = dim; 

    /* Block properties */ 
    offset += left*PyArray_STRIDE(im, i); 
    block_dims[i] = right-left;

  }

  /* Create the block as a vew and the block iterator */ 
  block = (PyArrayObject*)PyArray_New(&PyArray_Type, 3, block_dims, 
				      PyArray_TYPE(im), PyArray_STRIDES(im), 
				      (void*)(PyArray_DATA(im)+offset), 
				      PyArray_ITEMSIZE(im),
				      NPY_BEHAVED, NULL);
  block_iter = (PyArrayIterObject*)PyArray_IterNew((PyObject*)block); 

  /* Compute block histogram */ 
  histogram(H, clamp, block_iter); 

  /* Free memory */ 
  Py_XDECREF(block_iter); 
  Py_XDECREF(block); 

  return; 
}		     
开发者ID:Garyfallidis,项目名称:nipy,代码行数:52,代码来源:iconic.c


示例17: type_map

MPI_Datatype type_map(PyArrayObject *x, int *count) {  
  /* Return the MPI Datatype corresponding to                       
     the Python data type as follows  
  
     TYPE    py_type  mpi_type  bytes  symbol
     ---------------------------------------- 
     INT       4        6         4      'i'
     LONG      5        8         8      'l'
     FLOAT     6       10         4      'f'  
     DOUBLE    12      11         8      'd'
  
     Also return the total number of elements in the array
  
     The Python datatype COMPLEX ('F') and COMPLEX_DOUBLE ('D')
     is treated as a special case to the absence of an 
     MPI_COMPLEX datatype:
  
     Complex arrays are mapped to float or double arrays with real 
     and imaginary parts alternating and count is updated. */
  
  int py_type;
  MPI_Datatype mpi_type;

  *count = length(x);
  
  py_type = PyArray_TYPE(x);
  if (py_type == NPY_DOUBLE) 
    mpi_type = MPI_DOUBLE;
  else if (py_type == NPY_INT) 
    mpi_type = MPI_INT;
  else if (py_type == NPY_CDOUBLE) {
    mpi_type = MPI_DOUBLE;
    (*count) *= 2;
  } else if (py_type == NPY_FLOAT) 
    mpi_type = MPI_FLOAT;
  else if (py_type == NPY_LONG)   
    mpi_type = MPI_LONG;  
  else if (py_type == NPY_CFLOAT) {
    mpi_type = MPI_FLOAT;
    (*count) *= 2;
  } else {
      /* FIXME:  Should let caller decide about setting Python exception */
    PyErr_Format(PyExc_ValueError,
	    "Array must be of type int or float. I got py_type == %d", py_type);
    /* FIXME: consider MPI_DATATYPE_NULL */
    return (MPI_Datatype) NULL;
  }      

  //printf("Types: py_type=%d, mpi_type=%d\n", py_type, (int) mpi_type);
  
  return mpi_type;
}    
开发者ID:congma,项目名称:pypar,代码行数:52,代码来源:mpiext.c


示例18: coerce_ndarray_double

static double*
coerce_ndarray_double(PyArrayObject *in, PyArrayObject **out)
{
        int pcm_type = PyArray_TYPE(in);
        if (pcm_type==NPY_DOUBLE)
                return ((double *) PyArray_DATA(in));
        else if (PyArray_CanCastSafely(pcm_type, NPY_DOUBLE)) {
                *out = (PyArrayObject*)PyArray_Cast(in, NPY_DOUBLE);
                return ((double *) PyArray_DATA(*out));
        }
        else
                return NULL;
}
开发者ID:miaomaocat,项目名称:chirp,代码行数:13,代码来源:libtfr.c


示例19: _fff_vector_new_from_PyArrayIter

/* Create an fff_vector from a PyArrayIter object */ 
fff_vector* _fff_vector_new_from_PyArrayIter(const PyArrayIterObject* it, npy_intp axis)
{
  fff_vector* y; 
  char* data = PyArray_ITER_DATA(it);
  PyArrayObject* ao = (PyArrayObject*) it->ao; 
  npy_intp dim = PyArray_DIM(ao, axis); 
  npy_intp stride = PyArray_STRIDE(ao, axis); 
  int type = PyArray_TYPE(ao); 
  int itemsize = PyArray_ITEMSIZE(ao); 
   
  y = _fff_vector_new_from_buffer(data, dim, stride, type, itemsize); 
  return y;
}
开发者ID:FNNDSC,项目名称:nipy,代码行数:14,代码来源:fffpy.c


示例20: PyAubio_ArrayToCFvec

fvec_t *
PyAubio_ArrayToCFvec (PyObject *input) {
  PyObject *array;
  fvec_t *vec;
  if (input == NULL) {
    PyErr_SetString (PyExc_ValueError, "input array is not a python object");
    goto fail;
  }
  // parsing input object into a Py_fvec
  if (PyArray_Check(input)) {

    // we got an array, convert it to an fvec 
    if (PyArray_NDIM (input) == 0) {
      PyErr_SetString (PyExc_ValueError, "input array is a scalar");
      goto fail;
    } else if (PyArray_NDIM (input) > 1) {
      PyErr_SetString (PyExc_ValueError,
          "input array has more than one dimensions");
      goto fail;
    }

    if (!PyArray_ISFLOAT (input)) {
      PyErr_SetString (PyExc_ValueError, "input array should be float");
      goto fail;
    } else if (PyArray_TYPE (input) != AUBIO_NPY_SMPL) {
      PyErr_SetString (PyExc_ValueError, "input array should be float32");
      goto fail;
    } else {
      // input data type is float32, nothing else to do
      array = input;
    }

    // vec = new_fvec (vec->length);
    // no need to really allocate fvec, just its struct member 
    vec = (fvec_t *)malloc(sizeof(fvec_t));
    vec->length = PyArray_SIZE (array);
    vec->data = (smpl_t *) PyArray_GETPTR1 (array, 0);

  } else if (PyObject_TypeCheck (input, &PyList_Type)) {
    PyErr_SetString (PyExc_ValueError, "does not convert from list yet");
    return NULL;
  } else {
    PyErr_SetString (PyExc_ValueError, "can only accept vector of float as input");
    return NULL;
  }

  return vec;

fail:
  return NULL;
}
开发者ID:dirkjankrijnders,项目名称:aubio,代码行数:51,代码来源:aubioproxy.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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