Skip to content

Commit

Permalink
Add deep_clone, currently WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
advieser committed Aug 14, 2024
1 parent 53ae9a7 commit 2eef42d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions R/PipeOpUMAP.R
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,26 @@ PipeOpUMAP = R6Class("PipeOpUMAP",
.predict_dt = function(dt, levels) {
params = self$param_set$get_values(tags = c("umap", "predict"))
invoke(uwot::umap_transform, dt, self$state, .args = params)
},

# We need to overload deep_clone since state$nn_index$ann is a C++ address if nn_method is "annoy" or "hnsw"
deep_clone = function(name, value) {
if (name == "state" && "NO_OP" %nin% class(value)) {
# TODO: Make sure these class names are correct for different options for nn_args
# attr(attr(value$nn_index, "class"), "package") might work otherwise
if (class(value$nn_index$ann) %in% c("RcppHNSWL2", "Rcpp_AnnoyEuclidean")) {
state = value
state$nn_index$ann = value$nn_index$ann$copy()
state$nn_index$type = value$nn_index$type
state$nn_index$metric = value$nn_index$metric
state$nn_index$ndim = value$nn_index$ndim
state
} else {
super$deep_clone(name, value)
}
} else {
super$deep_clone(name, value)
}
}
)
)
Expand Down

0 comments on commit 2eef42d

Please sign in to comment.