Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call from jit operators #840

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Support for NULL tensors.
dfalbel committed May 31, 2022

Verified

This commit was signed with the committer’s verified signature. The key has expired.
alexandre-abrioux Alexandre ABRIOUX
commit 30eed6375b7a5abcd7bcdbec23264995528b0dda
6 changes: 6 additions & 0 deletions src/tensor.cpp
Original file line number Diff line number Diff line change
@@ -128,6 +128,12 @@ torch::Tensor torch_tensor_cpp(SEXP x, Rcpp::Nullable<torch::Dtype> dtype,
break;
}
}
case NILSXP: {
cdtype = lantern_Dtype_bool();
final_type = dtype.isNull() ? torch::Dtype(lantern_Dtype_bool())
: Rcpp::as<torch::Dtype>(dtype);
break;
}
default: {
Rcpp::stop("R type not handled");
}
12 changes: 12 additions & 0 deletions tests/testthat/test-indexing.R
Original file line number Diff line number Diff line change
@@ -250,3 +250,15 @@ test_that("regression test for #695", {
as.array(a)[c(1, 3), , c(1, 3)]
)
})

test_that("NULL tensor", {

x <- torch_tensor(NULL)
expect_true(x$dtype == torch_bool())
expect_equal(x$shape, 0)

# subsetting shouldn't crash
expect_error(x[1], regexp = "out of bounds")
expect_error(torch_tensor(as.integer(NULL))[1], regexp = "out of bounds")

})