Skip to content

Commit d7a897c

Browse files
committed
Fix issue with Metric/Loss wrapper
1 parent 135eafa commit d7a897c

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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/losses.R

Lines changed: 2 additions & 1 deletion
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

Lines changed: 7 additions & 0 deletions
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()

0 commit comments

Comments
 (0)