def initialize_from(self, keys, values, name=None): """Initialize the table with the provided keys and values tensors. Construct an initializer object from keys and value tensors. Args: keys: The tensor for the keys. values: The tensor for the values. name: Optional name for the op. Returns: The operation that initializes the table. Raises: TypeError: when the keys and values data types do not match the table key and value data types. """ if name is None: name = "%s_initialize_table" % self.name with ops.op_scope([keys, values], None, name): keys = ops.convert_to_tensor(keys, dtype=self.key_dtype, name="keys") values = ops.convert_to_tensor(values, dtype=self.value_dtype, name="values") init_op = gen_data_flow_ops._initialize_table(self.table_ref, keys, values, name=name) ops.add_to_collection(ops.GraphKeys.TABLE_INITIALIZERS, init_op) return init_op
def initialize_from(self, keys, values, name=None): """Initialize the lookup table with the provided keys and values tensors. Construct an initializer object from keys and value tensors. Args: keys: The tensor for the keys. values: The tensor for the values. name: Optional name for the op. Returns: The operation that initializes a lookup table. Raises: TypeError: when the 'keys' and 'values' data type do not match the table key and value data types. """ if name is None: name = "%s_initialize_table" % self.name with ops.op_scope([keys, values], None, name): keys = ops.convert_to_tensor(keys, dtype=self.key_dtype, name="keys") values = ops.convert_to_tensor(values, dtype=self.value_dtype, name="values") init_op = gen_data_flow_ops._initialize_table(self.table_ref, keys, values, name=name) ops.add_to_collection(ops.GraphKeys.TABLE_INITIALIZERS, init_op) return init_op
def initialize(self, table): """Initializes the given `table` with `keys` and `values` tensors. Args: table: The table to initialize. Returns: The operation that initializes the table. Raises: TypeError: when the keys and values data types do not match the table key and value data types. """ # pylint: disable=protected-access table._check_table_dtypes(self._keys.dtype, self._values.dtype) with ops.name_scope(self._name, values=[table]) as scope: init_op = gen_data_flow_ops._initialize_table(table.table_ref, self._keys, self._values, name=scope) # pylint: enable=protected-access ops.add_to_collection(ops.GraphKeys.TABLE_INITIALIZERS, init_op) return init_op