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)
| 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 |
nothing calls this directly
no test coverage detected