本文整理汇总了C++中PyArray_DescrFromType函数的典型用法代码示例。如果您正苦于以下问题:C++ PyArray_DescrFromType函数的具体用法?C++ PyArray_DescrFromType怎么用?C++ PyArray_DescrFromType使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyArray_DescrFromType函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: dotblas_restoredot
static PyObject *
dotblas_restoredot(PyObject *dummy, PyObject *args)
{
PyArray_Descr *descr;
if (!PyArg_ParseTuple(args, "")) return NULL;
if (altered) {
descr = PyArray_DescrFromType(PyArray_FLOAT);
descr->f->dotfunc = oldFunctions[PyArray_FLOAT];
oldFunctions[PyArray_FLOAT] = NULL;
Py_XDECREF(descr);
descr = PyArray_DescrFromType(PyArray_DOUBLE);
descr->f->dotfunc = oldFunctions[PyArray_DOUBLE];
oldFunctions[PyArray_DOUBLE] = NULL;
Py_XDECREF(descr);
descr = PyArray_DescrFromType(PyArray_CFLOAT);
descr->f->dotfunc = oldFunctions[PyArray_CFLOAT];
oldFunctions[PyArray_CFLOAT] = NULL;
Py_XDECREF(descr);
descr = PyArray_DescrFromType(PyArray_CDOUBLE);
descr->f->dotfunc = oldFunctions[PyArray_CDOUBLE];
oldFunctions[PyArray_CDOUBLE] = NULL;
Py_XDECREF(descr);
altered = FALSE;
}
Py_INCREF(Py_None);
return Py_None;
}
开发者ID:jadolfbr,项目名称:Pymol-script-repo,代码行数:34,代码来源:_dotblas.c
示例2: dotblas_alterdot
static PyObject *
dotblas_alterdot(PyObject *dummy, PyObject *args)
{
PyArray_Descr *descr;
if (!PyArg_ParseTuple(args, "")) return NULL;
/* Replace the dot functions to the ones using blas */
if (!altered) {
descr = PyArray_DescrFromType(PyArray_FLOAT);
oldFunctions[PyArray_FLOAT] = descr->f->dotfunc;
descr->f->dotfunc = (PyArray_DotFunc *)FLOAT_dot;
descr = PyArray_DescrFromType(PyArray_DOUBLE);
oldFunctions[PyArray_DOUBLE] = descr->f->dotfunc;
descr->f->dotfunc = (PyArray_DotFunc *)DOUBLE_dot;
descr = PyArray_DescrFromType(PyArray_CFLOAT);
oldFunctions[PyArray_CFLOAT] = descr->f->dotfunc;
descr->f->dotfunc = (PyArray_DotFunc *)CFLOAT_dot;
descr = PyArray_DescrFromType(PyArray_CDOUBLE);
oldFunctions[PyArray_CDOUBLE] = descr->f->dotfunc;
descr->f->dotfunc = (PyArray_DotFunc *)CDOUBLE_dot;
altered = TRUE;
}
Py_INCREF(Py_None);
return Py_None;
}
开发者ID:jadolfbr,项目名称:Pymol-script-repo,代码行数:32,代码来源:_dotblas.c
示例3: logical_or_popcount_neon_512_wrap
static PyObject*
logical_or_popcount_neon_512_wrap(PyObject* self, PyObject* args)
{
// get numpy.array([], numpy.uint8)
PyArrayObject *image_pyobj, *mask_pyobj;
char *image, *mask;
PyArray_Descr *descr1, *descr2;
npy_intp dims1[3], dims2[3];
int pixels;
if (!PyArg_ParseTuple(args, "O!O!i",
&PyArray_Type, &image_pyobj,
&PyArray_Type, &mask_pyobj,
&pixels)){
return NULL;
}
descr1 = PyArray_DescrFromType(NPY_UINT8);
descr2 = PyArray_DescrFromType(NPY_UINT8);
if (PyArray_AsCArray((PyObject **) &image_pyobj, (void *)&image, dims1, 1, descr1) < 0 ||
PyArray_AsCArray((PyObject **) &mask_pyobj, (void *)&mask, dims2, 1, descr2) < 0) {
PyErr_SetString(PyExc_TypeError, "error converting to c array");
return NULL;
}
uint32_t popcnt = logical_or_popcount_neon_512(image, mask, pixels);
PyArray_Free((PyObject *) image_pyobj, (void *) image);
PyArray_Free((PyObject *) mask_pyobj, (void *) mask);
return Py_BuildValue("i", popcnt);
}
开发者ID:hasegaw,项目名称:IkaLog,代码行数:33,代码来源:ikamatcher2_neon_wrap.c
示例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: fftpack_rfftb
PyObject *
fftpack_rfftb(PyObject *NPY_UNUSED(self), PyObject *args)
{
PyObject *op1, *op2;
PyArrayObject *data, *ret;
PyArray_Descr *descr;
double *wsave, *dptr, *rptr;
npy_intp nsave;
int npts, nrepeats, i;
if(!PyArg_ParseTuple(args, "OO", &op1, &op2)) {
return NULL;
}
data = (PyArrayObject *)PyArray_ContiguousFromObject(op1,
NPY_CDOUBLE, 1, 0);
if (data == NULL) {
return NULL;
}
npts = PyArray_DIM(data, PyArray_NDIM(data) - 1);
ret = (PyArrayObject *)PyArray_Zeros(PyArray_NDIM(data), PyArray_DIMS(data),
PyArray_DescrFromType(NPY_DOUBLE), 0);
descr = PyArray_DescrFromType(NPY_DOUBLE);
if (PyArray_AsCArray(&op2, (void *)&wsave, &nsave, 1, descr) == -1) {
goto fail;
}
if (data == NULL || ret == NULL) {
goto fail;
}
if (nsave != npts*2 + 15) {
PyErr_SetString(ErrorObject, "invalid work array for fft size");
goto fail;
}
nrepeats = PyArray_SIZE(ret)/npts;
rptr = (double *)PyArray_DATA(ret);
dptr = (double *)PyArray_DATA(data);
NPY_SIGINT_ON;
for (i = 0; i < nrepeats; i++) {
memcpy((char *)(rptr + 1), (dptr + 2), (npts - 1)*sizeof(double));
rptr[0] = dptr[0];
rfftb(npts, rptr, wsave);
rptr += npts;
dptr += npts*2;
}
NPY_SIGINT_OFF;
PyArray_Free(op2, (char *)wsave);
Py_DECREF(data);
return (PyObject *)ret;
fail:
PyArray_Free(op2, (char *)wsave);
Py_XDECREF(data);
Py_XDECREF(ret);
return NULL;
}
开发者ID:MrBago,项目名称:numpy,代码行数:57,代码来源:fftpack_litemodule.c
示例6: QUATERNION_setitem
static int QUATERNION_setitem(PyObject *op, char *ov, PyArrayObject *ap)
{
quaternion q;
if (PyArray_IsScalar(op, Quaternion)) {
q = ((PyQuaternionScalarObject *)op)->obval;
}
else {
q.w = PyFloat_AsDouble(PyTuple_GetItem(op, 0));
q.x = PyFloat_AsDouble(PyTuple_GetItem(op, 1));
q.y = PyFloat_AsDouble(PyTuple_GetItem(op, 2));
q.z = PyFloat_AsDouble(PyTuple_GetItem(op, 3));
}
if (PyErr_Occurred()) {
if (PySequence_Check(op)) {
PyErr_Clear();
PyErr_SetString(PyExc_ValueError,
"setting an array element with a sequence.");
}
return -1;
}
if (ap == NULL || PyArray_ISBEHAVED(ap))
*((quaternion *)ov)=q;
else {
PyArray_Descr *descr;
descr = PyArray_DescrFromType(NPY_DOUBLE);
descr->f->copyswap(ov, &q.w, !PyArray_ISNOTSWAPPED(ap), NULL);
descr->f->copyswap(ov+8, &q.x, !PyArray_ISNOTSWAPPED(ap), NULL);
descr->f->copyswap(ov+16, &q.y, !PyArray_ISNOTSWAPPED(ap), NULL);
descr->f->copyswap(ov+24, &q.z, !PyArray_ISNOTSWAPPED(ap), NULL);
Py_DECREF(descr);
}
return 0;
}
开发者ID:jayvius,项目名称:numpy-dtypes,代码行数:35,代码来源:numpy_quaternion.c
示例7: QUATERNION_getitem
static PyObject *
QUATERNION_getitem(char *ip, PyArrayObject *ap)
{
quaternion q;
PyObject *tuple;
if ((ap == NULL) || PyArray_ISBEHAVED_RO(ap)) {
q = *((quaternion *)ip);
}
else {
PyArray_Descr *descr;
descr = PyArray_DescrFromType(NPY_DOUBLE);
descr->f->copyswap(&q.w, ip, !PyArray_ISNOTSWAPPED(ap), NULL);
descr->f->copyswap(&q.x, ip+8, !PyArray_ISNOTSWAPPED(ap), NULL);
descr->f->copyswap(&q.y, ip+16, !PyArray_ISNOTSWAPPED(ap), NULL);
descr->f->copyswap(&q.z, ip+24, !PyArray_ISNOTSWAPPED(ap), NULL);
Py_DECREF(descr);
}
tuple = PyTuple_New(4);
PyTuple_SET_ITEM(tuple, 0, PyFloat_FromDouble(q.w));
PyTuple_SET_ITEM(tuple, 1, PyFloat_FromDouble(q.x));
PyTuple_SET_ITEM(tuple, 2, PyFloat_FromDouble(q.y));
PyTuple_SET_ITEM(tuple, 3, PyFloat_FromDouble(q.z));
return tuple;
}
开发者ID:jayvius,项目名称:numpy-dtypes,代码行数:27,代码来源:numpy_quaternion.c
示例8: PyArray_DescrFromType
PyArrayObject *func_PyArray_NewFromDescr(int datatype, const int ndims,
Py_intptr_t *dims) {
return reinterpret_cast<PyArrayObject *>(PyArray_NewFromDescr(
&PyArray_Type, PyArray_DescrFromType(datatype), ndims, // rank
dims, // Length in each dimension
nullptr, NULL, 0, nullptr));
}
开发者ID:dezed,项目名称:mantid,代码行数:7,代码来源:NumpyFunctions.cpp
示例9: fprintf
static PyObject *Py_longdouble2string(PyObject *self, PyObject *args) {
PyObject *longdouble_obj = NULL;
long double _longdouble;
char _string[STRINGLEN];
long ndigit = 0;
if (!PyArg_ParseTuple(args,
(char*)"Ol",
&longdouble_obj,
&ndigit)) {
fprintf(stderr,"Failed to parse longdouble object.\n");
return NULL;
}
// raise an exception if this isn't a scalar...
if (!PyArray_CheckScalar(longdouble_obj)) {
PyErr_SetString(LongDoubleError,"Input long double must be a scalar.");
return NULL;
}
// cast to long double
PyArray_CastScalarToCtype(longdouble_obj, &_longdouble, PyArray_DescrFromType(NPY_LONGDOUBLE));
// do the conversion
if (longdouble2string(_longdouble, _string, ndigit) < 0) {
PyErr_SetString(LongDoubleError,"Error with conversion.");
return NULL;
}
return PyString_FromString(_string);
}
开发者ID:erykoff,项目名称:longdouble_conv,代码行数:31,代码来源:longdouble_pywrap.c
示例10: _PyArrayProxy_New
/*@[email protected]*/ static INLINE PyObject*
_PyArrayProxy_New(
/*@[email protected]*/ PyObject* self,
int nd,
const npy_intp* dims,
int typenum,
const void* data,
const int flags) {
PyArray_Descr* type_descr = NULL;
PyObject* result = NULL;
type_descr = (PyArray_Descr*)PyArray_DescrFromType(typenum);
if (type_descr == NULL) {
return NULL;
}
result = (PyObject*)PyArray_NewFromDescr(
&PyArray_Type,
type_descr,
nd, (npy_intp*)dims,
NULL,
(void*)data,
NPY_C_CONTIGUOUS | flags,
NULL);
if (result == NULL) {
return NULL;
}
Py_INCREF(self);
PyArray_BASE(result) = (PyObject*)self;
return result;
}
开发者ID:rajul,项目名称:astropy,代码行数:33,代码来源:pyutil.c
示例11: PyInt_AsLong
// Static helper functions
// =============================================================================
double * Epetra_NumPySerialSymDenseMatrix::getArray(PyObject * pyObject)
{
// If tmp_array is NULL, build a PyArrayObject from the pyObject
if (!tmp_array)
{
// If pyObject is an int, then emulate an int-int constructor
if (PyInt_Check(pyObject))
{
int numRows = (int) PyInt_AsLong(pyObject);
npy_intp dimensions[ ] = {numRows, numRows};
tmp_array = (PyArrayObject *)
PyArray_SimpleNew(2,dimensions,NPY_DOUBLE);
}
// If pyObject is not a bool nor an int, try to build a
// contiguous 2D PyArrayObject from the pyObject
else
{
// This function returns a borrowed ptr: no DECREF
PyArray_Descr * dtype =
PyArray_DescrFromType(NPY_DOUBLE);
tmp_array = (PyArrayObject *) PyArray_FromAny(pyObject, dtype, 2, 2,
NPY_ARRAY_FARRAY, NULL);
}
}
// If no array has been correctly constructed, clean up and throw a
// PythonException
if (!tmp_array)
{
cleanup();
throw PythonException();
}
return (double*)(PyArray_DATA(tmp_array));
}
开发者ID:EllieGong,项目名称:trilinos,代码行数:36,代码来源:Epetra_NumPySerialSymDenseMatrix.cpp
示例12: M
// =============================================================================
void Epetra_NumPySerialSymDenseMatrix::setArray(bool copy)
{
if (tmp_array)
{
array = tmp_array;
tmp_array = NULL;
}
else
{
npy_intp dimensions[ ] = { M(), N() };
double * data = NULL;
if (!copy) data = Epetra_SerialSymDenseMatrix::A();
// This NumPy function returns a borrowed pointer: no DECREF
PyArray_Descr * dtype = PyArray_DescrFromType(NPY_DOUBLE);
array = (PyArrayObject*)
PyArray_NewFromDescr(&PyArray_Type,dtype,2,dimensions,NULL,(void*)data,
NPY_ARRAY_FARRAY,NULL);
if (!array)
{
cleanup();
throw PythonException();
}
if (copy)
{
double * oldData = Epetra_SerialSymDenseMatrix::A();
double * newData = (double*) PyArray_DATA(array);
int size = dimensions[0] * dimensions[1];
for (int i=0; i<size; ++i) newData[i] = oldData[i];
}
}
}
开发者ID:EllieGong,项目名称:trilinos,代码行数:32,代码来源:Epetra_NumPySerialSymDenseMatrix.cpp
示例13: convertible
static void* convertible(PyObject* ptr)
{
if (!PyArray_Check(ptr))
{
return NULL;
}
PyObject* retval(PyArray_CastToType(
reinterpret_cast<PyArrayObject*>(ptr),
PyArray_DescrFromType(
peer::util::get_numpy_typecode<
native_type::value_type >::value ), 0) );
if (!retval)
{
return NULL;
}
if (PyObject_Size(retval) != 3)
{
boost::python::decref(retval);
return NULL;
}
return retval;
}
开发者ID:Jintram,项目名称:egfrd,代码行数:25,代码来源:position_converters.cpp
示例14: register_cast_function
static void register_cast_function(int sourceType, int destType, PyArray_VectorUnaryFunc *castfunc)
{
PyArray_Descr *descr = PyArray_DescrFromType(sourceType);
PyArray_RegisterCastFunc(descr, destType, castfunc);
PyArray_RegisterCanCast(descr, destType, NPY_NOSCALAR);
Py_DECREF(descr);
}
开发者ID:jayvius,项目名称:numpy-dtypes,代码行数:7,代码来源:numpy_quaternion.c
示例15: multifab_as_numpy
PyObject *
multifab_as_numpy (PyObject * self, PyObject * args)
{
int ndim;
long cptr;
double *ptr;
PyObject *arr = NULL;
npy_intp dims[4];
int idims[4];
if (!PyArg_ParseTuple (args, "li", &cptr, &nbox))
return NULL;
multifab_as_numpy_f((void *) cptr, nbox, idims, &ptr);
dims[0] = idims[0];
dims[1] = idims[1];
dims[2] = idims[2];
dims[3] = idims[3];
dims[ndim] = nc;
arr = PyArray_NewFromDescr(&PyArray_Type,
PyArray_DescrFromType(NPY_DOUBLE), ndim+1, dims, NULL,
ptr, NPY_FORTRAN|NPY_WRITEABLE, NULL);
Py_INCREF(arr);
return arr;
}
开发者ID:dwillcox,项目名称:BoxLib,代码行数:28,代码来源:boxlib_numpy_c.c
示例16: IkaMatcher2_encode_wrap
static PyObject*
IkaMatcher2_encode_wrap(PyObject* self, PyObject* args)
{
// get numpy.array([], numpy.uint8)
PyArrayObject *dest_pyobj, *src_pyobj;
char *dest, *src;
PyArray_Descr *descr;
npy_intp dims[1];
int pixels;
int nd = 1; //number_of_dimensions
if (!PyArg_ParseTuple(args, "O!O!i",
&PyArray_Type, &dest_pyobj,
&PyArray_Type, &src_pyobj,
&pixels)){
return NULL;
}
descr = PyArray_DescrFromType(NPY_UINT8);
if (PyArray_AsCArray((PyObject **) &dest_pyobj, (void *)&dest, dims, nd, descr) < 0 ||
PyArray_AsCArray((PyObject **) &src_pyobj, (void *)&src, dims, nd, descr) < 0) {
PyErr_SetString(PyExc_TypeError, "error converting to c array");
return NULL;
}
IkaMatcher2_encode(dest, src, pixels);
return PyArray_Return(dest_pyobj);
}
开发者ID:hasegaw,项目名称:IkaLog,代码行数:30,代码来源:ikamatcher2_neon_wrap.c
示例17: PyArray_FromAny
void Tomography::appendSinogram(PyObject *sinogram, PyObject *angles)
{
hlp::python::Ref sinogramTmp =
PyArray_FromAny(sinogram, PyArray_DescrFromType(NPY_FLOAT), 2, 2, NPY_ARRAY_ALIGNED | NPY_ARRAY_FORCECAST, nullptr);
hlp::python::Ref anglesTmp = PyArray_FromAny(angles, PyArray_DescrFromType(NPY_FLOAT), 1, 1, NPY_ARRAY_ALIGNED | NPY_ARRAY_FORCECAST, nullptr);
PyArrayObject *sinogramPy = (PyArrayObject *)sinogramTmp.ptr;
PyArrayObject *anglesPy = (PyArrayObject *)anglesTmp.ptr;
const float *sinogramData = reinterpret_cast<float *>(PyArray_DATA(sinogramPy));
const float *anglesData = reinterpret_cast<float *>(PyArray_DATA(anglesPy));
ndim::pointer<const float, 2> sinogramPtr(sinogramData, ndim::getShape<2>(sinogramPy), ndim::getStrides<2>(sinogramPy));
ndim::pointer<const float, 1> anglesPtr(anglesData, ndim::getShape<1>(anglesPy), ndim::getStrides<1>(anglesPy));
tomo::Tomography::appendSinogram(sinogramPtr, anglesPtr);
}
开发者ID:dejfh,项目名称:nicos-livewidget-ng,代码行数:16,代码来源:tomography.cpp
示例18: QUATERNION_copyswap
static void
QUATERNION_copyswap(quaternion *dst, quaternion *src,
int swap, void *NPY_UNUSED(arr))
{
PyArray_Descr *descr;
descr = PyArray_DescrFromType(NPY_DOUBLE);
descr->f->copyswapn(dst, sizeof(double), src, sizeof(double), 4, swap, NULL);
Py_DECREF(descr);
}
开发者ID:jayvius,项目名称:numpy-dtypes,代码行数:9,代码来源:numpy_quaternion.c
示例19: ndimToNumpy
hlp::python::Ref ndimToNumpy(ndim::pointer<const float, 2> data) {
hlp::python::Gil gil;
hlp::unused(gil);
hlp::python::Ref containerRef = ndim::makePyArrayRef(data, gil);
hlp::python::Ref result = PyArray_FromAny(containerRef.ptr, PyArray_DescrFromType(NPY_FLOAT), 2, 2, NPY_ARRAY_ENSURECOPY, nullptr);
return result;
}
开发者ID:dejfh,项目名称:nicos-livewidget-ng,代码行数:10,代码来源:tomography.cpp
示例20: _descr_from_subtype
static PyArray_Descr *
_descr_from_subtype(PyObject *type)
{
PyObject *mro;
mro = ((PyTypeObject *)type)->tp_mro;
if (PyTuple_GET_SIZE(mro) < 2) {
return PyArray_DescrFromType(PyArray_OBJECT);
}
return PyArray_DescrFromTypeObject(PyTuple_GET_ITEM(mro, 1));
}
开发者ID:chadnetzer,项目名称:numpy-gaurdro,代码行数:10,代码来源:scalarapi.c
注:本文中的PyArray_DescrFromType函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论