()
| 279 | |
| 280 | |
| 281 | def test_function_subclass() -> None: |
| 282 | class JitFunction: |
| 283 | def __init__(self, metadata: Any) -> None: |
| 284 | self.metadata = metadata |
| 285 | |
| 286 | class MyFunction(tvm_ffi.Function, JitFunction): |
| 287 | def __init__(self, metadata: Any) -> None: |
| 288 | # Explicitly initialize the mixin. `super()` is not used because `tvm_ffi.Function` |
| 289 | # is an extension type without a standard `__init__`. |
| 290 | JitFunction.__init__(self, metadata) |
| 291 | |
| 292 | # When subclassing a Cython cdef class and overriding `__init__`, |
| 293 | # special methods like `__call__` may not be inherited automatically. |
| 294 | # This explicit assignment ensures the subclass remains callable. |
| 295 | __call__ = tvm_ffi.Function.__call__ |
| 296 | |
| 297 | f = tvm_ffi.convert(lambda x: x) |
| 298 | assert isinstance(f, tvm_ffi.Function) |
| 299 | f_sub = MyFunction(128) |
| 300 | # move handle from f to f_sub an existing function |
| 301 | f_sub.__move_handle_from__(f) |
| 302 | assert isinstance(f_sub, MyFunction) |
| 303 | assert isinstance(f_sub, JitFunction) |
| 304 | assert f_sub.metadata == 128 |
| 305 | |
| 306 | y: int = f_sub(2) |
| 307 | assert y == 2 |
| 308 | echo = tvm_ffi.get_global_func("testing.echo") |
| 309 | fechoed = echo(f_sub) |
| 310 | assert isinstance(fechoed, tvm_ffi.Function) |
| 311 | assert fechoed.__chandle__() == f_sub.__chandle__() |
| 312 | assert fechoed(10) == 10 |
| 313 | |
| 314 | |
| 315 | def test_function_with_opaque_ptr_protocol() -> None: |
nothing calls this directly
no test coverage detected