Processor for dense ResourceVariables.
| 176 | |
| 177 | |
| 178 | class _DenseResourceVariableProcessor(_OptimizableVariable): |
| 179 | """Processor for dense ResourceVariables.""" |
| 180 | |
| 181 | def __init__(self, v): |
| 182 | self._v = v |
| 183 | |
| 184 | def target(self): |
| 185 | return self._v |
| 186 | |
| 187 | def update_op(self, optimizer, g): |
| 188 | # pylint: disable=protected-access |
| 189 | if isinstance(g, ops.IndexedSlices): |
| 190 | if self._v.constraint is not None: |
| 191 | raise RuntimeError( |
| 192 | "Cannot use a constraint function on a sparse variable.") |
| 193 | return optimizer._resource_apply_sparse_duplicate_indices( |
| 194 | g.values, self._v, g.indices) |
| 195 | update_op = optimizer._resource_apply_dense(g, self._v) |
| 196 | if self._v.constraint is not None: |
| 197 | with ops.control_dependencies([update_op]): |
| 198 | return self._v.assign(self._v.constraint(self._v)) |
| 199 | else: |
| 200 | return update_op |
| 201 | |
| 202 | |
| 203 | class _HashTableProcessor(_OptimizableVariable): |