Skip to content

Commit

Permalink
Force first arg in layer_ funcs before creating layer
Browse files Browse the repository at this point in the history
closes #1440
  • Loading branch information
t-kalinowski committed May 5, 2024
1 parent 876a3da commit 210478a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# keras3 (development version)

- Chains of `layer_*` calls with `|>` now instantiate layers in the
same order as `%>%` pipe chains: left-hand-side first (#1440).

User facing changes with upstream Keras v3.3.2:

- new function: `op_ctc_decode()`
Expand Down
7 changes: 6 additions & 1 deletion R/layer-r-helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
#' @noRd
create_layer <- function(LayerClass, object, args = list()) {

# force `object` before instantiating the layer, so pipe chains create layers
# in the the intutitively expected order.
# https://github.com/rstudio/keras/issues/1440
object <- if (missing(object)) NULL else object

# Starting in Keras 3.1, constraints can't be simple callable functions, they
# *must* inherit from keras.constraints.Constraint()
args <- imap(args, function(arg, name) {
Expand All @@ -37,7 +42,7 @@ create_layer <- function(LayerClass, object, args = list()) {
layer <- do.call(LayerClass, args)

# compose if we have an `object`
if (missing(object) || is.null(object))
if (is.null(object))
layer
else
invisible(compose_layer(object, layer))
Expand Down

0 comments on commit 210478a

Please sign in to comment.