tinysvm_wrap.c

来自「机器学习工具:非常流行的一种分类器」· C语言 代码 · 共 1,300 行 · 第 1/3 页

C
1,300
字号
SWIG_NewPointerObj(void *ptr, swig_type_info *type) {  char result[512];  PyObject *robj;  if (!ptr) {    Py_INCREF(Py_None);    return Py_None;  }#ifdef SWIG_COBJECT_TYPES  robj = PyCObject_FromVoidPtrAndDesc((void *) ptr, type->name, NULL);#else  SWIG_MakePtr(result,ptr,type);  robj = PyString_FromString(result);#endif  return robj;}/* Install Constants */SWIGRUNTIME(void)SWIG_InstallConstants(PyObject *d, swig_const_info constants[]) {  int i;  PyObject *obj;  for (i = 0; constants[i].type; i++) {    switch(constants[i].type) {    case SWIG_PY_INT:      obj = PyInt_FromLong(constants[i].lvalue);      break;    case SWIG_PY_FLOAT:      obj = PyFloat_FromDouble(constants[i].dvalue);      break;    case SWIG_PY_STRING:      obj = PyString_FromString((char *) constants[i].pvalue);      break;    case SWIG_PY_POINTER:      obj = SWIG_NewPointerObj(constants[i].pvalue, *(constants[i]).ptype);      break;    default:      obj = 0;      break;    }    if (obj) {      PyDict_SetItemString(d,constants[i].name,obj);      Py_DECREF(obj);    }  }}#endif#ifdef __cplusplus}#endif/* -------- TYPES TABLE (BEGIN) -------- */#define  SWIGTYPE_p_BaseExample swig_types[0] #define  SWIGTYPE_p_Example swig_types[1] #define  SWIGTYPE_p_Model swig_types[2] static swig_type_info *swig_types[4];/* -------- TYPES TABLE (END) -------- *//*-----------------------------------------------              @(target):= TinySVMc.so  ------------------------------------------------*/#define SWIG_init    initTinySVMc#define SWIG_name    "TinySVMc"#include <tinysvm.h>#include <ctype.h>#include <string.h>#define BaseExample TinySVM::BaseExample#define Example TinySVM::Example #define Model TinySVM::Model#undef VALUEFUNC#define VALUEFUNC(f) ((VALUE (*)())f)#ifdef __cplusplusextern "C" {#endifstatic PyObject *_wrap_BaseExample_add(PyObject *self, PyObject *args) {    PyObject *resultobj;    BaseExample *arg0 ;    char *arg1 ;    PyObject * argo0 =0 ;    int result ;        if(!PyArg_ParseTuple(args,"Os:BaseExample_add",&argo0,&arg1)) return NULL;    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_BaseExample,1)) == -1) return NULL;    result = (int )arg0->add((char const *)arg1);    resultobj = PyInt_FromLong((long)result);    return resultobj;}static PyObject *_wrap_BaseExample_set(PyObject *self, PyObject *args) {    PyObject *resultobj;    BaseExample *arg0 ;    int arg1 ;    char *arg2 ;    PyObject * argo0 =0 ;    int result ;        if(!PyArg_ParseTuple(args,"Ois:BaseExample_set",&argo0,&arg1,&arg2)) return NULL;    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_BaseExample,1)) == -1) return NULL;    result = (int )arg0->set(arg1,(char const *)arg2);    resultobj = PyInt_FromLong((long)result);    return resultobj;}static PyObject *_wrap_BaseExample_get(PyObject *self, PyObject *args) {    PyObject *resultobj;    BaseExample *arg0 ;    int arg1 ;    PyObject * argo0 =0 ;    char *result ;        if(!PyArg_ParseTuple(args,"Oi:BaseExample_get",&argo0,&arg1)) return NULL;    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_BaseExample,1)) == -1) return NULL;    result = (char *)arg0->get(arg1);    resultobj = PyString_FromString(result);    return resultobj;}static PyObject *_wrap_BaseExample_remove(PyObject *self, PyObject *args) {    PyObject *resultobj;    BaseExample *arg0 ;    int arg1 ;    PyObject * argo0 =0 ;    int result ;        if(!PyArg_ParseTuple(args,"Oi:BaseExample_remove",&argo0,&arg1)) return NULL;    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_BaseExample,1)) == -1) return NULL;    result = (int )arg0->remove(arg1);    resultobj = PyInt_FromLong((long)result);    return resultobj;}static PyObject *_wrap_BaseExample_clear(PyObject *self, PyObject *args) {    PyObject *resultobj;    BaseExample *arg0 ;    PyObject * argo0 =0 ;    int result ;        if(!PyArg_ParseTuple(args,"O:BaseExample_clear",&argo0)) return NULL;    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_BaseExample,1)) == -1) return NULL;    result = (int )arg0->clear();    resultobj = PyInt_FromLong((long)result);    return resultobj;}static PyObject *_wrap_BaseExample_size(PyObject *self, PyObject *args) {    PyObject *resultobj;    BaseExample *arg0 ;    PyObject * argo0 =0 ;    int result ;        if(!PyArg_ParseTuple(args,"O:BaseExample_size",&argo0)) return NULL;    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_BaseExample,1)) == -1) return NULL;    result = (int )arg0->size();    resultobj = PyInt_FromLong((long)result);    return resultobj;}static PyObject *_wrap_BaseExample_read(PyObject *self, PyObject *args) {    PyObject *resultobj;    BaseExample *arg0 ;    char *arg1 ;    char *arg2 = "r" ;    int arg3 = 0 ;    PyObject * argo0 =0 ;    int result ;        if(!PyArg_ParseTuple(args,"Os|si:BaseExample_read",&argo0,&arg1,&arg2,&arg3)) return NULL;    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_BaseExample,1)) == -1) return NULL;    result = (int )arg0->read((char const *)arg1,(char const *)arg2,arg3);    resultobj = PyInt_FromLong((long)result);    return resultobj;}static PyObject *_wrap_BaseExample_write(PyObject *self, PyObject *args) {    PyObject *resultobj;    BaseExample *arg0 ;    char *arg1 ;    char *arg2 = "w" ;    int arg3 = 0 ;    PyObject * argo0 =0 ;    int result ;        if(!PyArg_ParseTuple(args,"Os|si:BaseExample_write",&argo0,&arg1,&arg2,&arg3)) return NULL;    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_BaseExample,1)) == -1) return NULL;    result = (int )arg0->write((char const *)arg1,(char const *)arg2,arg3);    resultobj = PyInt_FromLong((long)result);    return resultobj;}static PyObject *_wrap_BaseExample_readSVindex(PyObject *self, PyObject *args) {    PyObject *resultobj;    BaseExample *arg0 ;    char *arg1 ;    char *arg2 = "r" ;    int arg3 = 0 ;    PyObject * argo0 =0 ;    int result ;        if(!PyArg_ParseTuple(args,"Os|si:BaseExample_readSVindex",&argo0,&arg1,&arg2,&arg3)) return NULL;    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_BaseExample,1)) == -1) return NULL;    result = (int )arg0->readSVindex((char const *)arg1,(char const *)arg2,arg3);    resultobj = PyInt_FromLong((long)result);    return resultobj;}static PyObject *_wrap_BaseExample_writeSVindex(PyObject *self, PyObject *args) {    PyObject *resultobj;    BaseExample *arg0 ;    char *arg1 ;    char *arg2 = "w" ;    int arg3 = 0 ;    PyObject * argo0 =0 ;    int result ;        if(!PyArg_ParseTuple(args,"Os|si:BaseExample_writeSVindex",&argo0,&arg1,&arg2,&arg3)) return NULL;    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_BaseExample,1)) == -1) return NULL;    result = (int )arg0->writeSVindex((char const *)arg1,(char const *)arg2,arg3);    resultobj = PyInt_FromLong((long)result);    return resultobj;}static PyObject *_wrap_delete_BaseExample(PyObject *self, PyObject *args) {    PyObject *resultobj;    BaseExample *arg0 ;    PyObject * argo0 =0 ;        if(!PyArg_ParseTuple(args,"O:delete_BaseExample",&argo0)) return NULL;    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_BaseExample,1)) == -1) return NULL;    delete arg0;    Py_INCREF(Py_None);    resultobj = Py_None;    return resultobj;}int  BaseExample_append(BaseExample *self,char *f) {    {        return self->write(f,"a");     }}static PyObject *_wrap_BaseExample_append(PyObject *self, PyObject *args) {    PyObject *resultobj;    BaseExample *arg0 ;    char *arg1 ;    PyObject * argo0 =0 ;    int result ;        if(!PyArg_ParseTuple(args,"Os:BaseExample_append",&argo0,&arg1)) return NULL;    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_BaseExample,1)) == -1) return NULL;    result = (int )BaseExample_append(arg0,arg1);    resultobj = PyInt_FromLong((long)result);    return resultobj;}int  BaseExample_appendSVindex(BaseExample *self,char *f) {    {        return self->writeSVindex(f,"a");     }}static PyObject *_wrap_BaseExample_appendSVindex(PyObject *self, PyObject *args) {    PyObject *resultobj;    BaseExample *arg0 ;    char *arg1 ;    PyObject * argo0 =0 ;    int result ;        if(!PyArg_ParseTuple(args,"Os:BaseExample_appendSVindex",&argo0,&arg1)) return NULL;    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_BaseExample,1)) == -1) return NULL;    result = (int )BaseExample_appendSVindex(arg0,arg1);    resultobj = PyInt_FromLong((long)result);    return resultobj;}int  BaseExample_getDimension(BaseExample *self) {    {        return self->d;     }}static PyObject *_wrap_BaseExample_getDimension(PyObject *self, PyObject *args) {    PyObject *resultobj;    BaseExample *arg0 ;    PyObject * argo0 =0 ;    int result ;        if(!PyArg_ParseTuple(args,"O:BaseExample_getDimension",&argo0)) return NULL;    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_BaseExample,1)) == -1) return NULL;    result = (int )BaseExample_getDimension(arg0);    resultobj = PyInt_FromLong((long)result);    return resultobj;}int  BaseExample_getNonzeroDimension(BaseExample *self) {    {        return self->pack_d;     }}static PyObject *_wrap_BaseExample_getNonzeroDimension(PyObject *self, PyObject *args) {    PyObject *resultobj;    BaseExample *arg0 ;    PyObject * argo0 =0 ;    int result ;        if(!PyArg_ParseTuple(args,"O:BaseExample_getNonzeroDimension",&argo0)) return NULL;    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_BaseExample,1)) == -1) return NULL;    result = (int )BaseExample_getNonzeroDimension(arg0);    resultobj = PyInt_FromLong((long)result);    return resultobj;}double  BaseExample_getY(BaseExample *self,int i) {    {        if (i >= 0 && i < self->l) return self->y[i];        fprintf(stderr, "BaseExample::getY() -- index is out of range\n");        return 0.0;    }}static PyObject *_wrap_BaseExample_getY(PyObject *self, PyObject *args) {    PyObject *resultobj;    BaseExample *arg0 ;    int arg1 ;    PyObject * argo0 =0 ;    double result ;        if(!PyArg_ParseTuple(args,"Oi:BaseExample_getY",&argo0,&arg1)) return NULL;    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_BaseExample,1)) == -1) return NULL;    result = (double )BaseExample_getY(arg0,arg1);    resultobj = PyFloat_FromDouble(result);    return resultobj;}char const * BaseExample_getX(BaseExample *self,int i) {    {        const char *s = self->get(i);        if (!s) return 0;                int len = strlen (s);        int i;        for (i = 0; i < len;) {            while (isspace (s[i])) i++;            while (i < len && !isspace (s[i])) i++;            while (i < len && isspace (s[i]))  i++;            break;        }                return (const char*)(s + i);    }}static PyObject *_wrap_BaseExample_getX(PyObject *self, PyObject *args) {    PyObject *resultobj;    BaseExample *arg0 ;    int arg1 ;    PyObject * argo0 =0 ;    char *result ;        if(!PyArg_ParseTuple(args,"Oi:BaseExample_getX",&argo0,&arg1)) return NULL;    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_BaseExample,1)) == -1) return NULL;    result = (char *)BaseExample_getX(arg0,arg1);    resultobj = PyString_FromString(result);    return resultobj;}double  BaseExample_getAlpha(BaseExample *self,int i) {    {        if (self->alpha && i >= 0 && i < self->svindex_size) return self->alpha[i];        fprintf(stderr, "BaseExample::getAlpha() -- \nalpha is not available or index is out of range\n");        return 0.0;    }}static PyObject *_wrap_BaseExample_getAlpha(PyObject *self, PyObject *args) {    PyObject *resultobj;    BaseExample *arg0 ;    int arg1 ;    PyObject * argo0 =0 ;    double result ;        if(!PyArg_ParseTuple(args,"Oi:BaseExample_getAlpha",&argo0,&arg1)) return NULL;    if ((SWIG_ConvertPtr(argo0,(void **) &arg0,SWIGTYPE_p_BaseExample,1)) == -1) return NULL;    result = (double )BaseExample_getAlpha(arg0,arg1);    resultobj = PyFloat_FromDouble(result);    return resultobj;}double  BaseExample_getGradient(BaseExample *self,int i) {    {        if (self->G && i >= 0 && i < self->svindex_size) return self->G[i];        fprintf(stderr, "BaseExample::getGradient() -- \ngradient is not available or index is out of range\n");        return 0.0;    }}static PyObject *_wrap_BaseExample_getGradient(PyObject *self, PyObject *args) {    PyObject *resultobj;    BaseExample *arg0 ;    int arg1 ;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?