(
self, shape, dtype, distributed_name,
initializer=None, init_func=None, segment_size=None,
collections=None, trainable=True, slicer=None,
hash_table=None, concurrent_read=True, children=None, name=None)
| 144 | DEFAULT_SLICE_SIZE = 4096 |
| 145 | |
| 146 | def __init__( |
| 147 | self, shape, dtype, distributed_name, |
| 148 | initializer=None, init_func=None, segment_size=None, |
| 149 | collections=None, trainable=True, slicer=None, |
| 150 | hash_table=None, concurrent_read=True, children=None, name=None): |
| 151 | self._distributed_name = distributed_name |
| 152 | self._slots = {} |
| 153 | self._concurrent_read = concurrent_read |
| 154 | self._children = [] if children is None else children |
| 155 | with ops.name_scope(name, "HashTable") as name: |
| 156 | handle_name = ops.name_from_scope_name(name) |
| 157 | self._name = handle_name |
| 158 | if hash_table is None: |
| 159 | hash_table = SimpleHashTable( |
| 160 | distributed_name, concurrent_read, slicer, self._children) |
| 161 | with ops.control_dependencies(None): |
| 162 | with ops.colocate_with(hash_table.handle): |
| 163 | if initializer == None and init_func == None: |
| 164 | raise ValueError("initializer or initial_value must be specified.") |
| 165 | if initializer != None and init_func != None: |
| 166 | raise ValueError("initializer and initial_value must not be specified both.") |
| 167 | |
| 168 | if segment_size == None: |
| 169 | segment_size = self.DEFAULT_SLICE_SIZE |
| 170 | self._shape = tensor_shape.TensorShape(shape) |
| 171 | self._dtype = dtypes.as_dtype(dtype) |
| 172 | self._segment_shape = tensor_shape.TensorShape.concatenate( |
| 173 | tensor_shape.TensorShape([segment_size]), self._shape) |
| 174 | |
| 175 | if initializer: |
| 176 | if isinstance(initializer, type): |
| 177 | initializer = initializer(self._dtype) |
| 178 | init_func = lambda: initializer(shape=self._segment_shape, dtype=self._dtype, partition_info=None) |
| 179 | |
| 180 | self._hash_table = hash_table |
| 181 | self._factory = function.Defun()(lambda: gen_hash_ops.copy_tensor(init_func())) |
| 182 | self._handle = gen_hash_ops.tensible_variable_op( |
| 183 | self._dtype, self._segment_shape, shared_name=handle_name, name=name) |
| 184 | with ops.control_dependencies([hash_table.initializer]): |
| 185 | self._initializer = self.initializer_without_hashtable(True, "Initializer") |
| 186 | self._false_initializer = self.initializer_without_hashtable(False, "FalseInitializer") |
| 187 | if collections is None: |
| 188 | collections = [ops.GraphKeys.GLOBAL_VARIABLES] |
| 189 | if not isinstance(collections, (list, tuple, set)): |
| 190 | raise ValueError( |
| 191 | "collections argument to Variable constructor must be a list, tuple, " |
| 192 | "or set. Got %s of type %s" % (collections, type(collections))) |
| 193 | trainable = trainable if trainable is not None else True |
| 194 | if trainable and ops.GraphKeys.TRAINABLE_VARIABLES not in collections: |
| 195 | collections = list(collections) + [ops.GraphKeys.TRAINABLE_VARIABLES] |
| 196 | ops.add_to_collections(collections, self) |
| 197 | |
| 198 | def __repr__(self): |
| 199 | return "<tf.hash_table.HashTable '%s' shape=%s dtype=%s" % ( |
nothing calls this directly
no test coverage detected