Skip to content

Commit c13d98e

Browse files
committed
only do things in toggle_sparsity if there is a recipe
1 parent 7ffc1f9 commit c13d98e

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

R/sparsevctrs.R

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,32 @@ is_sparse_matrix <- function(x) {
33
}
44

55
toggle_sparsity <- function(object, data) {
6-
toggle_sparse <- "no"
7-
8-
if (allow_sparse(expect_spec_parsnip(object))) {
9-
if (has_preprocessor_recipe(object)) {
10-
est_sparsity <- recipes::.recipes_estimate_sparsity(
11-
extract_preprocessor(object)
12-
)
13-
} else {
14-
est_sparsity <- sparsevctrs::sparsity(data, sample = 1000)
15-
}
6+
if (
7+
allow_sparse(object$fit$actions$model$spec) &&
8+
has_preprocessor_recipe(object)
9+
) {
10+
est_sparsity <- recipes::.recipes_estimate_sparsity(
11+
extract_preprocessor(object)
12+
)
1613

1714
pred_log_fold <- pred_log_fold(
1815
est_sparsity,
1916
extract_spec_parsnip(object)$engine,
2017
nrow(data)
2118
)
19+
20+
toggle_sparse <- "no"
21+
2222
if (pred_log_fold > 0) {
2323
toggle_sparse <- "yes"
2424
}
25+
26+
object$pre$actions$recipe$recipe <- recipes::.recipes_toggle_sparse_args(
27+
object$pre$actions$recipe$recipe,
28+
choice = toggle_sparse
29+
)
2530
}
2631

27-
object$pre$actions$recipe$recipe <- recipes::.recipes_toggle_sparse_args(
28-
object$pre$actions$recipe$recipe,
29-
choice = toggle_sparse
30-
)
3132
object
3233
}
3334

0 commit comments

Comments
 (0)