def sparse_read(self, indices, collections=None, trainable=True, name=None): """Reads the value of this variable sparsely, using `gather`.""" with ops.name_scope("Gather" if name is None else name): value = gen_resource_variable_ops.resource_gather( self._handle, indices, dtype=self._dtype) _register_variable_read(value, collections=collections, trainable=trainable) return array_ops.identity(value)
def sparse_read(self, indices, name=None): """Reads the value of this variable sparsely, using `gather`.""" with ops.name_scope("Gather" if name is None else name) as name: if self._trainable: tape.watch_variable(self) value = gen_resource_variable_ops.resource_gather( self._handle, indices, dtype=self._dtype, name=name) return array_ops.identity(value)
def sparse_read(self, indices, name=None): """Reads the value of this variable sparsely, using `gather`.""" with ops.name_scope("Gather" if name is None else name) as name: if self._trainable: tape.watch_variable(self) value = gen_resource_variable_ops.resource_gather( self._handle, indices, dtype=self._dtype, name=name) return array_ops.identity(value)
def sparse_read(self, indices, collections=None, trainable=True, name=None): with ops.name_scope("Gather" if name is None else name): value = gen_resource_variable_ops.resource_gather( self._handle, indices, dtype=self._dtype) _register_variable_read(value, collections=collections, trainable=trainable) return value
def resource_gather(resource, indices, dtype, validate_indices=True, name=None): """Gather slices from the variable pointed to by `resource`. `indices` must be an integer tensor of any dimension (usually 0-D or 1-D). Produces an output tensor with shape `indices.shape + params.shape[1:]` where: ```python # Scalar indices output[:, ..., :] = params[indices, :, ... :] # Vector indices output[i, :, ..., :] = params[indices[i], :, ... :] # Higher rank indices output[i, ..., j, :, ... :] = params[indices[i, ..., j], :, ..., :] ``` Args: resource: A `Tensor` of type `resource`. handle to the resource in which to store the variable. indices: a integer `Tensor` containing the indices to be gathered. dtype: A `tf.DType`. the dtype of the value. validate_indices: optional `bool`. If false will not validate that the indices fit in the variable. name: The optional name for the operation to be added. Returns: A `Tensor` of type `dtype`. """ result = gen_resource_variable_ops.resource_gather( resource, indices, dtype, validate_indices=validate_indices, name=name) def grad(dresult): return ops.IndexedSlices(dresult, indices, dense_shape=ops.convert_to_tensor( resource._variable_shape)) # pylint: disable=protected-access return result, grad
def resource_gather(resource, indices, dtype, validate_indices=True, name=None): """Gather slices from the variable pointed to by `resource`. `indices` must be an integer tensor of any dimension (usually 0-D or 1-D). Produces an output tensor with shape `indices.shape + params.shape[1:]` where: ```python # Scalar indices output[:, ..., :] = params[indices, :, ... :] # Vector indices output[i, :, ..., :] = params[indices[i], :, ... :] # Higher rank indices output[i, ..., j, :, ... :] = params[indices[i, ..., j], :, ..., :] ``` Args: resource: A `Tensor` of type `resource`. handle to the resource in which to store the variable. indices: a integer `Tensor` containing the indices to be gathered. dtype: A `tf.DType`. the dtype of the value. validate_indices: optional `bool`. If false will not validate that the indices fit in the variable. name: The optional name for the operation to be added. Returns: A `Tensor` of type `dtype`. """ result = gen_resource_variable_ops.resource_gather( resource, indices, dtype, validate_indices=validate_indices, name=name) def grad(dresult): return ops.IndexedSlices( dresult, indices, dense_shape=gen_resource_variable_ops.variable_shape(resource)) return result, grad
def sparse_read(self, indices, collections=None, trainable=True, name=None): with ops.name_scope("Gather" if name is None else name): value = gen_resource_variable_ops.resource_gather( self._handle, indices, dtype=self._dtype) _register_variable_read(value, collections=collections, trainable=trainable) return value