tvm_ffi.StructuralKey#

class tvm_ffi.StructuralKey(key)[source]#

Bases: Object

Hash-cached structural key wrapper.

This wrapper can be used to hint that a dict uses structural equality and hash for the key.

Examples

Use StructuralKey with 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 Object as method __init_handle_by_constructor__().

__move_handle_from__(other)

Defined in Object as method __move_handle_from__().

_move()

Defined in Object as method _move().

is_(other)

Defined in Object as method is_().

same_as(other)

Defined in Object as method same_as().

Attributes

hash_i64

id_

Defined in Object as attribute id_.

key

property key#
property hash_i64#
__ffi_init__(*args, **kwargs)[source]#
Parameters:
Return type:

None