当前位置: 首页>>代码示例>>C++>>正文


C++ PyNumber_Check函数代码示例

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


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

示例1: PyNumber_Float

static PyObject *mpy_Matrix_inplace_mul(PyObject *M, PyObject *N)
{
    PyObject *tmp_arg_as_py_double;

    if (PyObject_TypeCheck(M, &mpy_MatrixType)) {
        if (PyNumber_Check(N)) {
            tmp_arg_as_py_double = PyNumber_Float(N);
            if (tmp_arg_as_py_double != NULL) {
                double N_as_double = PyFloat_AsDouble(tmp_arg_as_py_double);
                ((mpy_Matrix *)M)->M *= N_as_double;
                Py_INCREF(M);
                return M;
            }
        }
    }
    else if (PyNumber_Check(M)) {
        if (PyObject_TypeCheck(N, &mpy_MatrixType)) {
            tmp_arg_as_py_double = PyNumber_Float(M);
            if (tmp_arg_as_py_double != NULL) {
                double M_as_double = PyFloat_AsDouble(tmp_arg_as_py_double);
                ((mpy_Matrix *)N)->M *= M_as_double;
                Py_INCREF(N);
                return N;
            }
        }
    }

    Py_INCREF(Py_NotImplemented);
    return Py_NotImplemented;
}
开发者ID:volund,项目名称:mango,代码行数:30,代码来源:mangopy_matrix.cpp

示例2: Bar_setbounds

static int Bar_setbounds(BarObject *self, PyObject *value, void *closure) {
  int i;
  double lb=0.0, ub=0.0;
  PyObject *lo, *uo;

  void (*bounder)(glp_prob*,int,int,double,double) = NULL;
  if (!Bar_Valid(self, 1)) return -1;

  i = Bar_Index(self)+1;
  bounder = Bar_Row(self) ? glp_set_row_bnds : glp_set_col_bnds;

  if (value==NULL || value==Py_None) {
    // We want it unbounded and free.
    bounder(LP, i, GLP_FR, 0.0, 0.0);
    return 0;
  }

  if (PyNumber_Check(value)) {
    // We want an equality fixed bound.
    value = PyNumber_Float(value);
    if (!value) return -1;
    lb = PyFloat_AsDouble(value);
    Py_DECREF(value);
    if (PyErr_Occurred()) return -1;
    bounder(LP, i, GLP_FX, lb, lb);
    return 0;
  }

  char t_error[] = "bounds must be set to None, number, or pair of numbers";
  if (!PyTuple_Check(value) || PyTuple_GET_SIZE(value)!=2) {
    PyErr_SetString(PyExc_TypeError, t_error);
    return -1;
  }

  // Get the lower and upper object.  These references are borrowed.
  lo = PyTuple_GetItem(value, 0);
  uo = PyTuple_GetItem(value, 1);

  if ((lo!=Py_None && !PyNumber_Check(lo)) ||
      (uo!=Py_None && !PyNumber_Check(uo))) {
    PyErr_SetString(PyExc_TypeError, t_error);
    return -1;
  }
  if (lo==Py_None) lo=NULL; else lb=PyFloat_AsDouble(lo);
  if (PyErr_Occurred()) return -1;
  if (uo==Py_None) uo=NULL; else ub=PyFloat_AsDouble(uo);
  if (PyErr_Occurred()) return -1;

  if (!lo && !uo)	bounder(LP, i, GLP_FR, 0.0, 0.0);
  else if (!uo)		bounder(LP, i, GLP_LO, lb, 0.0);
  else if (!lo)		bounder(LP, i, GLP_UP, 0.0, ub);
  else if (lb<=ub)	bounder(LP, i, lb==ub ? GLP_FX : GLP_DB, lb, ub);
  else {
    PyErr_SetString(PyExc_ValueError, "lower bound cannot exceed upper bound");
    return -1;
  }
  return 0;
}
开发者ID:CyanoFactory,项目名称:CyanoFactoryKB,代码行数:58,代码来源:bar.c

