Skip to content

Commit 94bccf6

Browse files
authored
Merge pull request #621 from rstudio/fixes
Misc. small fixes
2 parents e48867f + f9d6f4b commit 94bccf6

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed

Diff for: R/generics.R

+16
Original file line numberDiff line numberDiff line change
@@ -883,3 +883,19 @@ py_to_r.keras.src.utils.tracking.TrackedList <- function(x) import("builtins")$l
883883

884884
#' @export
885885
py_to_r.keras.src.utils.tracking.TrackedSet <- function(x) import("builtins")$list(x)
886+
887+
888+
#' @rdname Ops-python-methods
889+
#' @rawNamespace if (getRversion() >= "4.3.0") S3method("%*%",python.builtin.object)
890+
`%*%.tensorflow.tensor` <- function(x, y) {
891+
if (is.atomic(x) && is_tensor(y)) {
892+
if (length(x) > 1L)
893+
x <- as.array(x)
894+
x <- tf$convert_to_tensor(x, dtype = y$dtype)
895+
} else if (is_tensor(x) && is.atomic(y)) {
896+
if (length(y) > 1L)
897+
y <- as.array(y)
898+
y <- tf$convert_to_tensor(y, dtype = x$dtype)
899+
}
900+
NextMethod()
901+
}

Diff for: R/help.R

+10-8
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@
33
register_tf_help_handler <- function() {
44
reticulate::register_module_help_handler("tensorflow", function(name, subtopic = NULL) {
55

6-
# get the base tensorflow help url
7-
version <- tf$`__version__`
8-
version <- strsplit(version, ".", fixed = TRUE)[[1]]
9-
help_url <- paste0("https://www.tensorflow.org/versions/r",
10-
version[1], ".", version[2], "/api_docs/python/")
11-
12-
# upstream TF is missing public docs for later version
13-
# https://github.com/tensorflow/tensorflow/issues/89084
6+
# # Version specific URLs are disabled because
7+
# # upstream TF is missing public docs for later version
8+
# # https://github.com/tensorflow/tensorflow/issues/89084
9+
# # get the base tensorflow help url
10+
# version <- tf$`__version__`
11+
# version <- strsplit(version, ".", fixed = TRUE)[[1]]
12+
# help_url <- paste0("https://www.tensorflow.org/versions/r",
13+
# version[1], ".", version[2], "/api_docs/python/")
14+
1415
help_url <- "https://www.tensorflow.org/api_docs/python/"
1516

1617
# some adjustments
18+
name <- sub("^tensorflow\\._api\\.v2\\.", "tensorflow.", name)
1719
name <- sub("^tensorflow", "tf", name)
1820
name <- sub("python.client.session.", "", name, fixed = TRUE)
1921
name <- sub("python.ops.", "", name, fixed = TRUE)

Diff for: R/install.R

+10-8
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,14 @@ function(method = c("auto", "virtualenv", "conda"),
186186

187187
has_nvidia_gpu <- function() {
188188
lspci_listed <- tryCatch(
189-
as.logical(length(
190-
system("{ lspci | grep -i nvidia; } 2>/dev/null", intern = TRUE)
191-
)),
192-
warning = function(w) FALSE, # warning emitted by system for non-0 exit status
189+
{
190+
lspci <- system("lspci", intern = TRUE, ignore.stderr = TRUE)
191+
any(grepl("nvidia", lspci, ignore.case = TRUE))
192+
},
193+
warning = function(w) FALSE,
193194
error = function(e) FALSE
194195
)
196+
195197
if (lspci_listed)
196198
return(TRUE)
197199

@@ -342,10 +344,10 @@ has_gpu <- function() {
342344
# on.exit(options(oop), add = TRUE)
343345

344346
lspci_listed <- tryCatch(
345-
as.logical(length(
346-
system("{ lspci | grep -i nvidia; } 2>/dev/null", intern = TRUE)
347-
)),
348-
# warning emitted by system for non-0 exit status
347+
{
348+
lspci <- system("lspci", intern = TRUE, ignore.stderr = TRUE)
349+
any(grepl("nvidia", lspci, ignore.case = TRUE))
350+
},
349351
warning = function(w) FALSE,
350352
error = function(e) FALSE
351353
)

0 commit comments

Comments
 (0)