Follow-up to #241. The matrix path correctly returns a length-n vector of NA-functions on all-NA input, but the list path still hits the "truly empty" branch in new_tfd() because tfd.list NA-strips entries to numeric(0) before calling new_tfd, and new_tfd sees zero non-empty entries and returns the prototype.
library(tf)
length(tfd(matrix(NA_real_, nrow = 3, ncol = 5), arg = 1:5)) # 3 — correct after #241
length(tfd(list(NA_real_, NA_real_), arg = list(c(1,2), c(1,2)))) # 0 — still buggy
Fix
tfd.list should not strip all-NA entries before passing to new_tfd; preserve a marker so new_tfd's all-NA branch is triggered with the original input size.
Regression test
test_that("all-NA list input preserves vec_size", {
x <- tfd(list(NA_real_, NA_real_), arg = list(c(1, 2), c(1, 2))) |>
suppressWarnings()
expect_length(x, 2)
expect_true(all(is.na(x)))
})
Found while reviewing PR for #241.
Follow-up to #241. The matrix path correctly returns a length-n vector of NA-functions on all-NA input, but the list path still hits the "truly empty" branch in
new_tfd()becausetfd.listNA-strips entries tonumeric(0)before callingnew_tfd, andnew_tfdsees zero non-empty entries and returns the prototype.Fix
tfd.listshould not strip all-NA entries before passing tonew_tfd; preserve a marker sonew_tfd's all-NA branch is triggered with the original input size.Regression test
Found while reviewing PR for #241.