Type DenseHashTable
Namespace tensorflow.lookup.experimental
Parent LookupInterface
Interfaces IDenseHashTable
A generic mutable hash table implementation using tensors as backing store. Data can be inserted by calling the insert method and removed by calling the
remove method. It does not support initialization via the init method. It uses "open addressing" with quadratic reprobing to resolve collisions.
Compared to `MutableHashTable` the insert, remove and lookup operations in a
`DenseHashTable` are typically faster, but memory usage can be higher.
However, `DenseHashTable` does not require additional memory for
temporary tensors created during checkpointing and restore operations. Example usage:
Show Example
table = tf.lookup.DenseHashTable(key_dtype=tf.int64, value_dtype=tf.int64, default_value=-1, empty_key=0, deleted_key=-1) sess.run(table.insert(keys, values)) out = table.lookup(query_keys) print(out.eval())
Methods
Properties
Public instance methods
object erase(IGraphNodeBase keys, string name)
Removes `keys` and its associated values from the table. If a key is not present in the table, it is silently ignored.
Parameters
-
IGraphNodeBase
keys - Keys to remove. Can be a tensor of any shape. Must match the table's key type.
-
string
name - A name for the operation (optional).
Returns
-
object
- The created Operation.
object erase_dyn(object keys, object name)
Removes `keys` and its associated values from the table. If a key is not present in the table, it is silently ignored.
Parameters
-
object
keys - Keys to remove. Can be a tensor of any shape. Must match the table's key type.
-
object
name - A name for the operation (optional).
Returns
-
object
- The created Operation.
object insert_or_assign(IGraphNodeBase keys, IGraphNodeBase values, string name)
Associates `keys` with `values`.
Parameters
-
IGraphNodeBase
keys - Keys to insert. Can be a tensor of any shape. Must match the table's key type.
-
IGraphNodeBase
values - Values to be associated with keys. Must be a tensor of the same shape as `keys` and match the table's value type.
-
string
name - A name for the operation (optional).
Returns
-
object
- The created Operation.
object insert_or_assign_dyn(object keys, object values, object name)
Associates `keys` with `values`.
Parameters
-
object
keys - Keys to insert. Can be a tensor of any shape. Must match the table's key type.
-
object
values - Values to be associated with keys. Must be a tensor of the same shape as `keys` and match the table's value type.
-
object
name - A name for the operation (optional).
Returns
-
object
- The created Operation.
object remove(IGraphNodeBase keys, string name)
Removes `keys` and its associated values from the table. If a key is not present in the table, it is silently ignored.
Parameters
-
IGraphNodeBase
keys - Keys to remove. Can be a tensor of any shape. Must match the table's key type.
-
string
name - A name for the operation (optional).
Returns
-
object
- The created Operation.
object remove_dyn(object keys, object name)
Removes `keys` and its associated values from the table. If a key is not present in the table, it is silently ignored.
Parameters
-
object
keys - Keys to remove. Can be a tensor of any shape. Must match the table's key type.
-
object
name - A name for the operation (optional).
Returns
-
object
- The created Operation.
Public static methods
DenseHashTable NewDyn(object key_dtype, object value_dtype, object default_value, object empty_key, object deleted_key, object initial_num_buckets, ImplicitContainer<T> name, ImplicitContainer<T> checkpoint)
Creates an empty `DenseHashTable` object. Creates a table, the type of its keys and values are specified by key_dtype
and value_dtype, respectively.
Parameters
-
object
key_dtype - the type of the key tensors.
-
object
value_dtype - the type of the value tensors.
-
object
default_value - The value to use if a key is missing in the table.
-
object
empty_key - the key to use to represent empty buckets internally. Must not be used in insert, remove or lookup operations.
-
object
deleted_key - the key to use to represent deleted buckets internally. Must not be used in insert, remove or lookup operations and be different from the empty_key.
-
object
initial_num_buckets - the initial number of buckets.
-
ImplicitContainer<T>
name - A name for the operation (optional).
-
ImplicitContainer<T>
checkpoint - if True, the contents of the table are saved to and restored from checkpoints. If `shared_name` is empty for a checkpointed table, it is shared using the table node name.
Returns
-
DenseHashTable
- A `DenseHashTable` object.
Public properties
DType key_dtype get;
object key_dtype_dyn get;
object name get;
The name of the table.
object name_dyn get;
The name of the table.