示例3: PYTHON_INIT_DEFINITION

PYTHON_INIT_DEFINITION(ptPlayer, args, keywords)
{
    // we have two sets of arguments we can use, hence the generic PyObject* pointers
    // argument set 1: pyKey, string, uint32_t, float
    // argument set 2: string, uint32_t
    PyObject* firstObj = NULL; // can be a pyKey or a string
    PyObject* secondObj = NULL; // can be a string or a uint32_t
    PyObject* thirdObj = NULL; // uint32_t
    PyObject* fourthObj = NULL; // float
    if (!PyArg_ParseTuple(args, "OO|OO", &firstObj, &secondObj, &thirdObj, &fourthObj))
    {
        PyErr_SetString(PyExc_TypeError, "__init__ expects one of two argument lists: (ptKey, string, unsigned long, float) or (string, unsigned long)");
        PYTHON_RETURN_INIT_ERROR;
    }

    plKey key;
    plString name;
    uint32_t pid = -1;
    float distSeq = -1;

    if (pyKey::Check(firstObj))
    {
        if (!(PyString_CheckEx(secondObj) && PyNumber_Check(thirdObj) && PyFloat_Check(fourthObj)))
        {
            PyErr_SetString(PyExc_TypeError, "__init__ expects one of two argument lists: (ptKey, string, unsigned long, float) or (string, unsigned long)");
            PYTHON_RETURN_INIT_ERROR;
        }

        key = pyKey::ConvertFrom(firstObj)->getKey();
        name = PyString_AsStringEx(secondObj);
        pid = PyNumber_AsSsize_t(thirdObj, NULL);
        distSeq = (float)PyFloat_AsDouble(fourthObj);
    } else if (PyString_CheckEx(firstObj)) {
        name = PyString_AsStringEx(firstObj);
        if (!PyNumber_Check(secondObj) || thirdObj  || fourthObj)
        {
            PyErr_SetString(PyExc_TypeError, "__init__ expects one of two argument lists: (ptKey, string, unsigned long, float) or (string, unsigned long)");
            PYTHON_RETURN_INIT_ERROR;
        }

        pid = PyNumber_AsSsize_t(secondObj, NULL);
    } else {
        PyErr_SetString(PyExc_TypeError, "__init__ expects one of two argument lists: (ptKey, string, unsigned long, float) or (string, unsigned long)");
        PYTHON_RETURN_INIT_ERROR;
    }

    self->fThis->Init(key, name.c_str(), pid, distSeq);
    PYTHON_RETURN_INIT_OK;
}
开发者ID:Michellacoste,项目名称:Plasma,代码行数:49,代码来源:pyPlayerGlue.cpp

示例4: PyComm_setData

static PyObject *
PyComm_setData (PyObject *self, PyObject *args)
{
  PyObject *current;
  int team, player;
  std::vector<float> values;

  int size = PyTuple_Size(args);
  for (int i = 0; i < size; i++) {
    // retrive i'th object
    current = PyTuple_GET_ITEM(args, i);

    // check type
    if (!PyNumber_Check(current)) {
      PyErr_SetString(PyExc_TypeError,
          "setData() expects all float or integer arguments");
      return NULL;
    }

    // add it to the list
    values.push_back(static_cast<float>(PyFloat_AsDouble(current)));
  }

  Py_BEGIN_ALLOW_THREADS

  // set comm data
  ((PyComm*)self)->comm->setData(values);

  Py_END_ALLOW_THREADS
  
  Py_INCREF(Py_None);
  return Py_None;
}
开发者ID:I82Much,项目名称:nao-man,代码行数:33,代码来源:Comm.cpp

示例5: start

