This is an automated email from the ASF dual-hosted git repository.
expye pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm-ffi.git
The following commit(s) were added to refs/heads/main by this push:
new dd3de07 [TEST] Add test for Optional<TensorView> (#274)
dd3de07 is described below
commit dd3de0746b50009091a0ecc3e63bfcf2e4a2da94
Author: Tianqi Chen <[email protected]>
AuthorDate: Mon Nov 17 10:45:17 2025 -0500
[TEST] Add test for Optional<TensorView> (#274)
This PR adds tests for Optional<TensorView> to ensure correct behavior.
---
src/ffi/testing/testing.cc | 2 ++
tests/python/test_tensor.py | 11 +++++++++++
2 files changed, 13 insertions(+)
diff --git a/src/ffi/testing/testing.cc b/src/ffi/testing/testing.cc
index bccc5c0..056ac68 100644
--- a/src/ffi/testing/testing.cc
+++ b/src/ffi/testing/testing.cc
@@ -270,6 +270,8 @@ TVM_FFI_STATIC_INIT_BLOCK() {
// NOLINTNEXTLINE(bugprone-casting-through-void)
return
reinterpret_cast<int64_t>(reinterpret_cast<void*>(_mlir_add_one_c_symbol));
})
+ .def("testing.optional_tensor_view_has_value",
+ [](Optional<TensorView> t) { return t.has_value(); })
.def_method("testing.TestIntPairSum", &TestIntPair::Sum, "Get sum of the
pair");
}
diff --git a/tests/python/test_tensor.py b/tests/python/test_tensor.py
index 7a257cd..0551d14 100644
--- a/tests/python/test_tensor.py
+++ b/tests/python/test_tensor.py
@@ -131,5 +131,16 @@ def test_tensor_from_pytorch_rocm() -> None:
assert device_type == "rocm"
+def test_optional_tensor_view() -> None:
+ optional_tensor_view_has_value = tvm_ffi.get_global_func(
+ "testing.optional_tensor_view_has_value"
+ )
+ assert not optional_tensor_view_has_value(None)
+ x = np.zeros((128,), dtype="float32")
+ if not hasattr(x, "__dlpack__"):
+ return
+ assert optional_tensor_view_has_value(x)
+
+
if __name__ == "__main__":
pytest.main([__file__])