tvm_ffi.StructuralKey#
- class tvm_ffi.StructuralKey(key)[source]#
Bases:
ObjectHash-cached structural key wrapper.
This wrapper can be used to hint that a dict uses structural equality and hash for the key.
Examples
Use
StructuralKeywith Python dictionaries when you want key lookup by structural semantics:import tvm_ffi k0 = tvm_ffi.StructuralKey([1, 2, 3]) k1 = tvm_ffi.StructuralKey([1, 2, 3]) k2 = tvm_ffi.StructuralKey([1, 2, 4]) d = {k0: "value-a", k2: "value-b"} assert d[k1] == "value-a" # k1 matches k0 structurally assert d[k2] == "value-b"
It can also be used directly with
tvm_ffi.Map:m = tvm_ffi.Map({k0: 1, k1: 2}) assert len(m) == 1 assert m[k0] == 2
See also
tvm_ffi.structural_equal()Structural equality comparison.
tvm_ffi.structural_hash()Structural hash computation.
- Parameters:
key (
Any)
- __init__(key)[source]#
Create a structural key from
key.- Parameters:
key (
Any) – The underlying value used for structural hash/equality.- Return type:
None
Methods
__ffi_init__(*args, **kwargs)__init__(key)Create a structural key from
key.__init_handle_by_constructor__(fconstructor, ...)Defined in
Objectas method__init_handle_by_constructor__().__move_handle_from__(other)Defined in
Objectas method__move_handle_from__()._move()is_(other)Defined in
Objectas methodis_().same_as(other)Attributes
- property key#
- property hash_i64#