Creates an empty `DenseHashTable` 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 u
(self,
key_dtype,
value_dtype,
default_value,
empty_key,
deleted_key,
initial_num_buckets=None,
name="MutableDenseHashTable",
checkpoint=True)
| 1858 | # TODO(andreasst): consider extracting common code with MutableHashTable into |
| 1859 | # a common superclass. |
| 1860 | def __init__(self, |
| 1861 | key_dtype, |
| 1862 | value_dtype, |
| 1863 | default_value, |
| 1864 | empty_key, |
| 1865 | deleted_key, |
| 1866 | initial_num_buckets=None, |
| 1867 | name="MutableDenseHashTable", |
| 1868 | checkpoint=True): |
| 1869 | """Creates an empty `DenseHashTable` object. |
| 1870 | |
| 1871 | Creates a table, the type of its keys and values are specified by key_dtype |
| 1872 | and value_dtype, respectively. |
| 1873 | |
| 1874 | Args: |
| 1875 | key_dtype: the type of the key tensors. |
| 1876 | value_dtype: the type of the value tensors. |
| 1877 | default_value: The value to use if a key is missing in the table. |
| 1878 | empty_key: the key to use to represent empty buckets internally. Must not |
| 1879 | be used in insert, remove or lookup operations. |
| 1880 | deleted_key: the key to use to represent deleted buckets internally. Must |
| 1881 | not be used in insert, remove or lookup operations and be different from |
| 1882 | the empty_key. |
| 1883 | initial_num_buckets: the initial number of buckets. |
| 1884 | name: A name for the operation (optional). |
| 1885 | checkpoint: if True, the contents of the table are saved to and restored |
| 1886 | from checkpoints. If `shared_name` is empty for a checkpointed table, it |
| 1887 | is shared using the table node name. |
| 1888 | |
| 1889 | Returns: |
| 1890 | A `DenseHashTable` object. |
| 1891 | |
| 1892 | Raises: |
| 1893 | ValueError: If checkpoint is True and no name was specified. |
| 1894 | """ |
| 1895 | self._default_value = ops.convert_to_tensor( |
| 1896 | default_value, dtype=value_dtype, name="default_value") |
| 1897 | self._key_dtype = key_dtype |
| 1898 | self._value_dtype = value_dtype |
| 1899 | self._initial_num_buckets = initial_num_buckets |
| 1900 | self._value_shape = self._default_value.get_shape() |
| 1901 | self._checkpoint = checkpoint |
| 1902 | self._name = name |
| 1903 | |
| 1904 | self._empty_key = ops.convert_to_tensor( |
| 1905 | empty_key, dtype=key_dtype, name="empty_key") |
| 1906 | self._deleted_key = ops.convert_to_tensor( |
| 1907 | deleted_key, dtype=key_dtype, name="deleted_key") |
| 1908 | self._shared_name = None |
| 1909 | if context.executing_eagerly(): |
| 1910 | # TODO(allenl): This will leak memory due to kernel caching by the |
| 1911 | # shared_name attribute value (but is better than the alternative of |
| 1912 | # sharing everything by default when executing eagerly; hopefully creating |
| 1913 | # tables in a loop is uncommon). |
| 1914 | # TODO(rohanj): Use context.shared_name() instead. |
| 1915 | self._shared_name = "table_%d" % (ops.uid(),) |
| 1916 | super(DenseHashTable, self).__init__(key_dtype, value_dtype) |
| 1917 |
no test coverage detected