Generated by Cython 0.15.1 on Tue Jan 31 14:40:26 2012
Raw output: svm.cpp
1: import numpy as np
/* "vision/svm.pyx":1 * import numpy as np #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* cimport numpy as np * */ __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__numpy), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (PyObject_SetAttr(__pyx_m, __pyx_n_s__np, __pyx_t_1)<
0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "vision/svm.pyx":1 * import numpy as np #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* cimport numpy as np * */ __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); if (PyObject_SetAttr(__pyx_m, __pyx_n_s____test__, ((PyObject *)__pyx_t_1))<
0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 1; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
2: cimport numpy as np
3:
4: import logging
/* "vision/svm.pyx":4 * cimport numpy as np * * import logging #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* logger = logging.getLogger("vision.svm") * */ __pyx_t_1 = __Pyx_Import(((PyObject *)__pyx_n_s__logging), 0, -1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (PyObject_SetAttr(__pyx_m, __pyx_n_s__logging, __pyx_t_1)<
0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 4; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
5: logger = logging.getLogger("vision.svm")
/* "vision/svm.pyx":5 * * import logging * logger = logging.getLogger("vision.svm") #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* * cdef extern from *: */ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__logging); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__getLogger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_37), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; if (PyObject_SetAttr(__pyx_m, __pyx_n_s__logger, __pyx_t_1)<
0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
6:
7: cdef extern from *:
8: ctypedef char* const_char_ptr "const char*"
9:
10: cdef extern from "stdlib.h":
11: ctypedef unsigned long size_t
12: void free(void *ptr)
13: void *malloc(size_t size)
14:
15: cdef extern from "liblinear/linear.h":
16: cdef struct feature_node:
17: int index
18: double value
19:
20: cdef struct problem:
21: int l # number of training data
22: int n # number of features (incl. bias)
23: int *y # array of target values
24: feature_node **x # array of feature_nodes
25: double bias
26:
27: cdef struct parameter:
28: int solver_type
29:
30: # these are for training only
31: double eps #stopping criteria
32: double C
33: int nr_weight
34: int *weight_label
35: double* weight
36:
37: cdef struct model:
38: parameter param
39: int nr_class # number of classes
40: int nr_feature
41: double *w
42: int *label # label of each class (label[n])
43: double bias
44:
45: char *check_parameter(problem *prob, parameter *param) nogil
46: model *liblinear_train "train" (problem *prob, parameter *param) nogil
47:
48: cdef enum solver_type:
49: L2R_LR,
50: L2R_L2LOSS_SVC_DUAL,
51: L2R_L2LOSS_SVC,
52: L2R_L1LOSS_SVC_DUAL,
53: MCSVM_CS,
54: L1R_L2LOSS_SVC,
55: L1R_LR
56:
57: MACH_L1R_L2LOSS_SVC = 5
/* "vision/svm.pyx":57 * L1R_LR * * MACH_L1R_L2LOSS_SVC = 5 #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* MACH_L1R_LR = 6 * MACH_L2R_L1LOSS_SVC_DUAL = 3 */ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__MACH_L1R_L2LOSS_SVC, __pyx_int_5)<
0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 57; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
58: MACH_L1R_LR = 6
/* "vision/svm.pyx":58 * * MACH_L1R_L2LOSS_SVC = 5 * MACH_L1R_LR = 6 #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* MACH_L2R_L1LOSS_SVC_DUAL = 3 * MACH_L2R_L2LOSS_SVC = 2 */ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__MACH_L1R_LR, __pyx_int_6)<
0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 58; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
59: MACH_L2R_L1LOSS_SVC_DUAL = 3
/* "vision/svm.pyx":59 * MACH_L1R_L2LOSS_SVC = 5 * MACH_L1R_LR = 6 * MACH_L2R_L1LOSS_SVC_DUAL = 3 #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* MACH_L2R_L2LOSS_SVC = 2 * MACH_L2R_L2LOSS_SVC_DUAL = 1 */ if (PyObject_SetAttr(__pyx_m, __pyx_n_s_38, __pyx_int_3)<
0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
60: MACH_L2R_L2LOSS_SVC = 2
/* "vision/svm.pyx":60 * MACH_L1R_LR = 6 * MACH_L2R_L1LOSS_SVC_DUAL = 3 * MACH_L2R_L2LOSS_SVC = 2 #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* MACH_L2R_L2LOSS_SVC_DUAL = 1 * MACH_L2R_LR = 0 */ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__MACH_L2R_L2LOSS_SVC, __pyx_int_2)<
0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 60; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
61: MACH_L2R_L2LOSS_SVC_DUAL = 1
/* "vision/svm.pyx":61 * MACH_L2R_L1LOSS_SVC_DUAL = 3 * MACH_L2R_L2LOSS_SVC = 2 * MACH_L2R_L2LOSS_SVC_DUAL = 1 #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* MACH_L2R_LR = 0 * MACH_MCSVM_CS = 4 */ if (PyObject_SetAttr(__pyx_m, __pyx_n_s_39, __pyx_int_1)<
0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
62: MACH_L2R_LR = 0
/* "vision/svm.pyx":62 * MACH_L2R_L2LOSS_SVC = 2 * MACH_L2R_L2LOSS_SVC_DUAL = 1 * MACH_L2R_LR = 0 #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* MACH_MCSVM_CS = 4 * */ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__MACH_L2R_LR, __pyx_int_0)<
0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 62; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
63: MACH_MCSVM_CS = 4
/* "vision/svm.pyx":63 * MACH_L2R_L2LOSS_SVC_DUAL = 1 * MACH_L2R_LR = 0 * MACH_MCSVM_CS = 4 #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* * class Model(object): */ if (PyObject_SetAttr(__pyx_m, __pyx_n_s__MACH_MCSVM_CS, __pyx_int_4)<
0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
64:
65: class Model(object):
/* "vision/svm.pyx":65 * MACH_MCSVM_CS = 4 * * class Model(object): #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* """ * A SVM-trained model that stores the weights and bias. */ __pyx_t_1 = PyDict_New(); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); /* "vision/svm.pyx":65 * MACH_MCSVM_CS = 4 * * class Model(object): #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* """ * A SVM-trained model that stores the weights and bias. */ __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_INCREF(__pyx_builtin_object); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_builtin_object); __Pyx_GIVEREF(__pyx_builtin_object); if (PyDict_SetItemString(((PyObject *)__pyx_t_1), "__doc__", ((PyObject *)__pyx_kp_s_40))<
0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_3 = __Pyx_CreateClass(((PyObject *)__pyx_t_2), ((PyObject *)__pyx_t_1), __pyx_n_s__Model, __pyx_kp_s_36); if (unlikely(!__pyx_t_3)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_3); __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; if (PyObject_SetAttr(__pyx_m, __pyx_n_s__Model, __pyx_t_3)<
0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 65; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0;
66: """
67: A SVM-trained model that stores the weights and bias.
68: """
69: def __init__(self, weights, bias):
/* "vision/svm.pyx":69 * A SVM-trained model that stores the weights and bias. * """ * def __init__(self, weights, bias): #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* self.weights = weights * self.bias = bias */ static PyObject *__pyx_pf_6vision_3svm_5Model___init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static char __pyx_doc_6vision_3svm_5Model___init__[] = "Model.__init__(self, weights, bias)"; static PyMethodDef __pyx_mdef_6vision_3svm_5Model___init__ = {__Pyx_NAMESTR("__init__"), (PyCFunction)__pyx_pf_6vision_3svm_5Model___init__, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6vision_3svm_5Model___init__)}; static PyObject *__pyx_pf_6vision_3svm_5Model___init__(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_self = 0; PyObject *__pyx_v_weights = 0; PyObject *__pyx_v_bias = 0; PyObject *__pyx_r = NULL; static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__self,&__pyx_n_s__weights,&__pyx_n_s__bias,0}; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("__init__"); __pyx_self = __pyx_self; { PyObject* values[3] = {0,0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; switch (PyTuple_GET_SIZE(__pyx_args)) { case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (PyTuple_GET_SIZE(__pyx_args)) { case 0: values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__self); if (likely(values[0])) kw_args--; else goto __pyx_L5_argtuple_error; case 1: values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__weights); if (likely(values[1])) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 2: values[2] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__bias); if (likely(values[2])) kw_args--; else { __Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, 2); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "__init__")<
0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else if (PyTuple_GET_SIZE(__pyx_args) != 3) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); values[2] = PyTuple_GET_ITEM(__pyx_args, 2); } __pyx_v_self = values[0]; __pyx_v_weights = values[1]; __pyx_v_bias = values[2]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("__init__", 1, 3, 3, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("vision.svm.Model.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; /* "vision/svm.pyx":69 * A SVM-trained model that stores the weights and bias. * """ * def __init__(self, weights, bias): #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* self.weights = weights * self.bias = bias */ __pyx_t_2 = __pyx_binding_PyCFunctionType_NewEx(&__pyx_mdef_6vision_3svm_5Model___init__, NULL, __pyx_kp_s_36); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); if (PyObject_SetItem(__pyx_t_1, __pyx_n_s____init__, __pyx_t_2)<
0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 69; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
70: self.weights = weights
/* "vision/svm.pyx":70 * """ * def __init__(self, weights, bias): * self.weights = weights #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* self.bias = bias * */ if (PyObject_SetAttr(__pyx_v_self, __pyx_n_s__weights, __pyx_v_weights)<
0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
71: self.bias = bias
/* "vision/svm.pyx":71 * def __init__(self, weights, bias): * self.weights = weights * self.bias = bias #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* * def sanity(pos, neg): */ if (PyObject_SetAttr(__pyx_v_self, __pyx_n_s__bias, __pyx_v_bias)<
0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 71; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_AddTraceback("vision.svm.Model.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
72:
73: def sanity(pos, neg):
/* "vision/svm.pyx":73 * self.bias = bias * * def sanity(pos, neg): #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* """ * Performs a sanity check on the positive and negative data. Useful for */ static PyObject *__pyx_pf_6vision_3svm_sanity(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static char __pyx_doc_6vision_3svm_sanity[] = "sanity(pos, neg)\n\n Performs a sanity check on the positive and negative data. Useful for\n debugging training, especially if liblinear is segfaulting.\n "; static PyMethodDef __pyx_mdef_6vision_3svm_sanity = {__Pyx_NAMESTR("sanity"), (PyCFunction)__pyx_pf_6vision_3svm_sanity, METH_VARARGS|METH_KEYWORDS, __Pyx_DOCSTR(__pyx_doc_6vision_3svm_sanity)}; static PyObject *__pyx_pf_6vision_3svm_sanity(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_pos = 0; PyObject *__pyx_v_neg = 0; PyObject *__pyx_v_size = NULL; PyObject *__pyx_v_x = NULL; PyObject *__pyx_v_point = NULL; PyObject *__pyx_r = NULL; static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__pos,&__pyx_n_s__neg,0}; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("sanity"); __pyx_self = __pyx_self; { PyObject* values[2] = {0,0}; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; switch (PyTuple_GET_SIZE(__pyx_args)) { case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (PyTuple_GET_SIZE(__pyx_args)) { case 0: values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__pos); if (likely(values[0])) kw_args--; else goto __pyx_L5_argtuple_error; case 1: values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__neg); if (likely(values[1])) kw_args--; else { __Pyx_RaiseArgtupleInvalid("sanity", 1, 2, 2, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "sanity")<
0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else if (PyTuple_GET_SIZE(__pyx_args) != 2) { goto __pyx_L5_argtuple_error; } else { values[0] = PyTuple_GET_ITEM(__pyx_args, 0); values[1] = PyTuple_GET_ITEM(__pyx_args, 1); } __pyx_v_pos = values[0]; __pyx_v_neg = values[1]; } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("sanity", 1, 2, 2, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("vision.svm.sanity", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:; /* "vision/svm.pyx":73 * self.bias = bias * * def sanity(pos, neg): #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* """ * Performs a sanity check on the positive and negative data. Useful for */ __pyx_t_1 = PyCFunction_NewEx(&__pyx_mdef_6vision_3svm_sanity, NULL, __pyx_kp_s_36); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (PyObject_SetAttr(__pyx_m, __pyx_n_s__sanity, __pyx_t_1)<
0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 73; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0;
74: """
75: Performs a sanity check on the positive and negative data. Useful for
76: debugging training, especially if liblinear is segfaulting.
77: """
78: logger.info("Performing sanity check on input data")
/* "vision/svm.pyx":78 * debugging training, especially if liblinear is segfaulting. * """ * logger.info("Performing sanity check on input data") #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* if len(pos) == 0: * raise ValueError("Need at least one positive data point") */ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__info); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "vision/svm.pyx":78 * debugging training, especially if liblinear is segfaulting. * """ * logger.info("Performing sanity check on input data") #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* if len(pos) == 0: * raise ValueError("Need at least one positive data point") */ __pyx_k_tuple_2 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 78; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_2)); __Pyx_INCREF(((PyObject *)__pyx_kp_s_1)); PyTuple_SET_ITEM(__pyx_k_tuple_2, 0, ((PyObject *)__pyx_kp_s_1)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_1)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_2));
79: if len(pos) == 0:
/* "vision/svm.pyx":79 * """ * logger.info("Performing sanity check on input data") * if len(pos) == 0: #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* raise ValueError("Need at least one positive data point") * if len(neg) == 0: */ __pyx_t_3 = PyObject_Length(__pyx_v_pos); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_4 = (__pyx_t_3 == 0); if (__pyx_t_4) {
80: raise ValueError("Need at least one positive data point")
/* "vision/svm.pyx":80 * logger.info("Performing sanity check on input data") * if len(pos) == 0: * raise ValueError("Need at least one positive data point") #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* if len(neg) == 0: * raise ValueError("Need at least one negative data point") */ __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_4), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L6; } __pyx_L6:; /* "vision/svm.pyx":80 * logger.info("Performing sanity check on input data") * if len(pos) == 0: * raise ValueError("Need at least one positive data point") #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* if len(neg) == 0: * raise ValueError("Need at least one negative data point") */ __pyx_k_tuple_4 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 80; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_4)); __Pyx_INCREF(((PyObject *)__pyx_kp_s_3)); PyTuple_SET_ITEM(__pyx_k_tuple_4, 0, ((PyObject *)__pyx_kp_s_3)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_3)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_4));
81: if len(neg) == 0:
/* "vision/svm.pyx":81 * if len(pos) == 0: * raise ValueError("Need at least one positive data point") * if len(neg) == 0: #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* raise ValueError("Need at least one negative data point") * size = pos[0].size */ __pyx_t_3 = PyObject_Length(__pyx_v_neg); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_4 = (__pyx_t_3 == 0); if (__pyx_t_4) {
82: raise ValueError("Need at least one negative data point")
/* "vision/svm.pyx":82 * raise ValueError("Need at least one positive data point") * if len(neg) == 0: * raise ValueError("Need at least one negative data point") #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* size = pos[0].size * for x, point in enumerate(pos + neg): */ __pyx_t_1 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_k_tuple_6), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L7; } __pyx_L7:; /* "vision/svm.pyx":82 * raise ValueError("Need at least one positive data point") * if len(neg) == 0: * raise ValueError("Need at least one negative data point") #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* size = pos[0].size * for x, point in enumerate(pos + neg): */ __pyx_k_tuple_6 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_6)); __Pyx_INCREF(((PyObject *)__pyx_kp_s_5)); PyTuple_SET_ITEM(__pyx_k_tuple_6, 0, ((PyObject *)__pyx_kp_s_5)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_5)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_6));
83: size = pos[0].size
/* "vision/svm.pyx":83 * if len(neg) == 0: * raise ValueError("Need at least one negative data point") * size = pos[0].size #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* for x, point in enumerate(pos + neg): * if point.ndim != 1: */ __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_pos, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__size); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_v_size = __pyx_t_2; __pyx_t_2 = 0;
84: for x, point in enumerate(pos + neg):
/* "vision/svm.pyx":84 * raise ValueError("Need at least one negative data point") * size = pos[0].size * for x, point in enumerate(pos + neg): #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* if point.ndim != 1: * raise ValueError("Each data point must be exactly " */ __Pyx_INCREF(__pyx_int_0); __pyx_t_2 = __pyx_int_0; __pyx_t_1 = PyNumber_Add(__pyx_v_pos, __pyx_v_neg); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); if (PyList_CheckExact(__pyx_t_1) || PyTuple_CheckExact(__pyx_t_1)) { __pyx_t_5 = __pyx_t_1; __Pyx_INCREF(__pyx_t_5); __pyx_t_3 = 0; __pyx_t_6 = NULL; } else { __pyx_t_3 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_t_1); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __pyx_t_6 = Py_TYPE(__pyx_t_5)->tp_iternext; } __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; for (;;) { if (PyList_CheckExact(__pyx_t_5)) { if (__pyx_t_3 >= PyList_GET_SIZE(__pyx_t_5)) break; __pyx_t_1 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; } else if (PyTuple_CheckExact(__pyx_t_5)) { if (__pyx_t_3 >= PyTuple_GET_SIZE(__pyx_t_5)) break; __pyx_t_1 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_3); __Pyx_INCREF(__pyx_t_1); __pyx_t_3++; } else { __pyx_t_1 = __pyx_t_6(__pyx_t_5); if (unlikely(!__pyx_t_1)) { if (PyErr_Occurred()) { if (likely(PyErr_ExceptionMatches(PyExc_StopIteration))) PyErr_Clear(); else {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } break; } __Pyx_GOTREF(__pyx_t_1); } __Pyx_XDECREF(__pyx_v_point); __pyx_v_point = __pyx_t_1; __pyx_t_1 = 0; __Pyx_INCREF(__pyx_t_2); __Pyx_XDECREF(__pyx_v_x); __pyx_v_x = __pyx_t_2; __pyx_t_1 = PyNumber_Add(__pyx_t_2, __pyx_int_1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 84; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = __pyx_t_1; __pyx_t_1 = 0;
85: if point.ndim != 1:
/* "vision/svm.pyx":85 * size = pos[0].size * for x, point in enumerate(pos + neg): * if point.ndim != 1: #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* raise ValueError("Each data point must be exactly " * "1 dimension [{0}]".format(x)) */ __pyx_t_1 = PyObject_GetAttr(__pyx_v_point, __pyx_n_s__ndim); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_7 = PyObject_RichCompare(__pyx_t_1, __pyx_int_1, Py_NE); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_7); if (unlikely(__pyx_t_4<
0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; if (__pyx_t_4) {
86: raise ValueError("Each data point must be exactly "
87: "1 dimension [{0}]".format(x))
/* "vision/svm.pyx":87 * if point.ndim != 1: * raise ValueError("Each data point must be exactly " * "1 dimension [{0}]".format(x)) #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* if point.size != size: * raise ValueError("Each data point must have the " */ __pyx_t_7 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_7), __pyx_n_s__format); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); __Pyx_INCREF(__pyx_v_x); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_x); __Pyx_GIVEREF(__pyx_v_x); __pyx_t_8 = PyObject_Call(__pyx_t_7, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 87; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_8); __Pyx_GIVEREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_8 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; __Pyx_Raise(__pyx_t_8, 0, 0, 0); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 86; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L10; } __pyx_L10:;
88: if point.size != size:
/* "vision/svm.pyx":88 * raise ValueError("Each data point must be exactly " * "1 dimension [{0}]".format(x)) * if point.size != size: #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* raise ValueError("Each data point must have the " * "same size [{0}]".format(x)) */ __pyx_t_8 = PyObject_GetAttr(__pyx_v_point, __pyx_n_s__size); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_8); __pyx_t_1 = PyObject_RichCompare(__pyx_t_8, __pyx_v_size, Py_NE); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; __pyx_t_4 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely(__pyx_t_4<
0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 88; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; if (__pyx_t_4) {
89: raise ValueError("Each data point must have the "
90: "same size [{0}]".format(x))
/* "vision/svm.pyx":90 * if point.size != size: * raise ValueError("Each data point must have the " * "same size [{0}]".format(x)) #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* * logger.debug("Sanity check passed") */ __pyx_t_1 = PyObject_GetAttr(((PyObject *)__pyx_kp_s_8), __pyx_n_s__format); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_8)); __Pyx_INCREF(__pyx_v_x); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_v_x); __Pyx_GIVEREF(__pyx_v_x); __pyx_t_7 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 90; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; __pyx_t_8 = PyTuple_New(1); if (unlikely(!__pyx_t_8)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_8)); PyTuple_SET_ITEM(__pyx_t_8, 0, __pyx_t_7); __Pyx_GIVEREF(__pyx_t_7); __pyx_t_7 = 0; __pyx_t_7 = PyObject_Call(__pyx_builtin_ValueError, ((PyObject *)__pyx_t_8), NULL); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_7); __Pyx_DECREF(((PyObject *)__pyx_t_8)); __pyx_t_8 = 0; __Pyx_Raise(__pyx_t_7, 0, 0, 0); __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 89; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L11; } __pyx_L11:; } __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0;
91:
92: logger.debug("Sanity check passed")
/* "vision/svm.pyx":92 * "same size [{0}]".format(x)) * * logger.debug("Sanity check passed") #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* * cpdef train(positives, negatives, float c = 1.0, */ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_5 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__debug); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = PyObject_Call(__pyx_t_5, ((PyObject *)__pyx_k_tuple_10), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_7); __Pyx_XDECREF(__pyx_t_8); __Pyx_AddTraceback("vision.svm.sanity", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XDECREF(__pyx_v_size); __Pyx_XDECREF(__pyx_v_x); __Pyx_XDECREF(__pyx_v_point); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "vision/svm.pyx":92 * "same size [{0}]".format(x)) * * logger.debug("Sanity check passed") #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* * cpdef train(positives, negatives, float c = 1.0, */ __pyx_k_tuple_10 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_10)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 92; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_10)); __Pyx_INCREF(((PyObject *)__pyx_kp_s_9)); PyTuple_SET_ITEM(__pyx_k_tuple_10, 0, ((PyObject *)__pyx_kp_s_9)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_9)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_10));
93:
94: cpdef train(positives, negatives, float c = 1.0,
/* "vision/svm.pyx":94 * logger.debug("Sanity check passed") * * cpdef train(positives, negatives, float c = 1.0, #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* mach = L2R_L2LOSS_SVC_DUAL, float eps = 0.01, * float posc = 1.0, float negc = 1.0): */ static PyObject *__pyx_pf_6vision_3svm_1train(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyObject *__pyx_f_6vision_3svm_train(PyObject *__pyx_v_positives, PyObject *__pyx_v_negatives, int __pyx_skip_dispatch, struct __pyx_opt_args_6vision_3svm_train *__pyx_optional_args) { float __pyx_v_c = ((float)1.0); PyObject *__pyx_v_mach = __pyx_k_11; /* "vision/svm.pyx":94 * logger.debug("Sanity check passed") * * cpdef train(positives, negatives, float c = 1.0, #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* mach = L2R_L2LOSS_SVC_DUAL, float eps = 0.01, * float posc = 1.0, float negc = 1.0): */ static PyObject *__pyx_pf_6vision_3svm_1train(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static char __pyx_doc_6vision_3svm_1train[] = "train(positives, negatives, float c=1.0, mach=L2R_L2LOSS_SVC_DUAL, float eps=0.01, float posc=1.0, float negc=1.0)\n\n Trains a linear SVM with positives and negatives.\n\n positive and negative should be lists of numpy vectors with the\n respective features. Sparse vectors are *not* supported at this time.\n\n c is the cost of a constraint violation.\n\n eps is the stopping criterion.\n\n Returns the learned the weights and bias through a Model object.\n "; static PyObject *__pyx_pf_6vision_3svm_1train(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_positives = 0; PyObject *__pyx_v_negatives = 0; float __pyx_v_c; PyObject *__pyx_v_mach = 0; float __pyx_v_eps; float __pyx_v_posc; float __pyx_v_negc; PyObject *__pyx_r = NULL; static PyObject **__pyx_pyargnames[] = {&__pyx_n_s__positives,&__pyx_n_s__negatives,&__pyx_n_s__c,&__pyx_n_s__mach,&__pyx_n_s__eps,&__pyx_n_s__posc,&__pyx_n_s__negc,0}; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("train"); __pyx_self = __pyx_self; { PyObject* values[7] = {0,0,0,0,0,0,0}; values[3] = __pyx_k_11; if (unlikely(__pyx_kwds)) { Py_ssize_t kw_args; switch (PyTuple_GET_SIZE(__pyx_args)) { case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); case 1: values[0] = PyTuple_GET_ITEM(__pyx_args, 0); case 0: break; default: goto __pyx_L5_argtuple_error; } kw_args = PyDict_Size(__pyx_kwds); switch (PyTuple_GET_SIZE(__pyx_args)) { case 0: values[0] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__positives); if (likely(values[0])) kw_args--; else goto __pyx_L5_argtuple_error; case 1: values[1] = PyDict_GetItem(__pyx_kwds, __pyx_n_s__negatives); if (likely(values[1])) kw_args--; else { __Pyx_RaiseArgtupleInvalid("train", 0, 2, 7, 1); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } case 2: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__c); if (value) { values[2] = value; kw_args--; } } case 3: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__mach); if (value) { values[3] = value; kw_args--; } } case 4: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__eps); if (value) { values[4] = value; kw_args--; } } case 5: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__posc); if (value) { values[5] = value; kw_args--; } } case 6: if (kw_args > 0) { PyObject* value = PyDict_GetItem(__pyx_kwds, __pyx_n_s__negc); if (value) { values[6] = value; kw_args--; } } } if (unlikely(kw_args > 0)) { if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_pyargnames, 0, values, PyTuple_GET_SIZE(__pyx_args), "train")<
0)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } } else { switch (PyTuple_GET_SIZE(__pyx_args)) { case 7: values[6] = PyTuple_GET_ITEM(__pyx_args, 6); case 6: values[5] = PyTuple_GET_ITEM(__pyx_args, 5); case 5: values[4] = PyTuple_GET_ITEM(__pyx_args, 4); case 4: values[3] = PyTuple_GET_ITEM(__pyx_args, 3); case 3: values[2] = PyTuple_GET_ITEM(__pyx_args, 2); case 2: values[1] = PyTuple_GET_ITEM(__pyx_args, 1); values[0] = PyTuple_GET_ITEM(__pyx_args, 0); break; default: goto __pyx_L5_argtuple_error; } } __pyx_v_positives = values[0]; __pyx_v_negatives = values[1]; if (values[2]) { __pyx_v_c = __pyx_PyFloat_AsDouble(values[2]); if (unlikely((__pyx_v_c == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } else { __pyx_v_c = ((float)1.0); } __pyx_v_mach = values[3]; if (values[4]) { __pyx_v_eps = __pyx_PyFloat_AsDouble(values[4]); if (unlikely((__pyx_v_eps == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } else { /* "vision/svm.pyx":94 * logger.debug("Sanity check passed") * * cpdef train(positives, negatives, float c = 1.0, #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* mach = L2R_L2LOSS_SVC_DUAL, float eps = 0.01, * float posc = 1.0, float negc = 1.0): */ __Pyx_XDECREF(__pyx_r); __pyx_t_2.__pyx_n = 5; __pyx_t_2.c = __pyx_v_c; __pyx_t_2.mach = __pyx_v_mach; __pyx_t_2.eps = __pyx_v_eps; __pyx_t_2.posc = __pyx_v_posc; __pyx_t_2.negc = __pyx_v_negc; __pyx_t_1 = __pyx_f_6vision_3svm_train(__pyx_v_positives, __pyx_v_negatives, 0, &__pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_r = __pyx_t_1; __pyx_t_1 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_AddTraceback("vision.svm.train", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
95: mach = L2R_L2LOSS_SVC_DUAL, float eps = 0.01,
/* "vision/svm.pyx":95 * * cpdef train(positives, negatives, float c = 1.0, * mach = L2R_L2LOSS_SVC_DUAL, float eps = 0.01, #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* float posc = 1.0, float negc = 1.0): * """ */ float __pyx_v_eps = ((float)0.01); /* "vision/svm.pyx":95 * * cpdef train(positives, negatives, float c = 1.0, * mach = L2R_L2LOSS_SVC_DUAL, float eps = 0.01, #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* float posc = 1.0, float negc = 1.0): * """ */ __pyx_v_eps = ((float)0.01); } if (values[5]) { __pyx_v_posc = __pyx_PyFloat_AsDouble(values[5]); if (unlikely((__pyx_v_posc == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } else { /* "vision/svm.pyx":95 * * cpdef train(positives, negatives, float c = 1.0, * mach = L2R_L2LOSS_SVC_DUAL, float eps = 0.01, #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* float posc = 1.0, float negc = 1.0): * """ */ __pyx_t_1 = PyInt_FromLong(L2R_L2LOSS_SVC_DUAL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_k_11 = __pyx_t_1; __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = 0;
96: float posc = 1.0, float negc = 1.0):
/* "vision/svm.pyx":96 * cpdef train(positives, negatives, float c = 1.0, * mach = L2R_L2LOSS_SVC_DUAL, float eps = 0.01, * float posc = 1.0, float negc = 1.0): #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* """ * Trains a linear SVM with positives and negatives. */ float __pyx_v_posc = ((float)1.0); float __pyx_v_negc = ((float)1.0); int __pyx_v_numpos; int __pyx_v_numneg; int __pyx_v_numall; int __pyx_v_numfeat; int __pyx_v_i; struct problem __pyx_v_prob; struct parameter __pyx_v_param; const char* __pyx_v_message; struct model *__pyx_v_mod; PyArrayObject *__pyx_v_weights = 0; double __pyx_v_bias; Py_buffer __pyx_bstruct_weights; Py_ssize_t __pyx_bstride_0_weights = 0; Py_ssize_t __pyx_bshape_0_weights = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("train"); if (__pyx_optional_args) { if (__pyx_optional_args->__pyx_n > 0) { __pyx_v_c = __pyx_optional_args->c; if (__pyx_optional_args->__pyx_n > 1) { __pyx_v_mach = __pyx_optional_args->mach; if (__pyx_optional_args->__pyx_n > 2) { __pyx_v_eps = __pyx_optional_args->eps; if (__pyx_optional_args->__pyx_n > 3) { __pyx_v_posc = __pyx_optional_args->posc; if (__pyx_optional_args->__pyx_n > 4) { __pyx_v_negc = __pyx_optional_args->negc; } } } } } } __pyx_bstruct_weights.buf = NULL; /* "vision/svm.pyx":96 * cpdef train(positives, negatives, float c = 1.0, * mach = L2R_L2LOSS_SVC_DUAL, float eps = 0.01, * float posc = 1.0, float negc = 1.0): #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* """ * Trains a linear SVM with positives and negatives. */ __pyx_v_posc = ((float)1.0); } if (values[6]) { __pyx_v_negc = __pyx_PyFloat_AsDouble(values[6]); if (unlikely((__pyx_v_negc == (float)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 96; __pyx_clineno = __LINE__; goto __pyx_L3_error;} } else { __pyx_v_negc = ((float)1.0); } } goto __pyx_L4_argument_unpacking_done; __pyx_L5_argtuple_error:; __Pyx_RaiseArgtupleInvalid("train", 0, 2, 7, PyTuple_GET_SIZE(__pyx_args)); {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; __pyx_clineno = __LINE__; goto __pyx_L3_error;} __pyx_L3_error:; __Pyx_AddTraceback("vision.svm.train", __pyx_clineno, __pyx_lineno, __pyx_filename); __Pyx_RefNannyFinishContext(); return NULL; __pyx_L4_argument_unpacking_done:;
97: """
98: Trains a linear SVM with positives and negatives.
99:
100: positive and negative should be lists of numpy vectors with the
101: respective features. Sparse vectors are *not* supported at this time.
102:
103: c is the cost of a constraint violation.
104:
105: eps is the stopping criterion.
106:
107: Returns the learned the weights and bias through a Model object.
108: """
109: logger.info("Constructing SVM problems and parameters")
/* "vision/svm.pyx":109 * Returns the learned the weights and bias through a Model object. * """ * logger.info("Constructing SVM problems and parameters") #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* * cdef int numpos = len(positives), numneg = len(negatives) */ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__info); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_13), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "vision/svm.pyx":109 * Returns the learned the weights and bias through a Model object. * """ * logger.info("Constructing SVM problems and parameters") #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* * cdef int numpos = len(positives), numneg = len(negatives) */ __pyx_k_tuple_13 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 109; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_13)); __Pyx_INCREF(((PyObject *)__pyx_kp_s_12)); PyTuple_SET_ITEM(__pyx_k_tuple_13, 0, ((PyObject *)__pyx_kp_s_12)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_12)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_13));
110:
111: cdef int numpos = len(positives), numneg = len(negatives)
/* "vision/svm.pyx":111 * logger.info("Constructing SVM problems and parameters") * * cdef int numpos = len(positives), numneg = len(negatives) #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* cdef int numall = numpos + numneg * cdef int numfeat = positives[0].size */ __pyx_t_3 = PyObject_Length(__pyx_v_positives); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_numpos = __pyx_t_3; __pyx_t_3 = PyObject_Length(__pyx_v_negatives); if (unlikely(__pyx_t_3 == -1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 111; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_numneg = __pyx_t_3;
112: cdef int numall = numpos + numneg
/* "vision/svm.pyx":112 * * cdef int numpos = len(positives), numneg = len(negatives) * cdef int numall = numpos + numneg #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* cdef int numfeat = positives[0].size * cdef int i # counter */ __pyx_v_numall = (__pyx_v_numpos + __pyx_v_numneg);
113: cdef int numfeat = positives[0].size
/* "vision/svm.pyx":113 * cdef int numpos = len(positives), numneg = len(negatives) * cdef int numall = numpos + numneg * cdef int numfeat = positives[0].size #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* cdef int i # counter * */ __pyx_t_1 = __Pyx_GetItemInt(__pyx_v_positives, 0, sizeof(long), PyInt_FromLong); if (!__pyx_t_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__size); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 113; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_numfeat = __pyx_t_4;
114: cdef int i # counter
115:
116: logger.debug("Constructing problem")
/* "vision/svm.pyx":116 * cdef int i # counter * * logger.debug("Constructing problem") #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* cdef problem prob * prob.l = numall */ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__debug); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_15), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "vision/svm.pyx":116 * cdef int i # counter * * logger.debug("Constructing problem") #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* cdef problem prob * prob.l = numall */ __pyx_k_tuple_15 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_15)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 116; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_15)); __Pyx_INCREF(((PyObject *)__pyx_kp_s_14)); PyTuple_SET_ITEM(__pyx_k_tuple_15, 0, ((PyObject *)__pyx_kp_s_14)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_14)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_15));
117: cdef problem prob
118: prob.l = numall
/* "vision/svm.pyx":118 * logger.debug("Constructing problem") * cdef problem prob * prob.l = numall #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* prob.n = numfeat + 1 * prob.y =<
int*> malloc(numall * sizeof(int)) */ __pyx_v_prob.l = __pyx_v_numall;
119: prob.n = numfeat + 1
/* "vision/svm.pyx":119 * cdef problem prob * prob.l = numall * prob.n = numfeat + 1 #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* prob.y =<
int*> malloc(numall * sizeof(int)) * for i from 0<
= i<
numpos: */ __pyx_v_prob.n = (__pyx_v_numfeat + 1);
120: prob.y = <int*> malloc(numall * sizeof(int))
/* "vision/svm.pyx":120 * prob.l = numall * prob.n = numfeat + 1 * prob.y =<
int*> malloc(numall * sizeof(int)) #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* for i from 0<
= i<
numpos: * prob.y[i] = 1 */ __pyx_v_prob.y = ((int *)malloc((__pyx_v_numall * (sizeof(int)))));
121: for i from 0 <= i < numpos:
/* "vision/svm.pyx":121 * prob.n = numfeat + 1 * prob.y =<
int*> malloc(numall * sizeof(int)) * for i from 0<
= i<
numpos: #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* prob.y[i] = 1 * for i from 0<
= i<
numneg: */ __pyx_t_4 = __pyx_v_numpos; for (__pyx_v_i = 0; __pyx_v_i<
__pyx_t_4; __pyx_v_i++) {
122: prob.y[i] = 1
/* "vision/svm.pyx":122 * prob.y =<
int*> malloc(numall * sizeof(int)) * for i from 0<
= i<
numpos: * prob.y[i] = 1 #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* for i from 0<
= i<
numneg: * prob.y[numpos + i] = -1 */ (__pyx_v_prob.y[__pyx_v_i]) = 1; }
123: for i from 0 <= i < numneg:
/* "vision/svm.pyx":123 * for i from 0<
= i<
numpos: * prob.y[i] = 1 * for i from 0<
= i<
numneg: #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* prob.y[numpos + i] = -1 * prob.bias = 1 */ __pyx_t_4 = __pyx_v_numneg; for (__pyx_v_i = 0; __pyx_v_i<
__pyx_t_4; __pyx_v_i++) {
124: prob.y[numpos + i] = -1
/* "vision/svm.pyx":124 * prob.y[i] = 1 * for i from 0<
= i<
numneg: * prob.y[numpos + i] = -1 #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* prob.bias = 1 * prob.x =<
feature_node**> malloc(numall * sizeof(feature_node*)) */ (__pyx_v_prob.y[(__pyx_v_numpos + __pyx_v_i)]) = -1; }
125: prob.bias = 1
/* "vision/svm.pyx":125 * for i from 0<
= i<
numneg: * prob.y[numpos + i] = -1 * prob.bias = 1 #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* prob.x =<
feature_node**> malloc(numall * sizeof(feature_node*)) * for i from 0<
= i<
numpos: */ __pyx_v_prob.bias = 1.0;
126: prob.x = <feature_node**> malloc(numall * sizeof(feature_node*))
/* "vision/svm.pyx":126 * prob.y[numpos + i] = -1 * prob.bias = 1 * prob.x =<
feature_node**> malloc(numall * sizeof(feature_node*)) #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* for i from 0<
= i<
numpos: * prob.x[i] = build_feature_node(positives[i]) */ __pyx_v_prob.x = ((struct feature_node **)malloc((__pyx_v_numall * (sizeof(struct feature_node *)))));
127: for i from 0 <= i < numpos:
/* "vision/svm.pyx":127 * prob.bias = 1 * prob.x =<
feature_node**> malloc(numall * sizeof(feature_node*)) * for i from 0<
= i<
numpos: #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* prob.x[i] = build_feature_node(positives[i]) * for i from 0<
= i<
numneg: */ __pyx_t_4 = __pyx_v_numpos; for (__pyx_v_i = 0; __pyx_v_i<
__pyx_t_4; __pyx_v_i++) {
128: prob.x[i] = build_feature_node(positives[i])
/* "vision/svm.pyx":128 * prob.x =<
feature_node**> malloc(numall * sizeof(feature_node*)) * for i from 0<
= i<
numpos: * prob.x[i] = build_feature_node(positives[i]) #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* for i from 0<
= i<
numneg: * prob.x[numpos + i] = build_feature_node(negatives[i]) */ __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_positives, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 128; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); (__pyx_v_prob.x[__pyx_v_i]) = __pyx_f_6vision_3svm_build_feature_node(__pyx_t_2); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; }
129: for i from 0 <= i < numneg:
/* "vision/svm.pyx":129 * for i from 0<
= i<
numpos: * prob.x[i] = build_feature_node(positives[i]) * for i from 0<
= i<
numneg: #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* prob.x[numpos + i] = build_feature_node(negatives[i]) * */ __pyx_t_4 = __pyx_v_numneg; for (__pyx_v_i = 0; __pyx_v_i<
__pyx_t_4; __pyx_v_i++) {
130: prob.x[numpos + i] = build_feature_node(negatives[i])
/* "vision/svm.pyx":130 * prob.x[i] = build_feature_node(positives[i]) * for i from 0<
= i<
numneg: * prob.x[numpos + i] = build_feature_node(negatives[i]) #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* * logger.debug("Constructing parameter") */ __pyx_t_2 = __Pyx_GetItemInt(__pyx_v_negatives, __pyx_v_i, sizeof(int), PyInt_FromLong); if (!__pyx_t_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 130; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); (__pyx_v_prob.x[(__pyx_v_numpos + __pyx_v_i)]) = __pyx_f_6vision_3svm_build_feature_node(__pyx_t_2); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; }
131:
132: logger.debug("Constructing parameter")
/* "vision/svm.pyx":132 * prob.x[numpos + i] = build_feature_node(negatives[i]) * * logger.debug("Constructing parameter") #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* cdef parameter param * param.solver_type = mach */ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__debug); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_17), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "vision/svm.pyx":132 * prob.x[numpos + i] = build_feature_node(negatives[i]) * * logger.debug("Constructing parameter") #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* cdef parameter param * param.solver_type = mach */ __pyx_k_tuple_17 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_17)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 132; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_17)); __Pyx_INCREF(((PyObject *)__pyx_kp_s_16)); PyTuple_SET_ITEM(__pyx_k_tuple_17, 0, ((PyObject *)__pyx_kp_s_16)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_16)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_17));
133: cdef parameter param
134: param.solver_type = mach
/* "vision/svm.pyx":134 * logger.debug("Constructing parameter") * cdef parameter param * param.solver_type = mach #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* param.eps = eps * param.C = c */ __pyx_t_4 = __Pyx_PyInt_AsInt(__pyx_v_mach); if (unlikely((__pyx_t_4 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 134; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_param.solver_type = __pyx_t_4;
135: param.eps = eps
/* "vision/svm.pyx":135 * cdef parameter param * param.solver_type = mach * param.eps = eps #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* param.C = c * param.nr_weight = 2 */ __pyx_v_param.eps = __pyx_v_eps;
136: param.C = c
/* "vision/svm.pyx":136 * param.solver_type = mach * param.eps = eps * param.C = c #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* param.nr_weight = 2 * param.weight =<
double*> malloc(param.nr_weight*sizeof(double)) */ __pyx_v_param.C = __pyx_v_c;
137: param.nr_weight = 2
/* "vision/svm.pyx":137 * param.eps = eps * param.C = c * param.nr_weight = 2 #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* param.weight =<
double*> malloc(param.nr_weight*sizeof(double)) * param.weight[0] = posc */ __pyx_v_param.nr_weight = 2;
138: param.weight = <double*> malloc(param.nr_weight*sizeof(double))
/* "vision/svm.pyx":138 * param.C = c * param.nr_weight = 2 * param.weight =<
double*> malloc(param.nr_weight*sizeof(double)) #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* param.weight[0] = posc * param.weight[1] = negc */ __pyx_v_param.weight = ((double *)malloc((__pyx_v_param.nr_weight * (sizeof(double)))));
139: param.weight[0] = posc
/* "vision/svm.pyx":139 * param.nr_weight = 2 * param.weight =<
double*> malloc(param.nr_weight*sizeof(double)) * param.weight[0] = posc #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* param.weight[1] = negc * param.weight_label =<
int*> malloc(param.nr_weight*sizeof(int)) */ (__pyx_v_param.weight[0]) = __pyx_v_posc;
140: param.weight[1] = negc
/* "vision/svm.pyx":140 * param.weight =<
double*> malloc(param.nr_weight*sizeof(double)) * param.weight[0] = posc * param.weight[1] = negc #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* param.weight_label =<
int*> malloc(param.nr_weight*sizeof(int)) * param.weight_label[0] = +1 */ (__pyx_v_param.weight[1]) = __pyx_v_negc;
141: param.weight_label = <int*> malloc(param.nr_weight*sizeof(int))
/* "vision/svm.pyx":141 * param.weight[0] = posc * param.weight[1] = negc * param.weight_label =<
int*> malloc(param.nr_weight*sizeof(int)) #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* param.weight_label[0] = +1 * param.weight_label[1] = -1 */ __pyx_v_param.weight_label = ((int *)malloc((__pyx_v_param.nr_weight * (sizeof(int)))));
142: param.weight_label[0] = +1
/* "vision/svm.pyx":142 * param.weight[1] = negc * param.weight_label =<
int*> malloc(param.nr_weight*sizeof(int)) * param.weight_label[0] = +1 #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* param.weight_label[1] = -1 * */ (__pyx_v_param.weight_label[0]) = 1;
143: param.weight_label[1] = -1
/* "vision/svm.pyx":143 * param.weight_label =<
int*> malloc(param.nr_weight*sizeof(int)) * param.weight_label[0] = +1 * param.weight_label[1] = -1 #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* * logger.debug("Checking parameters") */ (__pyx_v_param.weight_label[1]) = -1;
144:
145: logger.debug("Checking parameters")
/* "vision/svm.pyx":145 * param.weight_label[1] = -1 * * logger.debug("Checking parameters") #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* cdef const_char_ptr message =<
char*> check_parameter(&prob, ¶m) * if message: */ __pyx_t_2 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_1 = PyObject_GetAttr(__pyx_t_2, __pyx_n_s__debug); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_k_tuple_19), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; /* "vision/svm.pyx":145 * param.weight_label[1] = -1 * * logger.debug("Checking parameters") #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* cdef const_char_ptr message =<
char*> check_parameter(&prob, ¶m) * if message: */ __pyx_k_tuple_19 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_19)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 145; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_19)); __Pyx_INCREF(((PyObject *)__pyx_kp_s_18)); PyTuple_SET_ITEM(__pyx_k_tuple_19, 0, ((PyObject *)__pyx_kp_s_18)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_18)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_19));
146: cdef const_char_ptr message = <char*> check_parameter(&prob, ¶m)
/* "vision/svm.pyx":146 * * logger.debug("Checking parameters") * cdef const_char_ptr message =<
char*> check_parameter(&prob, ¶m) #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* if message: * raise RuntimeError("Error training SVM: " + str(message)) */ __pyx_v_message = ((char *)check_parameter((&__pyx_v_prob), (&__pyx_v_param)));
147: if message:
/* "vision/svm.pyx":147 * logger.debug("Checking parameters") * cdef const_char_ptr message =<
char*> check_parameter(&prob, ¶m) * if message: #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* raise RuntimeError("Error training SVM: " + str(message)) * */ __pyx_t_5 = (__pyx_v_message != 0); if (__pyx_t_5) {
148: raise RuntimeError("Error training SVM: " + str(message))
/* "vision/svm.pyx":148 * cdef const_char_ptr message =<
char*> check_parameter(&prob, ¶m) * if message: * raise RuntimeError("Error training SVM: " + str(message)) #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* * logger.info("Optimizing SVM with liblinear") */ __pyx_t_2 = PyBytes_FromString(__pyx_v_message); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_1)); PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)__pyx_t_2)); __Pyx_GIVEREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __pyx_t_2 = PyObject_Call(((PyObject *)((PyObject*)(&PyString_Type))), ((PyObject *)__pyx_t_1), NULL); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(((PyObject *)__pyx_t_1)); __pyx_t_1 = 0; __pyx_t_1 = PyNumber_Add(((PyObject *)__pyx_kp_s_20), __pyx_t_2); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyObject_Call(__pyx_builtin_RuntimeError, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __Pyx_Raise(__pyx_t_1, 0, 0, 0); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 148; __pyx_clineno = __LINE__; goto __pyx_L1_error;} goto __pyx_L11; } __pyx_L11:;
149:
150: logger.info("Optimizing SVM with liblinear")
/* "vision/svm.pyx":150 * raise RuntimeError("Error training SVM: " + str(message)) * * logger.info("Optimizing SVM with liblinear") #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* cdef model *mod = liblinear_train(&prob, ¶m) * cdef np.ndarray[np.double_t, ndim=1] weights = np.zeros(mod.nr_feature) */ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__info); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_k_tuple_22), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "vision/svm.pyx":150 * raise RuntimeError("Error training SVM: " + str(message)) * * logger.info("Optimizing SVM with liblinear") #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* cdef model *mod = liblinear_train(&prob, ¶m) * cdef np.ndarray[np.double_t, ndim=1] weights = np.zeros(mod.nr_feature) */ __pyx_k_tuple_22 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_22)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 150; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_22)); __Pyx_INCREF(((PyObject *)__pyx_kp_s_21)); PyTuple_SET_ITEM(__pyx_k_tuple_22, 0, ((PyObject *)__pyx_kp_s_21)); __Pyx_GIVEREF(((PyObject *)__pyx_kp_s_21)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_22));
151: cdef model *mod = liblinear_train(&prob, ¶m)
/* "vision/svm.pyx":151 * * logger.info("Optimizing SVM with liblinear") * cdef model *mod = liblinear_train(&prob, ¶m) #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* cdef np.ndarray[np.double_t, ndim=1] weights = np.zeros(mod.nr_feature) * for i from 0<
= i<
mod.nr_feature: */ __pyx_v_mod = train((&__pyx_v_prob), (&__pyx_v_param));
152: cdef np.ndarray[np.double_t, ndim=1] weights = np.zeros(mod.nr_feature)
/* "vision/svm.pyx":152 * logger.info("Optimizing SVM with liblinear") * cdef model *mod = liblinear_train(&prob, ¶m) * cdef np.ndarray[np.double_t, ndim=1] weights = np.zeros(mod.nr_feature) #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* for i from 0<
= i<
mod.nr_feature: * weights[i] = mod.w[i] */ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__np); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_2 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__zeros); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyInt_FromLong(__pyx_v_mod->nr_feature); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_6)); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_1); __Pyx_GIVEREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyObject_Call(__pyx_t_2, ((PyObject *)__pyx_t_6), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_6)); __pyx_t_6 = 0; if (!(likely(((__pyx_t_1) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_1, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_7 = ((PyArrayObject *)__pyx_t_1); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_weights, (PyObject*)__pyx_t_7, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES| PyBUF_WRITABLE, 1, 0, __pyx_stack) == -1)) { __pyx_v_weights = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_weights.buf = NULL; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 152; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else {__pyx_bstride_0_weights = __pyx_bstruct_weights.strides[0]; __pyx_bshape_0_weights = __pyx_bstruct_weights.shape[0]; } } __pyx_t_7 = 0; __pyx_v_weights = ((PyArrayObject *)__pyx_t_1); __pyx_t_1 = 0;
153: for i from 0 <= i < mod.nr_feature:
/* "vision/svm.pyx":153 * cdef model *mod = liblinear_train(&prob, ¶m) * cdef np.ndarray[np.double_t, ndim=1] weights = np.zeros(mod.nr_feature) * for i from 0<
= i<
mod.nr_feature: #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* weights[i] = mod.w[i] * cdef double bias = mod.w[mod.nr_feature] */ __pyx_t_4 = __pyx_v_mod->nr_feature; for (__pyx_v_i = 0; __pyx_v_i<
__pyx_t_4; __pyx_v_i++) {
154: weights[i] = mod.w[i]
/* "vision/svm.pyx":154 * cdef np.ndarray[np.double_t, ndim=1] weights = np.zeros(mod.nr_feature) * for i from 0<
= i<
mod.nr_feature: * weights[i] = mod.w[i] #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* cdef double bias = mod.w[mod.nr_feature] * */ __pyx_t_8 = __pyx_v_i; if (__pyx_t_8<
0) __pyx_t_8 += __pyx_bshape_0_weights; *__Pyx_BufPtrStrided1d(__pyx_t_5numpy_double_t *, __pyx_bstruct_weights.buf, __pyx_t_8, __pyx_bstride_0_weights) = (__pyx_v_mod->w[__pyx_v_i]); }
155: cdef double bias = mod.w[mod.nr_feature]
/* "vision/svm.pyx":155 * for i from 0<
= i<
mod.nr_feature: * weights[i] = mod.w[i] * cdef double bias = mod.w[mod.nr_feature] #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* * logger.debug("Cleanup") */ __pyx_v_bias = (__pyx_v_mod->w[__pyx_v_mod->nr_feature]);
156:
157: logger.debug("Cleanup")
/* "vision/svm.pyx":157 * cdef double bias = mod.w[mod.nr_feature] * * logger.debug("Cleanup") #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* free(param.weight) * free(param.weight_label) */ __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__logger); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_6 = PyObject_GetAttr(__pyx_t_1, __pyx_n_s__debug); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __pyx_t_1 = PyObject_Call(__pyx_t_6, ((PyObject *)__pyx_k_tuple_23), NULL); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; /* "vision/svm.pyx":157 * cdef double bias = mod.w[mod.nr_feature] * * logger.debug("Cleanup") #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* free(param.weight) * free(param.weight_label) */ __pyx_k_tuple_23 = PyTuple_New(1); if (unlikely(!__pyx_k_tuple_23)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 157; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_k_tuple_23)); __Pyx_INCREF(((PyObject *)__pyx_n_s__Cleanup)); PyTuple_SET_ITEM(__pyx_k_tuple_23, 0, ((PyObject *)__pyx_n_s__Cleanup)); __Pyx_GIVEREF(((PyObject *)__pyx_n_s__Cleanup)); __Pyx_GIVEREF(((PyObject *)__pyx_k_tuple_23));
158: free(param.weight)
/* "vision/svm.pyx":158 * * logger.debug("Cleanup") * free(param.weight) #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* free(param.weight_label) * free(prob.y) */ free(__pyx_v_param.weight);
159: free(param.weight_label)
/* "vision/svm.pyx":159 * logger.debug("Cleanup") * free(param.weight) * free(param.weight_label) #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* free(prob.y) * for i from 0<
= i<
numall: */ free(__pyx_v_param.weight_label);
160: free(prob.y)
/* "vision/svm.pyx":160 * free(param.weight) * free(param.weight_label) * free(prob.y) #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* for i from 0<
= i<
numall: * free(prob.x[i]) */ free(__pyx_v_prob.y);
161: for i from 0 <= i < numall:
/* "vision/svm.pyx":161 * free(param.weight_label) * free(prob.y) * for i from 0<
= i<
numall: #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* free(prob.x[i]) * free(prob.x) */ __pyx_t_4 = __pyx_v_numall; for (__pyx_v_i = 0; __pyx_v_i<
__pyx_t_4; __pyx_v_i++) {
162: free(prob.x[i])
/* "vision/svm.pyx":162 * free(prob.y) * for i from 0<
= i<
numall: * free(prob.x[i]) #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* free(prob.x) * */ free((__pyx_v_prob.x[__pyx_v_i])); }
163: free(prob.x)
/* "vision/svm.pyx":163 * for i from 0<
= i<
numall: * free(prob.x[i]) * free(prob.x) #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* * return Model(weights, bias) */ free(__pyx_v_prob.x);
164:
165: return Model(weights, bias)
/* "vision/svm.pyx":165 * free(prob.x) * * return Model(weights, bias) #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* * cdef inline feature_node *build_feature_node(vector): */ __Pyx_XDECREF(__pyx_r); __pyx_t_1 = __Pyx_GetName(__pyx_m, __pyx_n_s__Model); if (unlikely(!__pyx_t_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_1); __pyx_t_6 = PyFloat_FromDouble(__pyx_v_bias); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); __pyx_t_2 = PyTuple_New(2); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(((PyObject *)__pyx_t_2)); __Pyx_INCREF(((PyObject *)__pyx_v_weights)); PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)__pyx_v_weights)); __Pyx_GIVEREF(((PyObject *)__pyx_v_weights)); PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_t_6); __Pyx_GIVEREF(__pyx_t_6); __pyx_t_6 = 0; __pyx_t_6 = PyObject_Call(__pyx_t_1, ((PyObject *)__pyx_t_2), NULL); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 165; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_6); __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; __Pyx_DECREF(((PyObject *)__pyx_t_2)); __pyx_t_2 = 0; __pyx_r = __pyx_t_6; __pyx_t_6 = 0; goto __pyx_L0; __pyx_r = Py_None; __Pyx_INCREF(Py_None); goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_1); __Pyx_XDECREF(__pyx_t_2); __Pyx_XDECREF(__pyx_t_6); { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); __Pyx_SafeReleaseBuffer(&__pyx_bstruct_weights); __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} __Pyx_AddTraceback("vision.svm.train", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; goto __pyx_L2; __pyx_L0:; __Pyx_SafeReleaseBuffer(&__pyx_bstruct_weights); __pyx_L2:; __Pyx_XDECREF((PyObject *)__pyx_v_weights); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; }
166:
167: cdef inline feature_node *build_feature_node(vector):
/* "vision/svm.pyx":167 * return Model(weights, bias) * * cdef inline feature_node *build_feature_node(vector): #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* """ * Builds a feature node for a vector. Includes a bias term. */ static CYTHON_INLINE struct feature_node *__pyx_f_6vision_3svm_build_feature_node(PyObject *__pyx_v_vector) { PyArrayObject *__pyx_v_vectort = 0; int __pyx_v_i; int __pyx_v_n; struct feature_node *__pyx_v_nodes; Py_buffer __pyx_bstruct_vectort; Py_ssize_t __pyx_bstride_0_vectort = 0; Py_ssize_t __pyx_bshape_0_vectort = 0; struct feature_node *__pyx_r; __Pyx_RefNannyDeclarations __Pyx_RefNannySetupContext("build_feature_node"); __pyx_bstruct_vectort.buf = NULL;
168: """
169: Builds a feature node for a vector. Includes a bias term.
170: """
171: cdef np.ndarray[np.double_t, ndim=1] vectort = vector
/* "vision/svm.pyx":171 * Builds a feature node for a vector. Includes a bias term. * """ * cdef np.ndarray[np.double_t, ndim=1] vectort = vector #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* cdef int i, n = vector.size * cdef feature_node *nodes */ if (!(likely(((__pyx_v_vector) == Py_None) || likely(__Pyx_TypeTest(__pyx_v_vector, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_t_1 = ((PyArrayObject *)__pyx_v_vector); { __Pyx_BufFmt_StackElem __pyx_stack[1]; if (unlikely(__Pyx_GetBufferAndValidate(&__pyx_bstruct_vectort, (PyObject*)__pyx_t_1, &__Pyx_TypeInfo_nn___pyx_t_5numpy_double_t, PyBUF_FORMAT| PyBUF_STRIDES, 1, 0, __pyx_stack) == -1)) { __pyx_v_vectort = ((PyArrayObject *)Py_None); __Pyx_INCREF(Py_None); __pyx_bstruct_vectort.buf = NULL; {__pyx_filename = __pyx_f[0]; __pyx_lineno = 171; __pyx_clineno = __LINE__; goto __pyx_L1_error;} } else {__pyx_bstride_0_vectort = __pyx_bstruct_vectort.strides[0]; __pyx_bshape_0_vectort = __pyx_bstruct_vectort.shape[0]; } } __pyx_t_1 = 0; __Pyx_INCREF(__pyx_v_vector); __pyx_v_vectort = ((PyArrayObject *)__pyx_v_vector);
172: cdef int i, n = vector.size
/* "vision/svm.pyx":172 * """ * cdef np.ndarray[np.double_t, ndim=1] vectort = vector * cdef int i, n = vector.size #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* cdef feature_node *nodes * nodes =<
feature_node*> malloc((n+2)*sizeof(feature_node)) */ __pyx_t_2 = PyObject_GetAttr(__pyx_v_vector, __pyx_n_s__size); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); __pyx_t_3 = __Pyx_PyInt_AsInt(__pyx_t_2); if (unlikely((__pyx_t_3 == (int)-1) && PyErr_Occurred())) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 172; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_v_n = __pyx_t_3;
173: cdef feature_node *nodes
174: nodes = <feature_node*> malloc((n+2)*sizeof(feature_node))
/* "vision/svm.pyx":174 * cdef int i, n = vector.size * cdef feature_node *nodes * nodes =<
feature_node*> malloc((n+2)*sizeof(feature_node)) #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* * for i from 0<
= i<
n: */ __pyx_v_nodes = ((struct feature_node *)malloc(((__pyx_v_n + 2) * (sizeof(struct feature_node)))));
175:
176: for i from 0 <= i < n:
/* "vision/svm.pyx":176 * nodes =<
feature_node*> malloc((n+2)*sizeof(feature_node)) * * for i from 0<
= i<
n: #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* nodes[i].index = i + 1 * nodes[i].value = vectort[i] */ __pyx_t_3 = __pyx_v_n; for (__pyx_v_i = 0; __pyx_v_i<
__pyx_t_3; __pyx_v_i++) {
177: nodes[i].index = i + 1
/* "vision/svm.pyx":177 * * for i from 0<
= i<
n: * nodes[i].index = i + 1 #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* nodes[i].value = vectort[i] * nodes[n].index = n + 1 */ (__pyx_v_nodes[__pyx_v_i]).index = (__pyx_v_i + 1);
178: nodes[i].value = vectort[i]
/* "vision/svm.pyx":178 * for i from 0<
= i<
n: * nodes[i].index = i + 1 * nodes[i].value = vectort[i] #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* nodes[n].index = n + 1 * nodes[n].value = 1 */ __pyx_t_4 = __pyx_v_i; if (__pyx_t_4<
0) __pyx_t_4 += __pyx_bshape_0_vectort; (__pyx_v_nodes[__pyx_v_i]).value = (*__Pyx_BufPtrStrided1d(__pyx_t_5numpy_double_t *, __pyx_bstruct_vectort.buf, __pyx_t_4, __pyx_bstride_0_vectort)); }
179: nodes[n].index = n + 1
/* "vision/svm.pyx":179 * nodes[i].index = i + 1 * nodes[i].value = vectort[i] * nodes[n].index = n + 1 #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* nodes[n].value = 1 * nodes[n + 1].index = -1 */ (__pyx_v_nodes[__pyx_v_n]).index = (__pyx_v_n + 1);
180: nodes[n].value = 1
/* "vision/svm.pyx":180 * nodes[i].value = vectort[i] * nodes[n].index = n + 1 * nodes[n].value = 1 #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* nodes[n + 1].index = -1 * return nodes */ (__pyx_v_nodes[__pyx_v_n]).value = 1.0;
181: nodes[n + 1].index = -1
/* "vision/svm.pyx":181 * nodes[n].index = n + 1 * nodes[n].value = 1 * nodes[n + 1].index = -1 #<
<
<
<
<
<
<
<
<
<
<
<
<
<
* return nodes */ (__pyx_v_nodes[(__pyx_v_n + 1)]).index = -1;
182: return nodes
/* "vision/svm.pyx":182 * nodes[n].value = 1 * nodes[n + 1].index = -1 * return nodes #<
<
<
<
<
<
<
<
<
<
<
<
<
<
*/ __pyx_r = __pyx_v_nodes; goto __pyx_L0; __pyx_r = 0; goto __pyx_L0; __pyx_L1_error:; __Pyx_XDECREF(__pyx_t_2); { PyObject *__pyx_type, *__pyx_value, *__pyx_tb; __Pyx_ErrFetch(&__pyx_type, &__pyx_value, &__pyx_tb); __Pyx_SafeReleaseBuffer(&__pyx_bstruct_vectort); __Pyx_ErrRestore(__pyx_type, __pyx_value, __pyx_tb);} __Pyx_WriteUnraisable("vision.svm.build_feature_node", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = 0; goto __pyx_L2; __pyx_L0:; __Pyx_SafeReleaseBuffer(&__pyx_bstruct_vectort); __pyx_L2:; __Pyx_XDECREF((PyObject *)__pyx_v_vectort); __Pyx_RefNannyFinishContext(); return __pyx_r; }