MCPcopy Create free account
hub / github.com/apache/tvm-ffi / test_function_with_value_protocol

Function test_function_with_value_protocol

tests/python/test_function.py:396–412  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

394
395
396def test_function_with_value_protocol() -> None:
397 class ValueProtocol:
398 def __init__(self, value: Any) -> None:
399 self.value = value
400
401 def __tvm_ffi_value__(self) -> Any:
402 return self.value
403
404 fecho = tvm_ffi.get_global_func("testing.echo")
405 assert fecho(ValueProtocol(10)) == 10
406 assert tuple(fecho(ValueProtocol([1, 2, 3]))) == (1, 2, 3)
407 assert tuple(fecho(ValueProtocol([1, 2, ValueProtocol(3)]))) == (1, 2, 3)
408 nested_value_protocol = ValueProtocol(ValueProtocol(ValueProtocol(10)))
409 assert fecho(nested_value_protocol) == 10
410
411 nested_value_protocol = ValueProtocol([ValueProtocol(1), ValueProtocol(2), ValueProtocol(3)])
412 assert tuple(fecho(nested_value_protocol)) == (1, 2, 3)
413
414
415def test_convert_func_tensor_cls_missing_attribute() -> None:

Callers

nothing calls this directly

Calls 1

ValueProtocolClass · 0.85

Tested by

no test coverage detected