static PyObject *PyView_find(PyView *o, PyObject *_args, PyObject* _kwargs) {
  PWONumber start(0);
  PWOMapping crit;
  try {
    PWOSequence args(_args);
    if (_kwargs) {
      PWOMapping kwargs(_kwargs);
      if (kwargs.hasKey("start")) {
        start = kwargs["start"];
        kwargs.delItem("start");
      }
      crit = kwargs;
    }
    int numargs = args.len();
    for (int i=0; i<numargs; ++i) {
      if (PyNumber_Check((PyObject*)args[i]))
        start = args[i];
      else
        crit = args[i];
    }
    c4_Row temp;
    o->makeRow(temp, crit, false);
    return PWONumber(o->Find(temp, start)).disOwn();
  }
  catch (...) { return 0; }
}
开发者ID:SASfit,项目名称:SASfit,代码行数:26,代码来源:PyView.cpp

示例6: pyimg_setitem

static int pyimg_setitem(PyObject *self, Py_ssize_t i, PyObject *v) {
    long tmp;
    struct bug_img *img = &((pyimgObject *) self)->img;
    if(!img->start) {
        PyErr_SetString(PyExc_Exception, "No memory allocated yet.");
        return -1;
    }
    if(i >= img->length || i < 0) {
        PyErr_SetString(PyExc_Exception, "Index out of bounds.");
        return -1;
    }
    if(!PyNumber_Check(v)) {
        PyErr_SetString(PyExc_Exception, "Value must be a number");
        return -1;
    }
    PyObject *n = PyNumber_Int(v);
    if(!n) {
        PyErr_SetString(PyExc_Exception, "Value must be convertable to an integer");
        return -1;
    }
    tmp = PyInt_AS_LONG(n);
    Py_DECREF(n);
    if(tmp > 255) tmp = 255;
    if(tmp < 0) tmp = 0;
    ((unsigned char *) img->start)[i] = tmp;
    return 0;
}
开发者ID:buglabs,项目名称:FactoryTests,代码行数:27,代码来源:py_bugv4l.c

示例7: MatrixPointer_setY

static PyObject *
MatrixPointer_setY(MatrixPointer *self, PyObject *arg)
{
	PyObject *tmp, *streamtmp;
	
	if (arg == NULL) {
		Py_INCREF(Py_None);
		return Py_None;
	}
    
	int isNumber = PyNumber_Check(arg);
	if (isNumber == 1) {
		PySys_WriteStderr("MatrixPointer y attributes must be a PyoObject.\n");
        if (PyInt_AsLong(PyObject_CallMethod(self->server, "getIsBooted", NULL))) {
            PyObject_CallMethod(self->server, "shutdown", NULL);
        }
        Py_Exit(1);
	}
	
	tmp = arg;
	Py_INCREF(tmp);
	Py_XDECREF(self->y);
    
    self->y = tmp;
    streamtmp = PyObject_CallMethod((PyObject *)self->y, "_getStream", NULL);
    Py_INCREF(streamtmp);
    Py_XDECREF(self->y_stream);
    self->y_stream = (Stream *)streamtmp;
    
	Py_INCREF(Py_None);
	return Py_None;
}	
开发者ID:xyproto,项目名称:gosignal,代码行数:32,代码来源:matrixprocessmodule.c

示例8: FourBandMain_setFreq3

static PyObject *
FourBandMain_setFreq3(FourBandMain *self, PyObject *arg)
{
	PyObject *tmp, *streamtmp;

	if (arg == NULL) {
		Py_INCREF(Py_None);
		return Py_None;
	}

	int isNumber = PyNumber_Check(arg);

	tmp = arg;
	Py_INCREF(tmp);
	Py_DECREF(self->freq3);
	if (isNumber == 1) {
		self->freq3 = PyNumber_Float(tmp);
        self->modebuffer[2] = 0;
	}
	else {
		self->freq3 = tmp;
        streamtmp = PyObject_CallMethod((PyObject *)self->freq3, "_getStream", NULL);
        Py_INCREF(streamtmp);
        Py_XDECREF(self->freq3_stream);
        self->freq3_stream = (Stream *)streamtmp;
		self->modebuffer[2] = 1;
	}

	Py_INCREF(Py_None);
	return Py_None;
}
开发者ID:BackupGGCode,项目名称:pyo,代码行数:31,代码来源:bandsplitmodule.c

