8000 MAINT Simplify liblinear helpers set_problem and csr_set_probl… (#14533) · thomasjpfan/scikit-learn@b7b0ba6 · GitHub
[go: up one dir, main page]

Skip to content

Commit b7b0ba6

Browse files
alexhenrierth
authored andcommitted
MAINT Simplify liblinear helpers set_problem and csr_set_probl… (scikit-learn#14533)
1 parent e23f58d commit b7b0ba6

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

sklearn/svm/src/liblinear/liblinear_helper.c

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -133,19 +133,13 @@ struct problem * set_problem(char *X, int double_precision_X, int n_samples,
133133
problem = malloc(sizeof(struct problem));
134134
if (problem == NULL) return NULL;
135135
problem->l = n_samples;
136-
137-
if (bias > 0) {
138-
problem->n = (int) n_features + 1;
139-
} else {
140-
problem->n = (int) n_features;
141-
}
142-
136+
problem->n = n_features + (bias > 0);
143137
problem->y = (double *) Y;
144138
problem->sample_weight = (double *) sample_weight;
145139
problem->x = dense_to_sparse(X, double_precision_X, n_samples, n_features,
146140
n_nonzero, bias);
147141
problem->bias = bias;
148-
problem->sample_weight = sample_weight;
142+
149143
if (problem->x == NULL) {
150144
free(problem);
151145
return NULL;
@@ -162,19 +156,12 @@ struct problem * csr_set_problem (char *X, int double_precision_X,
162156
problem = malloc (sizeof (struct problem));
163157
if (problem == NULL) return NULL;
164158
problem->l = n_samples;
165-
problem->sample_weight = (double *) sample_weight;
166-
167-
if (bias > 0){
168-
problem->n = (int) n_features + 1;
169-
} else {
170-
problem->n = (int) n_features;
171-
}
172-
159+
problem->n = n_features + (bias > 0);
173160
problem->y = (double *) Y;
161+
problem->sample_weight = (double *) sample_weight;
174162
problem->x = csr_to_sparse(X, double_precision_X, (int *) indices,
175163
(int *) indptr, n_samples, n_features, n_nonzero, bias);
176164
problem->bias = bias;
177-
problem->sample_weight = sample_weight;
178165

179166
if (problem->x == NULL) {
180167
free(problem);

0 commit comments

Comments
 (0)
0