tests/testthat/test-nn-flatten.R

test_that("flatten and unflatten", {
  x <- torch_randn(32, 5, 3, 2)
  fl <- nn_flatten()
  unfl <- nn_unflatten(2, c(5, 3, 2))

  expect_equal_to_tensor(unfl(fl(x)), x)
})

Try the torch package in your browser

Any scripts or data that you put into this service are public.

torch documentation built on Nov. 5, 2025, 7:02 p.m.