Skip to content

Commit e357997

Browse files
authored
Merge pull request #1494 from rstudio/cran/1.3.0
CRAN Release v1.3.0
2 parents ffc7437 + a132df0 commit e357997

File tree

788 files changed

+23987
-3876
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

788 files changed

+23987
-3876
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: keras3
22
Type: Package
33
Title: R Interface to 'Keras'
4-
Version: 1.2.0.9000
4+
Version: 1.3.0
55
Authors@R: c(
66
person("Tomasz", "Kalinowski", role = c("aut", "cph", "cre"),
77
email = "[email protected]"),

NEWS.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# keras3 (development version)
1+
# keras3 1.3.0
22

33
- Keras now uses `reticulate::py_require()` to resolve Python dependencies.
44
Calling `install_keras()` is no longer required (but is still supported).
@@ -13,6 +13,9 @@
1313

1414
- `%*%` now dispatches to `op_matmul()` for tensorflow tensors, which
1515
has relaxed shape constraints compared to `tf$matmul()`.
16+
17+
- Fixed an issue where calling a `Metric` and `Loss` object
18+
with unnamed arguments would error.
1619

1720
## Added compatibility with Keras v3.8.0. User-facing changes:
1821

R/install.R

+23-12
Original file line numberDiff line numberDiff line change
@@ -128,23 +128,29 @@ is_linux <- function() {
128128

129129
#' Configure a Keras backend
130130
#'
131-
#' @param backend string, can be `"tensorflow"`, `"jax"`, `"numpy"`, or `"torch"`.
132-
#' @param gpu bool, whether to use the GPU.
131+
#' @param backend string, can be `"tensorflow"`, `"jax"`, `"numpy"`, or
132+
#' `"torch"`.
133+
#' @param gpu bool, whether to use the GPU. If `NA` (default), it will attempt
134+
#' to detect GPU availability on Linux. On M-series Macs, it defaults to
135+
#' `FALSE` for TensorFlow and `TRUE` for JAX. On Windows, it defaults to
136+
#' `FALSE`.
133137
#'
134138
#' @details
135-
#' These functions allow configuring which backend keras will use.
136-
#' Note that only one backend can be configured at a time.
139+
#'
140+
#' These functions allow configuring which backend keras will use. Note that
141+
#' only one backend can be configured at a time.
137142
#'
138143
#' The function should be called after `library(keras3)` and before calling
139144
#' other functions within the package (see below for an example).
140145
#'
141-
#' There is experimental support for changing the backend after keras has initialized.
142-
#' using `config_set_backend()`.
146+
#' There is experimental support for changing the backend after keras has
147+
#' initialized. using `config_set_backend()`.
143148
#' ```r
144149
#' library(keras3)
145150
#' use_backend("tensorflow")
146151
#' ```
147-
#' @returns Called primarily for side effects. Returns the provided `backend`, invisibly.
152+
#' @returns Called primarily for side effects. Returns the provided `backend`,
153+
#' invisibly.
148154
#' @export
149155
use_backend <- function(backend, gpu = NA) {
150156

@@ -245,9 +251,11 @@ use_backend <- function(backend, gpu = NA) {
245251
if (gpu) {
246252
py_require(c("tensorflow-cpu", "torch", "torchvision", "torchaudio"))
247253
} else {
248-
Sys.setenv("UV_INDEX" = "https://download.pytorch.org/whl/cpu")
254+
Sys.setenv("UV_INDEX" = trimws(paste(sep = " ",
255+
"https://download.pytorch.org/whl/cpu",
256+
Sys.getenv("UV_INDEX")
257+
)))
249258
py_require(c("tensorflow-cpu", "torch", "torchvision", "torchaudio"))
250-
# additional_args = c("--index", "https://download.pytorch.org/whl/cpu"))
251259
}
252260
},
253261

@@ -268,12 +276,14 @@ use_backend <- function(backend, gpu = NA) {
268276

269277
Windows_torch = {
270278
if (is.na(gpu))
271-
gpu <- has_gpu()
279+
gpu <- FALSE
272280

273281
if (gpu) {
274-
Sys.setenv("UV_INDEX" = "https://download.pytorch.org/whl/cu126")
282+
Sys.setenv("UV_INDEX" = trimws(paste(sep = " ",
283+
"https://download.pytorch.org/whl/cu126",
284+
Sys.getenv("UV_INDEX")
285+
)))
275286
py_require(c("torch", "torchvision", "torchaudio"))
276-
# additional_args = c("--index", "https://download.pytorch.org/whl/cu126"))
277287
} else {
278288
py_require(c("torch", "torchvision", "torchaudio"))
279289
}
@@ -289,6 +299,7 @@ use_backend <- function(backend, gpu = NA) {
289299

290300

291301

302+
292303
get_os <- function() {
293304
if (is_windows()) "Windows" else if (is_mac_arm64()) "macOS" else "Linux"
294305
}

R/losses.R

+2-1
Original file line numberDiff line numberDiff line change
@@ -1962,7 +1962,8 @@ py_to_r_wrapper.keras.src.losses.loss.Loss <- function(x) {
19621962
as.function.default(c(formals(x), quote({
19631963
args <- capture_args(list(y_true = as_py_array,
19641964
y_pred = as_py_array,
1965-
sample_weight = as_py_array))
1965+
sample_weight = as_py_array),
1966+
enforce_all_dots_named = FALSE)
19661967
do.call(x, args)
19671968
})))
19681969
}

R/metrics.R

+7
Original file line numberDiff line numberDiff line change
@@ -2978,6 +2978,13 @@ function (y_true, y_pred, from_logits = FALSE, ignore_class = NULL,
29782978
#' ```
29792979
#'
29802980
#' ```{r}
2981+
#' # calling a metric directly is equivalent to calling
2982+
#' # m$update_state(); m$result()
2983+
#' m <- metric_mean()
2984+
#' m(c(1, 3, 5, 7))
2985+
#' ```
2986+
#'
2987+
#' ```{r}
29812988
#' m$reset_state()
29822989
#' m$update_state(c(1, 3, 5, 7), sample_weight = c(1, 1, 0, 0))
29832990
#' m$result()

R/package.R

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ keras <- NULL
7272
# the tensorflow R package calls `py_require()` to ensure GPU is usable on Linux
7373
# use_backend() includes py_require(action = "remove") calls to undo
7474
# what tensorflow:::.onLoad() did. Keep them in sync!
75+
# backend <- Sys.getenv("KERAS_BACKEND", "jax")
7576
backend <- Sys.getenv("KERAS_BACKEND", "tensorflow")
7677
gpu <- NA
7778
if (endsWith(backend, "-cpu")) {

cran-comments.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
0 errors | 0 warnings | 1 note
44

5-
* installed size is 12.4Mb
5+
* checking installed package size ... NOTE
6+
installed size is 14.3Mb
67
sub-directories of 1Mb or more:
78
doc 3.3Mb
8-
help 8.4Mb
9+
help 10.1Mb

docs/404.html

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/LICENSE-text.html

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)