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
2 changes: 1 addition & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:

steps:

- uses: actions/checkout@v3
- uses: actions/checkout@v7

- uses: r-lib/actions/setup-pandoc@v2

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/awaiting-response-close.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
pull-requests: write

steps:
- uses: actions/stale@v4
- uses: actions/stale@v11
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/awaiting-response-remove-label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ jobs:
- name: Remove 'awaiting response' label and maybe reopen
if: contains(github.event.issue.labels.*.name, 'awaiting response')
run: |
gh issue edit $ISSUE --remove-label 'awaiting response'
gh issue reopen $ISSUE
gh issue edit "$ISSUE" --remove-label 'awaiting response'
gh issue reopen "$ISSUE"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ISSUE: ${{ github.event.issue.html_url }}
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Imports:
lifecycle
Roxygen: list(markdown = TRUE)
Suggests:
testthat (>= 2.1.0),
testthat (>= 3.1.7),
keras3,
pillar,
withr,
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# tensorflow (development version)

- `as_tensor()` preserves large numeric values when converting to `int64`,
`uint64`, or `uint32`, and avoids an integer overflow error on Windows.
- `py_require_tensorflow()` no longer adds an obsolete NumPy constraint on
Windows, allowing TensorFlow to resolve with Python 3.13.
- Updated docs to recommend `py_require_tensorflow()` for TensorFlow setup (#627).
- Fixed `tensorboard()` startup with recent TensorBoard versions (#626).

Expand Down
4 changes: 3 additions & 1 deletion R/generics.R
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,9 @@ as_tensor.double <- function(x, dtype = NULL, ..., name = NULL) {
# tf.dtypes.saturate_cast() is better, but still can be surprising.
# Users must opt in to saturate cast (or overflow cast)
# by casting in a separate call after converting to tensor.
if (dtype$max <= .Machine$integer.max)
# Compare width and signedness without converting dtype$max to an R
# integer, which overflows for int64, uint64, and uint32.
if (dtype$size < 4L || (dtype$size == 4L && !dtype$is_unsigned))
storage.mode(x) <- "integer"

if (anyNA(x))
Expand Down
13 changes: 4 additions & 9 deletions R/install.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@
#' if `tensorflow-metal` is installed. There are known issues with random number
#' generators like `tf$random$stateless_uniform()`, likely others as well.
#'
#' - On Windows: `"tensorflow"` and `"numpy<2"` are declared. Note that
#' TensorFlow GPU usage on Windows is no longer supported (Since TensorFlow
#' 2.10). To use a GPU on windows, use TensorFlow via WSL. `"numpy<2"` is
#' declared because at the time of this publishing, the pre-built binaries of
#' `tensorflow` for Windows are not compatible with `numpy>2`.
#' - On Windows: `"tensorflow"` is declared. TensorFlow's package metadata
#' determines the compatible NumPy versions. TensorFlow 2.10 was the last
#' release with GPU support on native Windows. To use a GPU with newer
#' versions, use TensorFlow via WSL.
#'
#' `install_tensorflow()` remains available for users who want to explicitly
#' create a persistent virtual environment. It creates a new virtual environment
Expand Down Expand Up @@ -411,10 +410,6 @@ get_py_requirements <- function(use_gpu = NA) {
packages <- c("tensorflow", "tensorflow-metal")
}

} else if (is_windows()) {

packages <- c(packages, "numpy<2")

}

list(packages = packages, python_version = python_version)
Expand Down
9 changes: 4 additions & 5 deletions man/install_tensorflow.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions tests/testthat/test-as_tensor.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ test_that("as_tensor works", {
})


test_that("as_tensor preserves values outside R's integer range", {
skip_if_no_tensorflow()

for (dtype in c("int64", "uint64", "uint32")) {
value <- if (dtype == "uint32") 2^31 else 2^40
for (x in list(value, c(value, value + 1))) {
tensor <- as_tensor(x, dtype)
expect_identical(tensor$dtype$name, dtype)
expect_equal(as.numeric(tensor), x)
}
}

expect_equal(as.numeric(as_tensor(-2^40, "int64")), -2^40)
})


test_that("conversion of tf.string dtype tensors", {

xx <- list(array("foo"),
Expand Down
18 changes: 18 additions & 0 deletions tests/testthat/test-requirements.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
test_that("TensorFlow requirements allow NumPy 2 on Windows", {
requirements <- callr::r(function() {
library(tensorflow)
testthat::local_mocked_bindings(
is_linux = function() FALSE,
is_mac_arm64 = function() FALSE,
is_windows = function() TRUE,
.package = "tensorflow"
)

reticulate::py_require("numpy>=2", python_version = "3.13", action = "set")
tensorflow::py_require_tensorflow()
reticulate::py_require()
})

expect_setequal(requirements$packages, c("numpy>=2", "tensorflow"))
expect_identical(requirements$python_version, "3.13")
})
Loading