示例9: BandSplitter_setQ

static PyObject *
BandSplitter_setQ(BandSplitter *self, PyObject *arg)
{
	PyObject *tmp, *streamtmp;

	if (arg == NULL) {
		Py_INCREF(Py_None);
		return Py_None;
	}

	int isNumber = PyNumber_Check(arg);

	tmp = arg;
	Py_INCREF(tmp);
	Py_DECREF(self->q);
	if (isNumber == 1) {
		self->q = PyNumber_Float(tmp);
        self->modebuffer[0] = 0;
        BandSplitter_compute_variables((BandSplitter *)self, PyFloat_AS_DOUBLE(self->q));
	}
	else {
		self->q = tmp;
        streamtmp = PyObject_CallMethod((PyObject *)self->q, "_getStream", NULL);
        Py_INCREF(streamtmp);
        Py_XDECREF(self->q_stream);
        self->q_stream = (Stream *)streamtmp;
		self->modebuffer[0] = 1;
	}

    (*self->mode_func_ptr)(self);

	Py_INCREF(Py_None);
	return Py_None;
}
开发者ID:BackupGGCode,项目名称:pyo,代码行数:34,代码来源:bandsplitmodule.c

示例10: OscBank_setArnda

static PyObject *
OscBank_setArnda(OscBank *self, PyObject *arg)
{
	PyObject *tmp, *streamtmp;
	
	if (arg == NULL) {
		Py_INCREF(Py_None);
		return Py_None;
	}
    
	int isNumber = PyNumber_Check(arg);
	
	tmp = arg;
	Py_INCREF(tmp);
	Py_DECREF(self->arnda);
	if (isNumber == 1) {
		self->arnda = PyNumber_Float(tmp);
        self->modebuffer[8] = 0;
	}
	else {
		self->arnda = tmp;
        streamtmp = PyObject_CallMethod((PyObject *)self->arnda, "_getStream", NULL);
        Py_INCREF(streamtmp);
        Py_XDECREF(self->arnda_stream);
        self->arnda_stream = (Stream *)streamtmp;
		self->modebuffer[8] = 1;
	}
    
	Py_INCREF(Py_None);
	return Py_None;
}	
开发者ID:aalex,项目名称:ubuntu-python-pyo,代码行数:31,代码来源:oscbankmodule.c

示例11: Chorus_setMix

static PyObject *
Chorus_setMix(Chorus *self, PyObject *arg)
{
	PyObject *tmp, *streamtmp;
	
	if (arg == NULL) {
		Py_INCREF(Py_None);
		return Py_None;
	}
    
	int isNumber = PyNumber_Check(arg);
    
	tmp = arg;
	Py_INCREF(tmp);
	Py_DECREF(self->mix);
	if (isNumber == 1) {
		self->mix = PyNumber_Float(tmp);
        self->modebuffer[4] = 0;
	}
	else {
		self->mix = tmp;
        streamtmp = PyObject_CallMethod((PyObject *)self->mix, "_getStream", NULL);
        Py_INCREF(streamtmp);
        Py_XDECREF(self->mix_stream);
        self->mix_stream = (Stream *)streamtmp;
		self->modebuffer[4] = 1;
	}
    
    (*self->mode_func_ptr)(self);
    
	Py_INCREF(Py_None);
	return Py_None;
}	
开发者ID:aalex,项目名称:ubuntu-python-pyo,代码行数:33,代码来源:chorusmodule.c

示例12: ue_py_slate_cast

