code: def testTensorGradArrayDynamicWriteRead(self):
      with self.session() as session, self.test_scope():
  
          def fn():
              ta = tensor_array_ops.TensorArray(
                  dtype=dtypes.float32, tensor_array_name="foo", size=3
              )
  
              w0 = ta.write(0, [[4.0]])
              w1 = w0.write(1, [[1.0]])
              w2 = w1.write(2, [[-3.0]])
  
              g_ta = w2.grad(
                  "grad"
              )  # Get gradient array here so we know the shape
  
              s = w2.size()
              g_s = g_ta.size()
  
              g_w0 = g_ta.write(0, [[5.0]])
              g_w1 = g_w0.write(1, [[2.0]])
              g_w2 = g_w1.write(2, [[-2.0]])
  
              r0 = w2.read(0)
              r1 = w2.read(1)
              r2 = w2.read(2)
  
              g_r0 = g_w2.read(0)
              g_r1 = g_w2.read(1)
              g_r2 = g_w2.read(2)
  
              return [r0, r1, r2, g_r0, g_r1, g_r2, s, g_s]
  
          d0, d1, d2, g_d0, g_d1, g_d2, vs, g_vs = self.evaluate(
              xla.compile(fn)
          )
          self.assertAllEqual([[4.0]], d0)
          self.assertAllEqual([[1.0]], d1)
          self.assertAllEqual([[-3.0]], d2)
          self.assertAllEqual([[5.0]], g_d0)
          self.assertAllEqual([[2.0]], g_d1)
          self.assertAllEqual([[-2.0]], g_d2)
          self.assertAllEqual(3, vs)
          self.assertAllEqual(3, g_vs)
  
imports: import numpy
  from tensorflow.compiler.tests import xla_test
  from tensorflow.python.compiler.xla import xla
  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 control_flow_util
  from tensorflow.python.ops import gen_data_flow_ops
  from tensorflow.python.ops import gradients_impl
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops import resource_variable_ops
  from tensorflow.python.ops import tensor_array_grad
  from tensorflow.python.ops import tensor_array_ops
  from tensorflow.python.ops import variables
  from tensorflow.python.platform import test
label_desc: Use image node_id 13 for calling the TensorArrayTest obj's underlying member method code with example usage: obj.testTensorGradArrayDynamicWriteRead() and returns: list