📄 tinysvm_wrap.cc
字号:
Get_BaseExample(self, arg0); arg1 = STR2CSTR(varg1); result = (int )BaseExample_appendSVindex(arg0,arg1); vresult = INT2NUM(result); return vresult;}int BaseExample_getDimension(BaseExample *self) { { return self->d; }}static VALUE_wrap_BaseExample_getDimension(VALUE self) { BaseExample *arg0 ; int result ; VALUE vresult = Qnil; Get_BaseExample(self, arg0); result = (int )BaseExample_getDimension(arg0); vresult = INT2NUM(result); return vresult;}int BaseExample_getNonzeroDimension(BaseExample *self) { { return self->pack_d; }}static VALUE_wrap_BaseExample_getNonzeroDimension(VALUE self) { BaseExample *arg0 ; int result ; VALUE vresult = Qnil; Get_BaseExample(self, arg0); result = (int )BaseExample_getNonzeroDimension(arg0); vresult = INT2NUM(result); return vresult;}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 VALUE_wrap_BaseExample_getY(VALUE self, VALUE varg1) { BaseExample *arg0 ; int arg1 ; double result ; VALUE vresult = Qnil; Get_BaseExample(self, arg0); arg1 = NUM2INT(varg1); result = (double )BaseExample_getY(arg0,arg1); vresult = rb_float_new(result); return vresult;}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 VALUE_wrap_BaseExample_getX(VALUE self, VALUE varg1) { BaseExample *arg0 ; int arg1 ; char *result ; VALUE vresult = Qnil; Get_BaseExample(self, arg0); arg1 = NUM2INT(varg1); result = (char *)BaseExample_getX(arg0,arg1); vresult = rb_str_new2(result); return vresult;}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 VALUE_wrap_BaseExample_getAlpha(VALUE self, VALUE varg1) { BaseExample *arg0 ; int arg1 ; double result ; VALUE vresult = Qnil; Get_BaseExample(self, arg0); arg1 = NUM2INT(varg1); result = (double )BaseExample_getAlpha(arg0,arg1); vresult = rb_float_new(result); return vresult;}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 VALUE_wrap_BaseExample_getGradient(VALUE self, VALUE varg1) { BaseExample *arg0 ; int arg1 ; double result ; VALUE vresult = Qnil; Get_BaseExample(self, arg0); arg1 = NUM2INT(varg1); result = (double )BaseExample_getGradient(arg0,arg1); vresult = rb_float_new(result); return vresult;}double BaseExample_getG(BaseExample *self,int i) { { if (self->G && i >= 0 && i < self->svindex_size) return self->G[i]; fprintf(stderr, "BaseExample::getG() -- index is out of range\n"); return 0.0; }}static VALUE_wrap_BaseExample_getG(VALUE self, VALUE varg1) { BaseExample *arg0 ; int arg1 ; double result ; VALUE vresult = Qnil; Get_BaseExample(self, arg0); arg1 = NUM2INT(varg1); result = (double )BaseExample_getG(arg0,arg1); vresult = rb_float_new(result); return vresult;}static VALUE_wrap_Model_read(int argc, VALUE *argv, VALUE self) { VALUE varg1 ; VALUE varg2 ; VALUE varg3 ; Model *arg0 ; char *arg1 ; char *arg2 = "r" ; int arg3 = 0 ; int result ; VALUE vresult = Qnil; rb_scan_args(argc, argv, "12", &varg1, &varg2, &varg3); Get_Model(self, arg0); arg1 = STR2CSTR(varg1); if (argc > 1) { arg2 = STR2CSTR(varg2); } if (argc > 2) { arg3 = NUM2INT(varg3); } result = (int )arg0->read((char const *)arg1,(char const *)arg2,arg3); vresult = INT2NUM(result); return vresult;}static VALUE_wrap_Model_write(int argc, VALUE *argv, VALUE self) { VALUE varg1 ; VALUE varg2 ; VALUE varg3 ; Model *arg0 ; char *arg1 ; char *arg2 = "w" ; int arg3 = 0 ; int result ; VALUE vresult = Qnil; rb_scan_args(argc, argv, "12", &varg1, &varg2, &varg3); Get_Model(self, arg0); arg1 = STR2CSTR(varg1); if (argc > 1) { arg2 = STR2CSTR(varg2); } if (argc > 2) { arg3 = NUM2INT(varg3); } result = (int )arg0->write((char const *)arg1,(char const *)arg2,arg3); vresult = INT2NUM(result); return vresult;}static VALUE_wrap_Model_clear(VALUE self) { Model *arg0 ; int result ; VALUE vresult = Qnil; Get_Model(self, arg0); result = (int )arg0->clear(); vresult = INT2NUM(result); return vresult;}static VALUE_wrap_Model_classify(VALUE self, VALUE varg1) { Model *arg0 ; char *arg1 ; double result ; VALUE vresult = Qnil; Get_Model(self, arg0); arg1 = STR2CSTR(varg1); result = (double )arg0->classify((char const *)arg1); vresult = rb_float_new(result); return vresult;}static VALUE_wrap_Model_estimateMargin(VALUE self) { Model *arg0 ; double result ; VALUE vresult = Qnil; Get_Model(self, arg0); result = (double )arg0->estimateMargin(); vresult = rb_float_new(result); return vresult;}static VALUE_wrap_Model_estimateSphere(VALUE self) { Model *arg0 ; double result ; VALUE vresult = Qnil; Get_Model(self, arg0); result = (double )arg0->estimateSphere(); vresult = rb_float_new(result); return vresult;}static VALUE_wrap_Model_estimateVC(VALUE self) { Model *arg0 ; double result ; VALUE vresult = Qnil; Get_Model(self, arg0); result = (double )arg0->estimateVC(); vresult = rb_float_new(result); return vresult;}static VALUE_wrap_Model_estimateXA(int argc, VALUE *argv, VALUE self) { VALUE varg1 ; Model *arg0 ; double arg1 = 2.0 ; double result ; VALUE vresult = Qnil; rb_scan_args(argc, argv, "01", &varg1); Get_Model(self, arg0); if (argc > 0) { arg1 = NUM2DBL(varg1); } result = (double )arg0->estimateXA(arg1); vresult = rb_float_new(result); return vresult;}static VALUE_wrap_Model_compress(VALUE self) { Model *arg0 ; int result ; VALUE vresult = Qnil; Get_Model(self, arg0); result = (int )arg0->compress(); vresult = INT2NUM(result); return vresult;}static VALUE_wrap_Model_getSVnum(VALUE self) { Model *arg0 ; int result ; VALUE vresult = Qnil; Get_Model(self, arg0); result = (int )arg0->getSVnum(); vresult = INT2NUM(result); return vresult;}static VALUE_wrap_Model_getBSVnum(VALUE self) { Model *arg0 ; int result ; VALUE vresult = Qnil; Get_Model(self, arg0); result = (int )arg0->getBSVnum(); vresult = INT2NUM(result); return vresult;}static VALUE_wrap_Model_getTrainingDataSize(VALUE self) { Model *arg0 ; int result ; VALUE vresult = Qnil; Get_Model(self, arg0); result = (int )arg0->getTrainingDataSize(); vresult = INT2NUM(result); return vresult;}static VALUE_wrap_Model_getLoss(VALUE self) { Model *arg0 ; double result ; VALUE vresult = Qnil; Get_Model(self, arg0); result = (double )arg0->getLoss(); vresult = rb_float_new(result); return vresult;}static VALUE_wrap_new_Model(VALUE self) { Model *result ; VALUE vresult = Qnil; result = (Model *)new Model(); vresult = Wrap_Model(self, result); return vresult;}static voidfree_Model(Model *arg0) { delete arg0;}static VALUE_wrap_Example_read(int argc, VALUE *argv, VALUE self) { VALUE varg1 ; VALUE varg2 ; VALUE varg3 ; Example *arg0 ; char *arg1 ; char *arg2 = "r" ; int arg3 = 0 ; int result ; VALUE vresult = Qnil; rb_scan_args(argc, argv, "12", &varg1, &varg2, &varg3); Get_Example(self, arg0); arg1 = STR2CSTR(varg1); if (argc > 1) { arg2 = STR2CSTR(varg2); } if (argc > 2) { arg3 = NUM2INT(varg3); } result = (int )arg0->read((char const *)arg1,(char const *)arg2,arg3); vresult = INT2NUM(result); return vresult;}static VALUE_wrap_Example_write(int argc, VALUE *argv, VALUE self) { VALUE varg1 ; VALUE varg2 ; VALUE varg3 ; Example *arg0 ; char *arg1 ; char *arg2 = "w" ; int arg3 = 0 ; int result ; VALUE vresult = Qnil; rb_scan_args(argc, argv, "12", &varg1, &varg2, &varg3); Get_Example(self, arg0); arg1 = STR2CSTR(varg1); if (argc > 1) { arg2 = STR2CSTR(varg2); } if (argc > 2) { arg3 = NUM2INT(varg3); } result = (int )arg0->write((char const *)arg1,(char const *)arg2,arg3); vresult = INT2NUM(result); return vresult;}static VALUE_wrap_Example_rebuildSVindex(VALUE self, VALUE varg1) { Example *arg0 ; Model *arg1 ; int result ; VALUE vresult = Qnil; Get_Example(self, arg0); Get_Model(varg1, arg1); result = (int )arg0->rebuildSVindex(arg1); vresult = INT2NUM(result); return vresult;}static VALUE_wrap_Example_learn(int argc, VALUE *argv, VALUE self) { VALUE varg1 ; Example *arg0 ; char *arg1 = 0 ; Model *result ; VALUE vresult = Qnil; rb_scan_args(argc, argv, "01", &varg1); Get_Example(self, arg0); if (argc > 0) { arg1 = STR2CSTR(varg1); } result = (Model *)arg0->learn((char const *)arg1); vresult = Wrap_Model(cModel, result); return vresult;}static VALUE_wrap_new_Example(VALUE self) { Example *result ; VALUE vresult = Qnil; result = (Example *)new Example(); vresult = Wrap_Example(self, result); return vresult;}static voidfree_Example(Example *arg0) { delete arg0;}/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (BEGIN) -------- */static swig_type_info *swig_types_initial[] = {0};/* -------- TYPE CONVERSION AND EQUIVALENCE RULES (END) -------- */#ifdef __cplusplusextern "C"#endifvoid Init_TinySVM(void) { int i; mTinySVM = rb_define_module("TinySVM"); _mSWIG = rb_define_module_under(mTinySVM, "SWIG"); for (i = 0; swig_types_initial[i]; i++) { swig_types[i] = SWIG_TypeRegister(swig_types_initial[i]); SWIG_define_class(swig_types[i]); } cBaseExample = rb_define_class_under(mTinySVM, "BaseExample", rb_cObject); rb_undef_method(CLASS_OF(cBaseExample), "new"); rb_define_method(cBaseExample, "add", VALUEFUNC(_wrap_BaseExample_add), 1); rb_define_method(cBaseExample, "set", VALUEFUNC(_wrap_BaseExample_set), 2); rb_define_method(cBaseExample, "get", VALUEFUNC(_wrap_BaseExample_get), 1); rb_define_method(cBaseExample, "remove", VALUEFUNC(_wrap_BaseExample_remove), 1); rb_define_method(cBaseExample, "clear", VALUEFUNC(_wrap_BaseExample_clear), 0); rb_define_method(cBaseExample, "size", VALUEFUNC(_wrap_BaseExample_size), 0); rb_define_method(cBaseExample, "read", VALUEFUNC(_wrap_BaseExample_read), -1); rb_define_method(cBaseExample, "write", VALUEFUNC(_wrap_BaseExample_write), -1); rb_define_method(cBaseExample, "readSVindex", VALUEFUNC(_wrap_BaseExample_readSVindex), -1); rb_define_method(cBaseExample, "writeSVindex", VALUEFUNC(_wrap_BaseExample_writeSVindex), -1); rb_define_method(cBaseExample, "append", VALUEFUNC(_wrap_BaseExample_append), 1); rb_define_method(cBaseExample, "appendSVindex", VALUEFUNC(_wrap_BaseExample_appendSVindex), 1); rb_define_method(cBaseExample, "getDimension", VALUEFUNC(_wrap_BaseExample_getDimension), 0); rb_define_method(cBaseExample, "getNonzeroDimension", VALUEFUNC(_wrap_BaseExample_getNonzeroDimension), 0); rb_define_method(cBaseExample, "getY", VALUEFUNC(_wrap_BaseExample_getY), 1); rb_define_method(cBaseExample, "getX", VALUEFUNC(_wrap_BaseExample_getX), 1); rb_define_method(cBaseExample, "getAlpha", VALUEFUNC(_wrap_BaseExample_getAlpha), 1); rb_define_method(cBaseExample, "getGradient", VALUEFUNC(_wrap_BaseExample_getGradient), 1); rb_define_method(cBaseExample, "getG", VALUEFUNC(_wrap_BaseExample_getG), 1); cModel = rb_define_class_under(mTinySVM, "Model", cBaseExample); rb_define_singleton_method(cModel, "new", VALUEFUNC(_wrap_new_Model), 0); rb_define_method(cModel, "read", VALUEFUNC(_wrap_Model_read), -1); rb_define_method(cModel, "write", VALUEFUNC(_wrap_Model_write), -1); rb_define_method(cModel, "clear", VALUEFUNC(_wrap_Model_clear), 0); rb_define_method(cModel, "classify", VALUEFUNC(_wrap_Model_classify), 1); rb_define_method(cModel, "estimateMargin", VALUEFUNC(_wrap_Model_estimateMargin), 0); rb_define_method(cModel, "estimateSphere", VALUEFUNC(_wrap_Model_estimateSphere), 0); rb_define_method(cModel, "estimateVC", VALUEFUNC(_wrap_Model_estimateVC), 0); rb_define_method(cModel, "estimateXA", VALUEFUNC(_wrap_Model_estimateXA), -1); rb_define_method(cModel, "compress", VALUEFUNC(_wrap_Model_compress), 0); rb_define_method(cModel, "getSVnum", VALUEFUNC(_wrap_Model_getSVnum), 0); rb_define_method(cModel, "getBSVnum", VALUEFUNC(_wrap_Model_getBSVnum), 0); rb_define_method(cModel, "getTrainingDataSize", VALUEFUNC(_wrap_Model_getTrainingDataSize), 0); rb_define_method(cModel, "getLoss", VALUEFUNC(_wrap_Model_getLoss), 0); cExample = rb_define_class_under(mTinySVM, "Example", cBaseExample); rb_define_singleton_method(cExample, "new", VALUEFUNC(_wrap_new_Example), 0); rb_define_method(cExample, "read", VALUEFUNC(_wrap_Example_read), -1); rb_define_method(cExample, "write", VALUEFUNC(_wrap_Example_write), -1); rb_define_method(cExample, "rebuildSVindex", VALUEFUNC(_wrap_Example_rebuildSVindex), 1); rb_define_method(cExample, "learn", VALUEFUNC(_wrap_Example_learn), -1);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -