MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / __init__

Method __init__

tensorflow/python/ops/lookup_ops.py:1611–1659  ·  view source on GitHub ↗

Creates an empty `MutableHashTable` object. Creates a table, the type of its keys and values are specified by key_dtype and value_dtype, respectively. Args: key_dtype: the type of the key tensors. value_dtype: the type of the value tensors. default_value: The value to

(self,
               key_dtype,
               value_dtype,
               default_value,
               name="MutableHashTable",
               checkpoint=True)

Source from the content-addressed store, hash-verified

1609 """
1610
1611 def __init__(self,
1612 key_dtype,
1613 value_dtype,
1614 default_value,
1615 name="MutableHashTable",
1616 checkpoint=True):
1617 """Creates an empty `MutableHashTable` object.
1618
1619 Creates a table, the type of its keys and values are specified by key_dtype
1620 and value_dtype, respectively.
1621
1622 Args:
1623 key_dtype: the type of the key tensors.
1624 value_dtype: the type of the value tensors.
1625 default_value: The value to use if a key is missing in the table.
1626 name: A name for the operation (optional).
1627 checkpoint: if True, the contents of the table are saved to and restored
1628 from checkpoints. If `shared_name` is empty for a checkpointed table, it
1629 is shared using the table node name.
1630
1631 Returns:
1632 A `MutableHashTable` object.
1633
1634 Raises:
1635 ValueError: If checkpoint is True and no name was specified.
1636 """
1637 self._default_value = ops.convert_to_tensor(
1638 default_value, dtype=value_dtype)
1639 self._value_shape = self._default_value.get_shape()
1640 self._checkpoint = checkpoint
1641 self._key_dtype = key_dtype
1642 self._value_dtype = value_dtype
1643 self._name = name
1644
1645 self._shared_name = None
1646 if context.executing_eagerly():
1647 # TODO(allenl): This will leak memory due to kernel caching by the
1648 # shared_name attribute value (but is better than the alternative of
1649 # sharing everything by default when executing eagerly; hopefully creating
1650 # tables in a loop is uncommon).
1651 # TODO(rohanj): Use context.shared_name() instead.
1652 self._shared_name = "table_%d" % (ops.uid(),)
1653 super(MutableHashTable, self).__init__(key_dtype, value_dtype)
1654
1655 self._resource_handle = self._create_resource()
1656 if checkpoint:
1657 saveable = MutableHashTable._Saveable(self, name)
1658 if not context.executing_eagerly():
1659 ops.add_to_collection(ops.GraphKeys.SAVEABLE_OBJECTS, saveable)
1660
1661 def _create_resource(self):
1662 # The table must be shared if checkpointing is requested for multi-worker

Callers

nothing calls this directly

Calls 6

_create_resourceMethod · 0.95
executing_eagerlyMethod · 0.80
uidMethod · 0.80
add_to_collectionMethod · 0.80
get_shapeMethod · 0.45
__init__Method · 0.45

Tested by

no test coverage detected