static PyObject *py_ue_sborder_set_padding(ue_PySBorder *self, PyObject * args)
{
	ue_py_slate_cast(SBorder);

	PyObject *py_padding;
	if (!PyArg_ParseTuple(args, "O:set_padding", &py_padding))
	{
		return nullptr;
	}

	FMargin *margin = ue_py_check_struct<FMargin>(py_padding);
	if (!margin)
	{
		if (!PyNumber_Check(py_padding))
		{
			return PyErr_Format(PyExc_Exception, "argument is not a FMargin or a number");
		}
		PyObject *py_float = PyNumber_Float(py_padding);
		FMargin new_margin(PyFloat_AsDouble(py_float));
		margin = &new_margin;
		Py_DECREF(py_float);
	}

	py_SBorder->SetPadding(*margin);

	Py_RETURN_SLATE_SELF;
}
开发者ID:rdsgautier,项目名称:UnrealEnginePython,代码行数:27,代码来源:UEPySBorder.cpp

示例13: Harmonizer_setFeedback

static PyObject *
Harmonizer_setFeedback(Harmonizer *self, PyObject *arg)
{
    PyObject *tmp, *streamtmp;

    if (arg == NULL) {
        Py_INCREF(Py_None);
        return Py_None;
    }

    int isNumber = PyNumber_Check(arg);

    tmp = arg;
    Py_INCREF(tmp);
    Py_DECREF(self->feedback);
    if (isNumber == 1) {
        self->feedback = PyNumber_Float(tmp);
        self->modebuffer[3] = 0;
    }
    else {
        self->feedback = tmp;
        streamtmp = PyObject_CallMethod((PyObject *)self->feedback, "_getStream", NULL);
        Py_INCREF(streamtmp);
        Py_XDECREF(self->feedback_stream);
        self->feedback_stream = (Stream *)streamtmp;
        self->modebuffer[3] = 1;
    }

    (*self->mode_func_ptr)(self);

    Py_INCREF(Py_None);
    return Py_None;
}
开发者ID:aalex,项目名称:ubuntu-python-pyo,代码行数:33,代码来源:harmonizermodule.c

示例14: OscBank_setArndf

static PyObject *
OscBank_setArndf(OscBank *self, PyObject *arg)
{
	PyObject *tmp, *streamtmp;

    ASSERT_ARG_NOT_NULL

	int isNumber = PyNumber_Check(arg);

	tmp = arg;
	Py_INCREF(tmp);
	Py_DECREF(self->arndf);
	if (isNumber == 1) {
		self->arndf = PyNumber_Float(tmp);
        self->modebuffer[7] = 0;
	}
	else {
		self->arndf = tmp;
        streamtmp = PyObject_CallMethod((PyObject *)self->arndf, "_getStream", NULL);
        Py_INCREF(streamtmp);
        Py_XDECREF(self->arndf_stream);
        self->arndf_stream = (Stream *)streamtmp;
		self->modebuffer[7] = 1;
	}

	Py_INCREF(Py_None);
	return Py_None;
}
开发者ID:razorboy73,项目名称:pyo,代码行数:28,代码来源:oscbankmodule.c

示例15: LFO_setSharp

static PyObject *
LFO_setSharp(LFO *self, PyObject *arg)
{
	PyObject *tmp, *streamtmp;

    ASSERT_ARG_NOT_NULL

	int isNumber = PyNumber_Check(arg);

	tmp = arg;
	Py_INCREF(tmp);
	Py_DECREF(self->sharp);
	if (isNumber == 1) {
		self->sharp = PyNumber_Float(tmp);
        self->modebuffer[3] = 0;
	}
	else {
		self->sharp = tmp;
        streamtmp = PyObject_CallMethod((PyObject *)self->sharp, "_getStream", NULL);
        Py_INCREF(streamtmp);
        Py_XDECREF(self->sharp_stream);
        self->sharp_stream = (Stream *)streamtmp;
		self->modebuffer[3] = 1;
	}

    (*self->mode_func_ptr)(self);

	Py_INCREF(Py_None);
	return Py_None;
}
开发者ID:belangeo,项目名称:pyo,代码行数:30,代码来源:lfomodule.c


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