Skip to content

Commit 9f7e867

Browse files
alexhenrieNicolasHug
authored andcommitted
PERF Free problem and param sooner in liblinear.train_wrap
1 parent be03467 commit 9f7e867

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

sklearn/svm/liblinear.pyx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ def train_wrap(X, np.ndarray[np.float64_t, ndim=1, mode='c'] Y,
6161
with nogil:
6262
model = train(problem, param, &blas_functions)
6363

64+
### FREE
65+
free_problem(problem)
66+
free_parameter(param)
67+
# destroy_param(param) don't call this or it will destroy class_weight_label and class_weight
68+
6469
# coef matrix holder created as fortran since that's what's used in liblinear
6570
cdef np.ndarray[np.float64_t, ndim=2, mode='fortran'] w
6671
cdef int nr_class = get_nr_class(model)
@@ -81,11 +86,7 @@ def train_wrap(X, np.ndarray[np.float64_t, ndim=1, mode='c'] Y,
8186
w = np.empty((nr_class, nr_feature),order='F')
8287
copy_w(w.data, model, len_w)
8388

84-
### FREE
8589
free_and_destroy_model(&model)
86-
free_problem(problem)
87-
free_parameter(param)
88-
# destroy_param(param) don't call this or it will destroy class_weight_label and class_weight
8990

9091
return w, n_iter
9192

0 commit comments

Comments
 (0)