class_docstr: Test cases for resource variable operators.
class_docstr_tok: ["Test","cases","for","resource","variable","operators","."]
docstr: Tests a gradient descent step for a simple model.
code: def testTraining(self):
      """Tests a gradient descent step for a simple model."""
      with self.session() as session:
          with self.test_scope():
              with variable_scope.variable_scope(
                  "ascope", use_resource=True
              ):
                  w = variable_scope.get_variable(
                      "w",
                      shape=[4, 2],
                      dtype=dtypes.float32,
                      initializer=init_ops.constant_initializer(
                          np.array(
                              [[1, 2], [3, 4], [5, 6], [7, 8]],
                              dtype=np.float32,
                          )
                      ),
                  )
                  b = variable_scope.get_variable(
                      "b",
                      shape=[2],
                      dtype=dtypes.float32,
                      initializer=init_ops.constant_initializer(
                          np.array([2, 3], dtype=np.float32)
                      ),
                  )
  
                  x = array_ops.placeholder(
                      dtypes.float32, shape=[1, 4]
                  )
                  y = math_ops.matmul(x, w) + b
                  loss = math_ops.reduce_sum(y)
                  optimizer = GradientDescentOptimizer(0.1)
                  train = optimizer.minimize(loss)
  
          session.run(variables.global_variables_initializer())
          session.run(
              train, {x: np.array([[7, 3, 5, 9]], dtype=np.float32)}
          )
          vw, vb = session.run([w, b])
          self.assertAllClose(
              np.array(
                  [[0.3, 1.3], [2.7, 3.7], [4.5, 5.5], [6.1, 7.1]],
                  dtype=np.float32,
              ),
              vw,
              rtol=1e-4,
          )
          self.assertAllClose(
              np.array([1.9, 2.9], dtype=np.float32), vb, rtol=1e-4
          )
  
imports: import re
  import numpy
  from tensorflow.compiler.tests import xla_test
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import errors
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import test_util
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import gen_state_ops
  from tensorflow.python.ops import init_ops
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import resource_variable_ops
  from tensorflow.python.ops import state_ops
  from tensorflow.python.ops import variable_scope
  from tensorflow.python.ops import variables
  from tensorflow.python.platform import googletest
  from tensorflow.python.training.gradient_descent import GradientDescentOptimizer
label_desc: Use image node_id 10 for calling the VariableOpsTest obj's underlying member method code with example usage: obj.testTraining() without return types