Skip to content

Commit

Permalink
#109: detect Windows 7 and set tar --force-local
Browse files Browse the repository at this point in the history
  • Loading branch information
jlmelville committed May 31, 2023
1 parent 766fcd7 commit 9d6339d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ components, a spectral initialization would attempt to merge multiple
sub-graphs. Not true: actually, spectral initialization is abandoned in favor
of PCA. The documentation has been updated to reflect the true state of affairs.
No idea what I was thinking of there.
* `load_model` and `save_model` didn't work on Windows 7 due to how the version
of `tar` there handles drive letters. Thank you
[mytarmail](https://github.com/mytarmail) for the report
(<https://github.com/jlmelville/uwot/issues/109>).

# uwot 0.1.14

Expand Down
22 changes: 14 additions & 8 deletions R/util.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ progress_for <- function(n, nchunks, fun) {
chunk_end <- chunk_start + round(remaining / (nchunks - i + 1)) - 1
remaining <- remaining - (chunk_end - chunk_start + 1)
fun(chunk_start, chunk_end)

message("*", appendLF = FALSE)
utils::flush.console()
}
Expand All @@ -129,7 +129,7 @@ checkna <- function(X) {
}
}

check_graph <- function(graph, expected_rows = NULL, expected_cols = NULL,
check_graph <- function(graph, expected_rows = NULL, expected_cols = NULL,
bipartite = FALSE) {
idx <- graph$idx
dist <- graph$dist
Expand Down Expand Up @@ -162,11 +162,11 @@ check_graph <- function(graph, expected_rows = NULL, expected_cols = NULL,
}
if (max(idx) > nrow(idx)) {
stop("Invalid neighbors: max index exceeds number of observations")
}
}
}
}

check_sparse_graph <- function(graph, expected_rows = NULL,
check_sparse_graph <- function(graph, expected_rows = NULL,
expected_cols = NULL, bipartite = FALSE) {
if (!is.null(expected_rows)) {
if (nrow(graph) != expected_rows) {
Expand All @@ -180,12 +180,12 @@ check_sparse_graph <- function(graph, expected_rows = NULL,
}
if (!bipartite) {
if (nrow(graph) != ncol(graph)) {
stop("Sparse distance matrix must have same number of rows and cols")
stop("Sparse distance matrix must have same number of rows and cols")
}
}
}

check_graph_list <- function(graph_list, expected_rows = NULL,
check_graph_list <- function(graph_list, expected_rows = NULL,
expected_cols = NULL, bipartite = FALSE) {
if (nn_is_single(graph_list)) {
graph_list <- list(graph_list)
Expand All @@ -200,7 +200,7 @@ check_graph_list <- function(graph_list, expected_rows = NULL,
check_graph(graph, expected_rows, expected_cols, bipartite = bipartite)
}
else if (is_sparse_matrix(graph)) {
check_sparse_graph(graph, expected_rows, expected_cols,
check_sparse_graph(graph, expected_rows, expected_cols,
bipartite = bipartite)
}
else {
Expand Down Expand Up @@ -288,4 +288,10 @@ is_installed <- function(pkgname) {
quietly = TRUE,
warn.conflicts = FALSE)
isNamespaceLoaded(pkgname)
}
}

is_win7 <- function() {
sys_info <- Sys.info()
sys_info[["sysname"]] == "Windows" &&
strsplit(sys_info["release"], split = " ")$release[[1]] == "7"
}
22 changes: 20 additions & 2 deletions R/uwot.R
Original file line number Diff line number Diff line change
Expand Up @@ -3231,7 +3231,16 @@ save_uwot <- function(model, file, unload = FALSE, verbose = FALSE) {
setwd(mod_dir)
tmp_model_file <- abspath(file)
tsmessage("Creating ", tmp_model_file)
utils::tar(tarfile = tmp_model_file, files = "uwot/")

# #109: Windows 7 tar needs "--force-local" to avoid interpreting colon
# as indicating a remote machine
extra_flags <- ""
if (is_win7()) {
extra_flags <- "--force-local"
}
utils::tar(tarfile = tmp_model_file,
extra_flags = extra_flags,
files = "uwot/")
},
finally = {
setwd(wd)
Expand Down Expand Up @@ -3304,7 +3313,16 @@ load_uwot <- function(file, verbose = FALSE) {
tsmessage("Creating temp directory ", mod_dir)
dir.create(mod_dir)

utils::untar(abspath(file), exdir = mod_dir, verbose = verbose)
# #109: Windows 7 tar needs "--force-local" to avoid interpreting colon
# as indicating a remote machine
extras <- NULL
if (is_win7()) {
extras <- "--force-local"
}
utils::untar(abspath(file),
exdir = mod_dir,
extras = extras,
verbose = verbose)

model_fname <- file.path(mod_dir, "uwot/model")
if (!file.exists(model_fname)) {
Expand Down

0 comments on commit 9d6339d

Please sign in to comment.