| 91 | return ret, max_idx |
| 92 | |
| 93 | class svm_problem(Structure): |
| 94 | _names = ["l", "y", "x"] |
| 95 | _types = [c_int, POINTER(c_double), POINTER(POINTER(svm_node))] |
| 96 | _fields_ = genFields(_names, _types) |
| 97 | |
| 98 | def __init__(self, y, x, isKernel=None): |
| 99 | if len(y) != len(x): |
| 100 | raise ValueError("len(y) != len(x)") |
| 101 | self.l = l = len(y) |
| 102 | |
| 103 | max_idx = 0 |
| 104 | x_space = self.x_space = [] |
| 105 | for i, xi in enumerate(x): |
| 106 | tmp_xi, tmp_idx = gen_svm_nodearray(xi,isKernel=isKernel) |
| 107 | x_space += [tmp_xi] |
| 108 | max_idx = max(max_idx, tmp_idx) |
| 109 | self.n = max_idx |
| 110 | |
| 111 | self.y = (c_double * l)() |
| 112 | for i, yi in enumerate(y): self.y[i] = yi |
| 113 | |
| 114 | self.x = (POINTER(svm_node) * l)() |
| 115 | for i, xi in enumerate(self.x_space): self.x[i] = xi |
| 116 | |
| 117 | class svm_parameter(Structure): |
| 118 | _names = ["svm_type", "kernel_type", "degree", "gamma", "coef0", |