Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions R/generics.R
Original file line number Diff line number Diff line change
Expand Up @@ -883,3 +883,19 @@ py_to_r.keras.src.utils.tracking.TrackedList <- function(x) import("builtins")$l

#' @export
py_to_r.keras.src.utils.tracking.TrackedSet <- function(x) import("builtins")$list(x)


#' @rdname Ops-python-methods
#' @rawNamespace if (getRversion() >= "4.3.0") S3method("%*%",python.builtin.object)
`%*%.tensorflow.tensor` <- function(x, y) {
if (is.atomic(x) && is_tensor(y)) {
if (length(x) > 1L)
x <- as.array(x)
x <- tf$convert_to_tensor(x, dtype = y$dtype)
} else if (is_tensor(x) && is.atomic(y)) {
if (length(y) > 1L)
y <- as.array(y)
y <- tf$convert_to_tensor(y, dtype = x$dtype)
}
NextMethod()
}
18 changes: 10 additions & 8 deletions R/help.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
register_tf_help_handler <- function() {
reticulate::register_module_help_handler("tensorflow", function(name, subtopic = NULL) {

# get the base tensorflow help url
version <- tf$`__version__`
version <- strsplit(version, ".", fixed = TRUE)[[1]]
help_url <- paste0("https://www.tensorflow.org/versions/r",
version[1], ".", version[2], "/api_docs/python/")

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

help_url <- "https://www.tensorflow.org/api_docs/python/"

# some adjustments
name <- sub("^tensorflow\\._api\\.v2\\.", "tensorflow.", name)
name <- sub("^tensorflow", "tf", name)
name <- sub("python.client.session.", "", name, fixed = TRUE)
name <- sub("python.ops.", "", name, fixed = TRUE)
Expand Down
18 changes: 10 additions & 8 deletions R/install.R
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,14 @@ function(method = c("auto", "virtualenv", "conda"),

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

if (lspci_listed)
return(TRUE)

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

lspci_listed <- tryCatch(
as.logical(length(
system("{ lspci | grep -i nvidia; } 2>/dev/null", intern = TRUE)
)),
# warning emitted by system for non-0 exit status
{
lspci <- system("lspci", intern = TRUE, ignore.stderr = TRUE)
any(grepl("nvidia", lspci, ignore.case = TRUE))
},
warning = function(w) FALSE,
error = function(e) FALSE
)
Expand Down