本文整理汇总了C++中PyInt_AS_LONG函数的典型用法代码示例。如果您正苦于以下问题:C++ PyInt_AS_LONG函数的具体用法?C++ PyInt_AS_LONG怎么用?C++ PyInt_AS_LONG使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyInt_AS_LONG函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: choose_node_with_higher_cardinality
/*
def choose_node_with_higher_cardinality(condensed_matrix,nodes,cutoff):
"""
Returns the node in 'nodes' which has the bigger number of neighbours. One node
is a neighbour of other if the distance between them is lower than the cutoff.
The distances are stored in a condensed form distance matrix ('condensed_matrix') which
represents a 'row_len' x 'row_len' symmetric square matrix.
"""
neighbors = numpy.array([0]*len(nodes))
len_nodes = len(nodes)
nodes.sort()
for i in range(len_nodes-1):
inode = nodes[i]
for j in range(i+1,len_nodes):
#print inode, nodes[j],":",access_element(condensed_matrix, inode, nodes[j]-1, row_len)
if condensed_matrix[inode,nodes[j]]<=cutoff: #access_element(condensed_matrix, inode, nodes[j]-1, row_len) <= cutoff:
neighbors[i] += 1
neighbors[j] += 1
#print neighbors
idx = neighbors.argmax()
return (nodes[idx],neighbors[idx])
*/
static PyObject* condensedMatrix_choose_node_with_higher_cardinality(CondensedMatrix* self, PyObject *args){
// Parse all arguments
PyObject *nodes_list,*cutoff_obj;
if (!PyArg_ParseTuple(args, "OO",&nodes_list,&cutoff_obj)){
PyErr_SetString(PyExc_RuntimeError, "Error parsing parameters.");
return NULL;
}
// Convert to C types
double cutoff = PyFloat_AsDouble((PyObject *)cutoff_obj);
int len_nodes = PyList_Size((PyObject *)nodes_list);
int* nodes = new int[len_nodes];
for(int i = 0; i < len_nodes; ++i){
nodes[i] = PyInt_AS_LONG(PyList_GET_ITEM((PyObject*) nodes_list,i));
}
//Do the job
vector<int> neighbors(len_nodes,0);
int inode,jnode,pos;
double value;
for (int i =0; i< len_nodes-1;++i){
inode = nodes[i];
for (int j = i+1; j< len_nodes;++j){
jnode =nodes[j];
pos = calc_vector_pos(inode,jnode,self);
value =self->data[pos];
if(value <= cutoff){
neighbors[i] += 1;
neighbors[j] += 1;
}
}
}
//Get index with maximum value
int max = *(max_element(neighbors.begin(),neighbors.end()));
int index = 0;
for (int i = 0; i< len_nodes-1;++i){
if (neighbors[i]==max){
index = i;
break;
}
}
PyObject* tuple = Py_BuildValue("(ii)", nodes[index],neighbors[index]);//PyTuple_Pack(2,nodes[index],neighbors[index]);
delete [] nodes;
return tuple;
}
开发者ID:asford,项目名称:pyRMSD,代码行数:68,代码来源:Matrix.Neighbours.cpp
示例2: PySequence_Size
/**
* Returns an AmberSystem block as an array of ints.
*
* You have to free the thing you get back from this method!
* Equivalent to: mol.blocks[block_name]
*/
int *get_block_as_int_array(PyObject *mol, const char *block_name, int *size)
{
PyObject *block;
if((block = get_block(mol, block_name)) == NULL)
{
// fprintf(stderr, "get_block_as_int_array: Couldn't find block %s\n", block_name);
return NULL;
}
// Extract the list of integers from the AmberSystem
Py_ssize_t block_length = PySequence_Size(block);
*size = (int) block_length;
int *data = (int*) malloc(sizeof(int) * (int) block_length);
for(Py_ssize_t i = 0; i < block_length; i++)
data[i] = PyInt_AS_LONG(PySequence_Fast_GET_ITEM(block, i));
return data;
}
开发者ID:govindarb,项目名称:mmdevel,代码行数:23,代码来源:mmeval.c
示例3: ColorAttribute_SetColor
/*static*/ PyObject *
ColorAttribute_SetColor(PyObject *self, PyObject *args)
{
ColorAttributeObject *obj = (ColorAttributeObject *)self;
unsigned char *cvals = obj->data->GetColor();
if(!PyArg_ParseTuple(args, "cccc", &cvals[0], &cvals[1], &cvals[2], &cvals[3]))
{
PyObject *tuple;
if(!PyArg_ParseTuple(args, "O", &tuple))
return NULL;
if(PyTuple_Check(tuple))
{
if(PyTuple_Size(tuple) != 4)
return NULL;
PyErr_Clear();
for(int i = 0; i < PyTuple_Size(tuple); ++i)
{
int c;
PyObject *item = PyTuple_GET_ITEM(tuple, i);
if(PyFloat_Check(item))
c = int(PyFloat_AS_DOUBLE(item));
else if(PyInt_Check(item))
c = int(PyInt_AS_LONG(item));
else if(PyLong_Check(item))
c = int(PyLong_AsDouble(item));
else
c = 0;
if(c < 0) c = 0;
if(c > 255) c = 255;
cvals[i] = (unsigned char)(c);
}
}
else
return NULL;
}
// Mark the color in the object as modified.
obj->data->SelectColor();
Py_INCREF(Py_None);
return Py_None;
}
开发者ID:ahota,项目名称:visit_intel,代码行数:46,代码来源:PyColorAttribute.C
示例4: SpiDev_writebytes
static PyObject *
SpiDev_writebytes(SpiDevObject *self, PyObject *args)
{
int status;
uint16_t ii, len;
uint8_t buf[SPIDEV_MAXPATH];
PyObject *list;
if (!PyArg_ParseTuple(args, "O:write", &list))
return NULL;
if (!PyList_Check(list)) {
PyErr_SetString(PyExc_TypeError, wrmsg);
return NULL;
}
if ((len = PyList_GET_SIZE(list)) > SPIDEV_MAXPATH) {
PyErr_SetString(PyExc_OverflowError, wrmsg);
return NULL;
}
for (ii = 0; ii < len; ii++) {
PyObject *val = PyList_GET_ITEM(list, ii);
if (!PyInt_Check(val)) {
PyErr_SetString(PyExc_TypeError, wrmsg);
return NULL;
}
buf[ii] = (__u8)PyInt_AS_LONG(val);
}
status = write(self->fd, &buf[0], len);
if (status < 0) {
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}
if (status != len) {
perror("short write");
return NULL;
}
Py_INCREF(Py_None);
return Py_None;
}
开发者ID:oryxr,项目名称:py-spidev,代码行数:45,代码来源:spidev_module.c
示例5: set_int
static int
set_int(_UpdateCollectionPackageObject *self, PyObject *value, void *member_offset)
{
long val;
if (check_UpdateCollectionPackageStatus(self))
return -1;
if (PyLong_Check(value)) {
val = PyLong_AsLong(value);
} else if (PyInt_Check(value)) {
val = PyInt_AS_LONG(value);
} else {
PyErr_SetString(PyExc_TypeError, "Number expected!");
return -1;
}
cr_UpdateCollectionPackage *pkg = self->pkg;
*((int *) ((size_t) pkg + (size_t) member_offset)) = (int) val;
return 0;
}
开发者ID:ralphbean,项目名称:createrepo_c,代码行数:18,代码来源:updatecollectionpackage-py.c
示例6: extract
static unsigned BOOST_PYTHON_LONG_LONG extract(PyObject* intermediate)
{
#if PY_VERSION_HEX < 0x03000000
if (PyInt_Check(intermediate))
{
return numeric_cast<unsigned BOOST_PYTHON_LONG_LONG>(PyInt_AS_LONG(intermediate));
}
else
#endif
{
unsigned BOOST_PYTHON_LONG_LONG result = PyLong_AsUnsignedLongLong(intermediate);
if (PyErr_Occurred())
throw_error_already_set();
return result;
}
}
开发者ID:RossBille,项目名称:vim-config,代码行数:18,代码来源:builtin_converters.cpp
示例7: __Pyx_PyInt_AsSignedLongLong
static INLINE signed PY_LONG_LONG __Pyx_PyInt_AsSignedLongLong(PyObject* x) {
#if PY_VERSION_HEX < 0x03000000
if (likely(PyInt_CheckExact(x) || PyInt_Check(x))) {
long val = PyInt_AS_LONG(x);
return (signed PY_LONG_LONG)val;
} else
#endif
if (likely(PyLong_CheckExact(x) || PyLong_Check(x))) {
return PyLong_AsLongLong(x);
} else {
signed PY_LONG_LONG val;
PyObject *tmp = __Pyx_PyNumber_Int(x);
if (!tmp) return (signed PY_LONG_LONG)-1;
val = __Pyx_PyInt_AsSignedLongLong(tmp);
Py_DECREF(tmp);
return val;
}
}
开发者ID:Mouse-Imaging-Centre,项目名称:generate_deformation_fields,代码行数:18,代码来源:setup.c
示例8: set_num
static int
set_num(_PackageObject *self, PyObject *value, void *member_offset)
{
gint64 val;
if (check_PackageStatus(self))
return -1;
if (PyLong_Check(value)) {
val = (gint64) PyLong_AsLong(value);
} else if (PyInt_Check(value)) {
val = (gint64) PyInt_AS_LONG(value);
} else {
PyErr_SetString(PyExc_TypeError, "Number expected!");
return -1;
}
cr_Package *pkg = self->package;
*((gint64 *) ((size_t) pkg + (size_t) member_offset)) = val;
return 0;
}
开发者ID:cottsay,项目名称:createrepo_c,代码行数:18,代码来源:package-py.c
示例9: PyGSL_PyArray_generate_gsl_matrix_view
static PyArrayObject *
PyGSL_PyArray_generate_gsl_matrix_view(PyObject *src,
int array_type,
int argnum)
{
PyObject *tmp;
PyArrayObject *a_array = NULL;
PyGSL_array_index_t dimensions[2];
int i;
FUNC_MESS_BEGIN();
if(!PySequence_Check(src) || PySequence_Size(src) != 2){
sprintf(pygsl_error_str, "I need a sequence of two elements as argument number % 3d",
argnum);
PyErr_SetString(PyExc_TypeError, pygsl_error_str);
return NULL;
}
for(i = 0; i<2; i++){
tmp = PyNumber_Int(PySequence_GetItem(src, i));
if(!tmp){
sprintf(pygsl_error_str, "I could not convert argument number % 3d. for dimension %3d to an integer.",
argnum, i);
PyErr_SetString(PyExc_TypeError, pygsl_error_str);
return NULL;
}
dimensions[i] = PyInt_AS_LONG(tmp);
Py_DECREF(tmp);
if(dimensions[i] <= 0){
sprintf(pygsl_error_str, "Argument number % 3d is % 10ld< 0. Its the size of the vector and thus must be positive!",
argnum, (long)dimensions[i]);
PyErr_SetString(PyExc_TypeError, pygsl_error_str);
return NULL;
}
}
a_array = (PyArrayObject *) PyGSL_New_Array(2, dimensions, array_type);
if(NULL == a_array){
return NULL;
}
return a_array;
}
开发者ID:juhnowski,项目名称:FishingRod,代码行数:44,代码来源:block_helpers.c
示例10: condensedMatrix_get_neighbors_for_node
static PyObject* condensedMatrix_get_neighbors_for_node(CondensedMatrix* self, PyObject *args){
// Parse all arguments
PyObject *nodes_left_list, *node_obj,*cutoff_obj;
if (!PyArg_ParseTuple(args, "OOO",&node_obj,&nodes_left_list,&cutoff_obj)){
PyErr_SetString(PyExc_RuntimeError, "Error parsing parameters.");
return NULL;
}
// Convert to C types
int node = (int) PyInt_AsLong((PyObject *)node_obj);
double cutoff = PyFloat_AsDouble((PyObject *)cutoff_obj);
int len_nodes_left = PyList_Size((PyObject *)nodes_left_list);
int* nodes_left = new int[len_nodes_left];
for(int i = 0; i < len_nodes_left; ++i){
nodes_left[i] = PyInt_AS_LONG(PyList_GET_ITEM((PyObject*) nodes_left_list,i));
}
// Do the job
vector<int> neighbours;
int pos,j;
for(int i = 0; i < len_nodes_left; ++i){
j = nodes_left[i];
if(node<j){
pos = calc_vector_pos(node,j,self);
if(self->data[pos]<=cutoff){
neighbours.push_back(j);
}
}
if(node>j){
pos = calc_vector_pos(j,node,self);
if(self->data[pos]<=cutoff){
neighbours.push_back(j);
}
}
}
int neigh_len = neighbours.size();
npy_intp dims[1] = {neigh_len};
int* neighbours_data = new int[neigh_len];
copy(&(neighbours[0]),&(neighbours[0]) + neigh_len,neighbours_data);
delete [] nodes_left;
return PyArray_SimpleNewFromData(1,dims,NPY_INT,neighbours_data);
}
开发者ID:asford,项目名称:pyRMSD,代码行数:44,代码来源:Matrix.Neighbours.cpp
示例11: w_object
static void
w_object(PyObject *v, WFILE *p)
{
int i, n;
p->depth++;
if (p->depth > MAX_MARSHAL_STACK_DEPTH) {
p->error = 2;
}
else if (v == NULL) {
w_byte(TYPE_NULL, p);
}
else if (v == Py_None) {
w_byte(TYPE_NONE, p);
}
else if (v == PyExc_StopIteration) {
w_byte(TYPE_STOPITER, p);
}
else if (v == Py_Ellipsis) {
w_byte(TYPE_ELLIPSIS, p);
}
else if (v == Py_False) {
w_byte(TYPE_FALSE, p);
}
else if (v == Py_True) {
w_byte(TYPE_TRUE, p);
}
else if (PyInt_Check(v)) {
long x = PyInt_AS_LONG((PyIntObject *)v);
#if SIZEOF_LONG > 4
long y = Py_ARITHMETIC_RIGHT_SHIFT(long, x, 31);
if (y && y != -1) {
w_byte(TYPE_INT64, p);
w_long64(x, p);
}
else
#endif
{
w_byte(TYPE_INT, p);
w_long(x, p);
}
}
else if (PyLong_Check(v)) {
开发者ID:JupiterSmalltalk,项目名称:openqwaq,代码行数:44,代码来源:marshal.c
示例12: Text3DObject_SetPosition
static PyObject *
Text3DObject_SetPosition(PyObject *self, PyObject *args)
{
Text3DObjectObject *obj = (Text3DObjectObject *)self;
double *dvals = obj->data->GetPosition();
if(!PyArg_ParseTuple(args, "ddd", &dvals[0], &dvals[1], &dvals[2]))
{
PyObject *tuple;
if(!PyArg_ParseTuple(args, "O", &tuple))
return NULL;
if(PyTuple_Check(tuple))
{
if(PyTuple_Size(tuple) != 3)
return NULL;
PyErr_Clear();
for(int i = 0; i < PyTuple_Size(tuple); ++i)
{
PyObject *item = PyTuple_GET_ITEM(tuple, i);
if(PyFloat_Check(item))
dvals[i] = PyFloat_AS_DOUBLE(item);
else if(PyInt_Check(item))
dvals[i] = double(PyInt_AS_LONG(item));
else if(PyLong_Check(item))
dvals[i] = PyLong_AsDouble(item);
else
dvals[i] = 0.;
}
}
else
return NULL;
}
// Mark the position in the object as modified.
obj->data->SelectPosition();
/*CUSTOM*/
UpdateAnnotationHelper(obj->data);
Py_INCREF(Py_None);
return Py_None;
}
开发者ID:burlen,项目名称:visit_vtk_7_src,代码行数:44,代码来源:PyText3DObject.C
示例13: PyDateTime_GET_YEAR
static void *PyDateToINT64(JSOBJ _obj, JSONTypeContext *tc, void *outValue, size_t *_outLen)
{
PyObject *obj = (PyObject *) _obj;
PyObject *date, *ord;
int y, m, d, days;
y = PyDateTime_GET_YEAR(obj);
m = PyDateTime_GET_MONTH(obj);
d = PyDateTime_GET_DAY(obj);
date = PyDate_FromDate(y, m, 1);
ord = PyObject_CallMethod(date, "toordinal", NULL);
days = PyInt_AS_LONG(ord) - EPOCH_ORD + d - 1;
Py_DECREF(date);
Py_DECREF(ord);
*( (JSINT64 *) outValue) = ((JSINT64) days * 86400);
return NULL;
}
开发者ID:MikeAthene,项目名称:ultrajson,代码行数:19,代码来源:objToJSON.c
示例14: test_dict_inner
static int
test_dict_inner(int count)
{
Py_ssize_t pos = 0, iterations = 0;
int i;
PyObject *dict = PyDict_New();
PyObject *v, *k;
if (dict == NULL)
return -1;
for (i = 0; i < count; i++) {
v = PyInt_FromLong(i);
PyDict_SetItem(dict, v, v);
Py_DECREF(v);
}
while (PyDict_Next(dict, &pos, &k, &v)) {
PyObject *o;
iterations++;
i = PyInt_AS_LONG(v) + 1;
o = PyInt_FromLong(i);
if (o == NULL)
return -1;
if (PyDict_SetItem(dict, k, o) < 0) {
Py_DECREF(o);
return -1;
}
Py_DECREF(o);
}
Py_DECREF(dict);
if (iterations != count) {
PyErr_SetString(
TestError,
"test_dict_iteration: dict iteration went wrong ");
return -1;
} else {
return 0;
}
}
开发者ID:Oize,项目名称:pspstacklesspython,代码行数:43,代码来源:_testcapimodule.c
示例15: grp_getgrgid
static PyObject *
grp_getgrgid(PyObject *self, PyObject *pyo_id)
{
PyObject *py_int_id;
unsigned int gid;
struct group *p;
py_int_id = PyNumber_Int(pyo_id);
if (!py_int_id)
return NULL;
gid = PyInt_AS_LONG(py_int_id);
Py_DECREF(py_int_id);
if ((p = getgrgid(gid)) == NULL) {
PyErr_Format(PyExc_KeyError, "getgrgid(): gid not found: %d", gid);
return NULL;
}
return mkgrent(p);
}
开发者ID:grobe0ba,项目名称:plan9front,代码行数:19,代码来源:grpmodule.c
示例16: s_pyvpi_systfdata_settype
int s_pyvpi_systfdata_settype(s_pyvpi_systfdata *self, PyObject *value, void *closure)
{
//Check type, it must be vpiSysTask,vpiSysFunc.
int tmp;
if(!PyInt_Check(value)){
PyErr_SetString(VpiError,
"The value must be vpiSys[Task,Func].");
return -1;
}
tmp = PyInt_AS_LONG(value);
if(tmp != vpiSysTask &&
tmp != vpiSysFunc) {
PyErr_SetString(VpiError,
"The value must be vpiSys[Task,Func].");
return -1;
}
self->_vpi_systfdata.type = tmp;
return 0;
}
开发者ID:GeneKong,项目名称:pyvpi,代码行数:19,代码来源:pysystfdata.c
示例17: builtin_videomode
static PyObject *
builtin_videomode(PyObject *self, PyObject *args)
{
PyObject *v = NULL;
if (!PyArg_UnpackTuple(args, "inb", 1, 1, &v))
return NULL;
if (!PyInt_CheckExact(v))
return NULL;
switch(PyInt_AS_LONG(v)) {
case 0: set80x25(); break;
case 1: set640x480x16(); break;
case 2: set320x200x256(); break;
}
Py_INCREF(Py_True);
return Py_True;
}
开发者ID:brosner,项目名称:cleese,代码行数:19,代码来源:bltinmodule.c
示例18: builtin_inb
static PyObject *
builtin_inb(PyObject *self, PyObject *args)
{
PyObject *v = NULL;
if (!PyArg_UnpackTuple(args, "inb", 1, 1, &v))
return NULL;
if (!PyInt_CheckExact(v)) {
/* ERROR */
return NULL;
} else {
unsigned short port = PyInt_AS_LONG(v);
unsigned char data = in(port);
PyObject *result = PyInt_FromLong(data);
return result;
}
}
开发者ID:brosner,项目名称:cleese,代码行数:19,代码来源:bltinmodule.c
示例19: test_list_api
static PyObject*
test_list_api(PyObject *self)
{
PyObject* list;
int i;
/* SF bug 132008: PyList_Reverse segfaults */
#define NLIST 30
list = PyList_New(NLIST);
if (list == (PyObject*)NULL)
return (PyObject*)NULL;
/* list = range(NLIST) */
for (i = 0; i < NLIST; ++i) {
PyObject* anint = PyInt_FromLong(i);
if (anint == (PyObject*)NULL) {
Py_DECREF(list);
return (PyObject*)NULL;
}
PyList_SET_ITEM(list, i, anint);
}
/* list.reverse(), via PyList_Reverse() */
i = PyList_Reverse(list); /* should not blow up! */
if (i != 0) {
Py_DECREF(list);
return (PyObject*)NULL;
}
/* Check that list == range(29, -1, -1) now */
for (i = 0; i < NLIST; ++i) {
PyObject* anint = PyList_GET_ITEM(list, i);
if (PyInt_AS_LONG(anint) != NLIST-1-i) {
PyErr_SetString(TestError,
"test_list_api: reverse screwed up");
Py_DECREF(list);
return (PyObject*)NULL;
}
}
Py_DECREF(list);
#undef NLIST
Py_INCREF(Py_None);
return Py_None;
}
开发者ID:Oize,项目名称:pspstacklesspython,代码行数:42,代码来源:_testcapimodule.c
示例20: convert_to_double
/* adapted from Python source, floatobject.c:convert_to_double */
int
convert_to_double(PyObject *obj, double *dbl)
{
if (PyFloat_Check(obj)) {
*dbl = PyFloat_AS_DOUBLE(obj);
#ifndef IS_PY3K
} else if (PyInt_Check(obj)) {
*dbl = (double)PyInt_AS_LONG(obj);
#endif
} else if (PyLong_Check(obj)) {
*dbl = PyLong_AsDouble(obj);
if (*dbl == -1.0 && PyErr_Occurred()) {
return 0;
}
} else {
PyErr_SetString(PyExc_ValueError, "Expected a number");
return 0;
}
return 1;
}
开发者ID:shengtu,项目名称:pypybox2d,代码行数:21,代码来源:commonmodule.c
注:本文中的PyInt_AS_LONG函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论