# Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""tensor_util tests."""

# pylint: disable=unused-import
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import re

import numpy as np

from tensorflow.contrib.framework.python.framework import tensor_util
from tensorflow.contrib.framework.python.ops import variables as variables_lib2
from tensorflow.python.framework import constant_op
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import errors_impl
from tensorflow.python.framework import ops
from tensorflow.python.framework import tensor_shape
from tensorflow.python.framework import test_util
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import variables as variables_lib
from tensorflow.python.platform import test


class LocalVariabletest(test.TestCase):

  def test_local_variable(self):
    with self.cached_session() as sess:
      self.assertEquals([], variables_lib.local_variables())
      value0 = 42
      variables_lib2.local_variable(value0)
      value1 = 43
      variables_lib2.local_variable(value1)
      variables = variables_lib.local_variables()
      self.assertEquals(2, len(variables))
      self.assertRaises(errors_impl.OpError, sess.run, variables)
      variables_lib.variables_initializer(variables).run()
      self.assertAllEqual(set([value0, value1]), set(sess.run(variables)))


class ReduceSumNTest(test.TestCase):

  def test_reduce_sum_n(self):
    with self.cached_session():
      a = constant_op.constant(1)
      b = constant_op.constant([2])
      c = constant_op.constant([[3, 4], [5, 6]])
      self.assertEqual(21, tensor_util.reduce_sum_n([a, b, c]).eval())


class AssertScalarIntTest(test.TestCase):

  def test_assert_scalar_int(self):
    tensor_util.assert_scalar_int(constant_op.constant(3, dtype=dtypes.int32))
    tensor_util.assert_scalar_int(constant_op.constant(3, dtype=dtypes.int64))
    tensor_util.assert_scalar_int(3)
    with self.assertRaisesRegexp(ValueError, "Expected integer"):
      tensor_util.assert_scalar_int(
          constant_op.constant(
              3, dtype=dtypes.float32))
    with self.assertRaisesRegexp(ValueError, "Expected scalar"):
      tensor_util.assert_scalar_int(
          constant_op.constant(
              [3, 4], dtype=dtypes.int32))


class WithShapeTest(test.TestCase):

  def _assert_with_shape(self, tensor, expected_value, expected_shape,
                         unexpected_shapes):
    for unexpected_shape in unexpected_shapes:
      self.assertRaises(ValueError, tensor_util.with_shape, unexpected_shape,
                        tensor)
      pattern = (
          r"\[Wrong shape for %s \[expected\] \[actual\].\] \[%s\] \[%s\]" %
          (tensor.name, " ".join([str(dim) for dim in unexpected_shape]),
           " ".join([str(dim) for dim in expected_shape])))
      self.assertRaisesRegexp(errors_impl.OpError,
                              re.compile(pattern),
                              tensor_util.with_shape(
                                  constant_op.constant(unexpected_shape),
                                  tensor).eval)
      expected_placeholder = array_ops.placeholder(dtypes.float32)
      self.assertRaisesRegexp(errors_impl.OpError,
                              re.compile(pattern),
                              tensor_util.with_same_shape(expected_placeholder,
                                                          tensor).eval,
                              {expected_placeholder: np.ones(unexpected_shape)})

    self.assertIs(tensor, tensor_util.with_shape(expected_shape, tensor))
    self.assertIs(
        tensor,
        tensor_util.with_same_shape(
            constant_op.constant(
                1, shape=expected_shape), tensor))
    tensor_with_shape = tensor_util.with_shape(
        constant_op.constant(expected_shape), tensor)
    np.testing.assert_array_equal(expected_value, tensor_with_shape.eval())
    tensor_with_same_shape = tensor_util.with_same_shape(expected_placeholder,
                                                         tensor)
    np.testing.assert_array_equal(expected_value,
                                  tensor_with_same_shape.eval({
                                      expected_placeholder:
                                          np.ones(expected_shape)
                                  }))

  def test_with_shape_invalid_expected_shape(self):
    with self.cached_session():
      self.assertRaisesRegexp(ValueError, "Invalid rank",
                              tensor_util.with_shape, [[1], [2]],
                              constant_op.constant(1.0))

  def test_with_shape_invalid_type(self):
    with self.cached_session():
      self.assertRaisesRegexp(ValueError, "Invalid dtype",
                              tensor_util.with_shape, [1.1],
                              constant_op.constant([1.0]))
      self.assertRaisesRegexp(ValueError, "Invalid dtype",
                              tensor_util.with_shape,
                              np.array([1.1]), constant_op.constant(1.0))
      self.assertRaisesRegexp(ValueError, "Invalid dtype",
                              tensor_util.with_shape,
                              constant_op.constant(np.array([1.1])),
                              constant_op.constant(1.0))

  def test_with_shape_0(self):
    with self.cached_session():
      value = 42
      shape = [0]
      unexpected_shapes = [[1], [2], [1, 1]]
      self._assert_with_shape(
          constant_op.constant(
              value, shape=shape),
          value,
          shape,
          unexpected_shapes)

  def test_with_shape_1(self):
    with self.cached_session():
      value = [42]
      shape = [1]
      unexpected_shapes = [[0], [2], [1, 1]]
      self._assert_with_shape(
          constant_op.constant(
              value, shape=shape),
          value,
          shape,
          unexpected_shapes)

  def test_with_shape_2(self):
    with self.cached_session():
      value = [42, 43]
      shape = [2]
      unexpected_shapes = [[0], [1], [2, 1]]
      self._assert_with_shape(
          constant_op.constant(
              value, shape=shape),
          value,
          shape,
          unexpected_shapes)

  def test_with_shape_2x2(self):
    with self.cached_session():
      value = [[42, 43], [44, 45]]
      shape = [2, 2]
      unexpected_shapes = [[0], [1], [2, 1]]
      self._assert_with_shape(
          constant_op.constant(
              value, shape=shape),
          value,
          shape,
          unexpected_shapes)

  def test_with_shape_2x2_with_partial_expected_shape(self):
    with self.cached_session():
      value = [[42, 43], [44, 45]]
      actual_shape = [2, 2]
      tensor = constant_op.constant(value, shape=actual_shape)
      partial_expected_shape = tensor_shape.TensorShape([None, 2])
      # Won't raise any exception here:
      tensor_with_shape = tensor_util.with_shape(partial_expected_shape, tensor)
      np.testing.assert_array_equal(value, tensor_with_shape.eval())

  def test_with_shape_none(self):
    with self.cached_session():
      tensor_no_shape = array_ops.placeholder(dtypes.float32)

      compatible_shape = [2, 2]
      with_present_2x2 = tensor_util.with_shape(compatible_shape,
                                                tensor_no_shape)
      self.assertEquals(compatible_shape, with_present_2x2.get_shape().dims)
      with_future_2x2 = tensor_util.with_shape(
          constant_op.constant(compatible_shape), tensor_no_shape)

      array_2x2 = [[42.0, 43.0], [44.0, 45.0]]
      for tensor_2x2 in [with_present_2x2, with_future_2x2]:
        np.testing.assert_array_equal(array_2x2,
                                      tensor_2x2.eval({
                                          tensor_no_shape: array_2x2
                                      }))
        self.assertRaisesRegexp(errors_impl.OpError, "Wrong shape",
                                tensor_2x2.eval,
                                {tensor_no_shape: [42.0, 43.0]})
        self.assertRaisesRegexp(errors_impl.OpError, "Wrong shape",
                                tensor_2x2.eval, {tensor_no_shape: [42.0]})

  def test_with_shape_partial(self):
    with self.cached_session():
      tensor_partial_shape = array_ops.placeholder(dtypes.float32)
      tensor_partial_shape.set_shape([None, 2])

      for incompatible_shape in [[0], [1]]:
        self.assertRaisesRegexp(
            ValueError, "Shapes must be equal rank, but are 2 and 1",
            tensor_util.with_shape, incompatible_shape, tensor_partial_shape)
      for incompatible_shape in [[1, 2, 1]]:
        self.assertRaisesRegexp(ValueError, "Dimensions must be equal",
                                tensor_util.with_shape, incompatible_shape,
                                tensor_partial_shape)
      for incompatible_shape in [[2, 1]]:
        self.assertRaisesRegexp(
            ValueError,
            r"Dimension 1 in both shapes must be equal, but are 2 and 1. "
            r"Shapes are \[\?,2\] and \[2,1\].",
            tensor_util.with_shape, incompatible_shape, tensor_partial_shape)

      compatible_shape = [2, 2]
      with_present_2x2 = tensor_util.with_shape(compatible_shape,
                                                tensor_partial_shape)
      self.assertEquals(compatible_shape, with_present_2x2.get_shape().dims)
      with_future_2x2 = tensor_util.with_shape(
          constant_op.constant(compatible_shape), tensor_partial_shape)

      array_2x2 = [[42.0, 43.0], [44.0, 45.0]]
      for tensor_2x2 in [with_present_2x2, with_future_2x2]:
        np.testing.assert_array_equal(array_2x2,
                                      tensor_2x2.eval({
                                          tensor_partial_shape: array_2x2
                                      }))
        self.assertRaises(ValueError, tensor_2x2.eval,
                          {tensor_partial_shape: [42.0, 43.0]})
        self.assertRaises(ValueError, tensor_2x2.eval,
                          {tensor_partial_shape: [42.0]})


class RemoveSqueezableDimensionsTest(test.TestCase):

  def testRemoveSqueezableDimensions(self):
    self._testRemoveSqueezableDimensions(
        predictions_have_static_shape=False,
        predictions_have_extra_dim=False,
        labels_have_static_shape=False,
        labels_have_extra_dim=False)

  def testRemoveSqueezableDimensions_extraLabelDim(self):
    self._testRemoveSqueezableDimensions(
        predictions_have_static_shape=False,
        predictions_have_extra_dim=False,
        labels_have_static_shape=False,
        labels_have_extra_dim=True)

  def testRemoveSqueezableDimensions_staticLabel(self):
    self._testRemoveSqueezableDimensions(
        predictions_have_static_shape=False,
        predictions_have_extra_dim=False,
        labels_have_static_shape=True,
        labels_have_extra_dim=False)

  def testRemoveSqueezableDimensions_staticLabel_extraLabelDim(self):
    self._testRemoveSqueezableDimensions(
        predictions_have_static_shape=False,
        predictions_have_extra_dim=False,
        labels_have_static_shape=True,
        labels_have_extra_dim=True)

  def testRemoveSqueezableDimensions_extraPredictionDim(self):
    self._testRemoveSqueezableDimensions(
        predictions_have_static_shape=False,
        predictions_have_extra_dim=True,
        labels_have_static_shape=False,
        labels_have_extra_dim=False)

  def testRemoveSqueezableDimensions_extraPredictionDim_staticLabel(self):
    self._testRemoveSqueezableDimensions(
        predictions_have_static_shape=False,
        predictions_have_extra_dim=True,
        labels_have_static_shape=True,
        labels_have_extra_dim=False)

  def testRemoveSqueezableDimensions_staticPrediction(self):
    self._testRemoveSqueezableDimensions(
        predictions_have_static_shape=True,
        predictions_have_extra_dim=False,
        labels_have_static_shape=False,
        labels_have_extra_dim=False)

  def testRemoveSqueezableDimensions_staticPrediction_extraLabelDim(self):
    self._testRemoveSqueezableDimensions(
        predictions_have_static_shape=True,
        predictions_have_extra_dim=False,
        labels_have_static_shape=False,
        labels_have_extra_dim=True)

  def testRemoveSqueezableDimensions_static(self):
    self._testRemoveSqueezableDimensions(
        predictions_have_static_shape=True,
        predictions_have_extra_dim=False,
        labels_have_static_shape=True,
        labels_have_extra_dim=False)

  def testRemoveSqueezableDimensions_static_extraLabelDim(self):
    self._testRemoveSqueezableDimensions(
        predictions_have_static_shape=True,
        predictions_have_extra_dim=False,
        labels_have_static_shape=True,
        labels_have_extra_dim=True)

  def testRemoveSqueezableDimensions_staticPrediction_extraPredictionDim(self):
    self._testRemoveSqueezableDimensions(
        predictions_have_static_shape=True,
        predictions_have_extra_dim=True,
        labels_have_static_shape=False,
        labels_have_extra_dim=False)

  def testRemoveSqueezableDimensions_static_extraPredictionDim(self):
    self._testRemoveSqueezableDimensions(
        predictions_have_static_shape=True,
        predictions_have_extra_dim=True,
        labels_have_static_shape=True,
        labels_have_extra_dim=False)

  # TODO(ptucker): Replace this with parameterized test.
  def _testRemoveSqueezableDimensions(self, predictions_have_static_shape,
                                      predictions_have_extra_dim,
                                      labels_have_static_shape,
                                      labels_have_extra_dim):
    assert not (predictions_have_extra_dim and labels_have_extra_dim)
    predictions_value = (0, 1, 1, 0, 0, 1, 0)
    labels_value = (0, 0, 1, 1, 0, 0, 0)

    input_predictions_value = ([[p] for p in predictions_value] if
                               predictions_have_extra_dim else
                               predictions_value)
    input_labels_value = ([[l] for l in labels_value] if labels_have_extra_dim
                          else labels_value)

    with ops.Graph().as_default() as g:
      feed_dict = {}
      if predictions_have_static_shape:
        predictions = constant_op.constant(
            input_predictions_value, dtype=dtypes.int32)
      else:
        predictions = array_ops.placeholder(
            dtype=dtypes.int32, name="predictions")
        feed_dict[predictions] = input_predictions_value
      if labels_have_static_shape:
        labels = constant_op.constant(input_labels_value, dtype=dtypes.int32)
      else:
        labels = array_ops.placeholder(dtype=dtypes.int32, name="labels")
        feed_dict[labels] = input_labels_value

      squeezed_predictions, squeezed_labels = (
          tensor_util.remove_squeezable_dimensions(predictions, labels))
      with self.session(g):
        variables_lib.local_variables_initializer().run()
        self.assertAllClose(
            predictions_value, squeezed_predictions.eval(feed_dict=feed_dict))
        self.assertAllClose(
            labels_value, squeezed_labels.eval(feed_dict=feed_dict))


if __name__ == "__main__":
  test.main()

[((387, 2, 387, 13), 'tensorflow.python.platform.test.main', 'test.main', ({}, {}), '()', False, 'from tensorflow.python.platform import test\n'), ((70, 4, 70, 36), 'tensorflow.contrib.framework.python.framework.tensor_util.assert_scalar_int', 'tensor_util.assert_scalar_int', ({(70, 34, 70, 35): '(3)'}, {}), '(3)', False, 'from tensorflow.contrib.framework.python.framework import tensor_util\n'), ((113, 29, 114, 64), 'tensorflow.contrib.framework.python.framework.tensor_util.with_same_shape', 'tensor_util.with_same_shape', ({(113, 57, 113, 77): 'expected_placeholder', (114, 57, 114, 63): 'tensor'}, {}), '(expected_placeholder, tensor)', False, 'from tensorflow.contrib.framework.python.framework import tensor_util\n'), ((45, 6, 45, 43), 'tensorflow.contrib.framework.python.ops.variables.local_variable', 'variables_lib2.local_variable', ({(45, 36, 45, 42): 'value0'}, {}), '(value0)', True, 'from tensorflow.contrib.framework.python.ops import variables as variables_lib2\n'), ((47, 6, 47, 43), 'tensorflow.contrib.framework.python.ops.variables.local_variable', 'variables_lib2.local_variable', ({(47, 36, 47, 42): 'value1'}, {}), '(value1)', True, 'from tensorflow.contrib.framework.python.ops import variables as variables_lib2\n'), ((48, 18, 48, 49), 'tensorflow.python.ops.variables.local_variables', 'variables_lib.local_variables', ({}, {}), '()', True, 'from tensorflow.python.ops import variables as variables_lib\n'), ((59, 10, 59, 33), 'tensorflow.python.framework.constant_op.constant', 'constant_op.constant', ({(59, 31, 59, 32): '1'}, {}), '(1)', False, 'from tensorflow.python.framework import constant_op\n'), ((60, 10, 60, 35), 'tensorflow.python.framework.constant_op.constant', 'constant_op.constant', ({(60, 31, 60, 34): '[2]'}, {}), '([2])', False, 'from tensorflow.python.framework import constant_op\n'), ((61, 10, 61, 48), 'tensorflow.python.framework.constant_op.constant', 'constant_op.constant', ({(61, 31, 61, 47): '[[3, 4], [5, 6]]'}, {}), '([[3, 4], [5, 6]])', False, 'from tensorflow.python.framework import constant_op\n'), ((68, 34, 68, 77), 'tensorflow.python.framework.constant_op.constant', 'constant_op.constant', (), '', False, 'from tensorflow.python.framework import constant_op\n'), ((69, 34, 69, 77), 'tensorflow.python.framework.constant_op.constant', 'constant_op.constant', (), '', False, 'from tensorflow.python.framework import constant_op\n'), ((97, 29, 97, 66), 'tensorflow.python.ops.array_ops.placeholder', 'array_ops.placeholder', ({(97, 51, 97, 65): 'dtypes.float32'}, {}), '(dtypes.float32)', False, 'from tensorflow.python.ops import array_ops\n'), ((104, 26, 104, 72), 'tensorflow.contrib.framework.python.framework.tensor_util.with_shape', 'tensor_util.with_shape', ({(104, 49, 104, 63): 'expected_shape', (104, 65, 104, 71): 'tensor'}, {}), '(expected_shape, tensor)', False, 'from tensorflow.contrib.framework.python.framework import tensor_util\n'), ((111, 8, 111, 44), 'tensorflow.python.framework.constant_op.constant', 'constant_op.constant', ({(111, 29, 111, 43): 'expected_shape'}, {}), '(expected_shape)', False, 'from tensorflow.python.framework import constant_op\n'), ((192, 15, 192, 62), 'tensorflow.python.framework.constant_op.constant', 'constant_op.constant', (), '', False, 'from tensorflow.python.framework import constant_op\n'), ((193, 31, 193, 66), 'tensorflow.python.framework.tensor_shape.TensorShape', 'tensor_shape.TensorShape', ({(193, 56, 193, 65): '[None, 2]'}, {}), '([None, 2])', False, 'from tensorflow.python.framework import tensor_shape\n'), ((195, 26, 195, 80), 'tensorflow.contrib.framework.python.framework.tensor_util.with_shape', 'tensor_util.with_shape', ({(195, 49, 195, 71): 'partial_expected_shape', (195, 73, 195, 79): 'tensor'}, {}), '(partial_expected_shape, tensor)', False, 'from tensorflow.contrib.framework.python.framework import tensor_util\n'), ((200, 24, 200, 61), 'tensorflow.python.ops.array_ops.placeholder', 'array_ops.placeholder', ({(200, 46, 200, 60): 'dtypes.float32'}, {}), '(dtypes.float32)', False, 'from tensorflow.python.ops import array_ops\n'), ((203, 25, 204, 64), 'tensorflow.contrib.framework.python.framework.tensor_util.with_shape', 'tensor_util.with_shape', ({(203, 48, 203, 64): 'compatible_shape', (204, 48, 204, 63): 'tensor_no_shape'}, {}), '(compatible_shape, tensor_no_shape)', False, 'from tensorflow.contrib.framework.python.framework import tensor_util\n'), ((223, 29, 223, 66), 'tensorflow.python.ops.array_ops.placeholder', 'array_ops.placeholder', ({(223, 51, 223, 65): 'dtypes.float32'}, {}), '(dtypes.float32)', False, 'from tensorflow.python.ops import array_ops\n'), ((242, 25, 243, 69), 'tensorflow.contrib.framework.python.framework.tensor_util.with_shape', 'tensor_util.with_shape', ({(242, 48, 242, 64): 'compatible_shape', (243, 48, 243, 68): 'tensor_partial_shape'}, {}), '(compatible_shape, tensor_partial_shape)', False, 'from tensorflow.contrib.framework.python.framework import tensor_util\n'), ((377, 10, 377, 71), 'tensorflow.contrib.framework.python.framework.tensor_util.remove_squeezable_dimensions', 'tensor_util.remove_squeezable_dimensions', ({(377, 51, 377, 62): 'predictions', (377, 64, 377, 70): 'labels'}, {}), '(predictions, labels)', False, 'from tensorflow.contrib.framework.python.framework import tensor_util\n'), ((43, 28, 43, 59), 'tensorflow.python.ops.variables.local_variables', 'variables_lib.local_variables', ({}, {}), '()', True, 'from tensorflow.python.ops import variables as variables_lib\n'), ((73, 10, 74, 38), 'tensorflow.python.framework.constant_op.constant', 'constant_op.constant', (), '', False, 'from tensorflow.python.framework import constant_op\n'), ((77, 10, 78, 41), 'tensorflow.python.framework.constant_op.constant', 'constant_op.constant', (), '', False, 'from tensorflow.python.framework import constant_op\n'), ((93, 30, 93, 49), 're.compile', 're.compile', ({(93, 41, 93, 48): 'pattern'}, {}), '(pattern)', False, 'import re\n'), ((99, 30, 99, 49), 're.compile', 're.compile', ({(99, 41, 99, 48): 'pattern'}, {}), '(pattern)', False, 'import re\n'), ((108, 12, 109, 40), 'tensorflow.python.framework.constant_op.constant', 'constant_op.constant', (), '', False, 'from tensorflow.python.framework import constant_op\n'), ((125, 30, 125, 55), 'tensorflow.python.framework.constant_op.constant', 'constant_op.constant', ({(125, 51, 125, 54): '(1.0)'}, {}), '(1.0)', False, 'from tensorflow.python.framework import constant_op\n'), ((131, 30, 131, 57), 'tensorflow.python.framework.constant_op.constant', 'constant_op.constant', ({(131, 51, 131, 56): '[1.0]'}, {}), '([1.0])', False, 'from tensorflow.python.framework import constant_op\n'), ((134, 30, 134, 45), 'numpy.array', 'np.array', ({(134, 39, 134, 44): '[1.1]'}, {}), '([1.1])', True, 'import numpy as np\n'), ((134, 47, 134, 72), 'tensorflow.python.framework.constant_op.constant', 'constant_op.constant', ({(134, 68, 134, 71): '(1.0)'}, {}), '(1.0)', False, 'from tensorflow.python.framework import constant_op\n'), ((138, 30, 138, 55), 'tensorflow.python.framework.constant_op.constant', 'constant_op.constant', ({(138, 51, 138, 54): '(1.0)'}, {}), '(1.0)', False, 'from tensorflow.python.framework import constant_op\n'), ((146, 10, 147, 33), 'tensorflow.python.framework.constant_op.constant', 'constant_op.constant', (), '', False, 'from tensorflow.python.framework import constant_op\n'), ((158, 10, 159, 33), 'tensorflow.python.framework.constant_op.constant', 'constant_op.constant', (), '', False, 'from tensorflow.python.framework import constant_op\n'), ((170, 10, 171, 33), 'tensorflow.python.framework.constant_op.constant', 'constant_op.constant', (), '', False, 'from tensorflow.python.framework import constant_op\n'), ((182, 10, 183, 33), 'tensorflow.python.framework.constant_op.constant', 'constant_op.constant', (), '', False, 'from tensorflow.python.framework import constant_op\n'), ((207, 10, 207, 48), 'tensorflow.python.framework.constant_op.constant', 'constant_op.constant', ({(207, 31, 207, 47): 'compatible_shape'}, {}), '(compatible_shape)', False, 'from tensorflow.python.framework import constant_op\n'), ((246, 10, 246, 48), 'tensorflow.python.framework.constant_op.constant', 'constant_op.constant', ({(246, 31, 246, 47): 'compatible_shape'}, {}), '(compatible_shape)', False, 'from tensorflow.python.framework import constant_op\n'), ((364, 22, 365, 56), 'tensorflow.python.framework.constant_op.constant', 'constant_op.constant', (), '', False, 'from tensorflow.python.framework import constant_op\n'), ((367, 22, 368, 51), 'tensorflow.python.ops.array_ops.placeholder', 'array_ops.placeholder', (), '', False, 'from tensorflow.python.ops import array_ops\n'), ((371, 17, 371, 77), 'tensorflow.python.framework.constant_op.constant', 'constant_op.constant', (), '', False, 'from tensorflow.python.framework import constant_op\n'), ((373, 17, 373, 73), 'tensorflow.python.ops.array_ops.placeholder', 'array_ops.placeholder', (), '', False, 'from tensorflow.python.ops import array_ops\n'), ((51, 6, 51, 52), 'tensorflow.python.ops.variables.variables_initializer', 'variables_lib.variables_initializer', ({(51, 42, 51, 51): 'variables'}, {}), '(variables)', True, 'from tensorflow.python.ops import variables as variables_lib\n'), ((100, 30, 101, 65), 'tensorflow.contrib.framework.python.framework.tensor_util.with_same_shape', 'tensor_util.with_same_shape', ({(100, 58, 100, 78): 'expected_placeholder', (101, 58, 101, 64): 'tensor'}, {}), '(expected_placeholder, tensor)', False, 'from tensorflow.contrib.framework.python.framework import tensor_util\n'), ((102, 53, 102, 78), 'numpy.ones', 'np.ones', ({(102, 61, 102, 77): 'unexpected_shape'}, {}), '(unexpected_shape)', True, 'import numpy as np\n'), ((118, 42, 118, 65), 'numpy.ones', 'np.ones', ({(118, 50, 118, 64): 'expected_shape'}, {}), '(expected_shape)', True, 'import numpy as np\n'), ((137, 51, 137, 66), 'numpy.array', 'np.array', ({(137, 60, 137, 65): '[1.1]'}, {}), '([1.1])', True, 'import numpy as np\n'), ((361, 9, 361, 20), 'tensorflow.python.framework.ops.Graph', 'ops.Graph', ({}, {}), '()', False, 'from tensorflow.python.framework import ops\n'), ((62, 27, 62, 62), 'tensorflow.contrib.framework.python.framework.tensor_util.reduce_sum_n', 'tensor_util.reduce_sum_n', ({(62, 52, 62, 61): '[a, b, c]'}, {}), '([a, b, c])', False, 'from tensorflow.contrib.framework.python.framework import tensor_util\n'), ((95, 34, 95, 72), 'tensorflow.python.framework.constant_op.constant', 'constant_op.constant', ({(95, 55, 95, 71): 'unexpected_shape'}, {}), '(unexpected_shape)', False, 'from tensorflow.python.framework import constant_op\n'), ((379, 8, 379, 51), 'tensorflow.python.ops.variables.local_variables_initializer', 'variables_lib.local_variables_initializer', ({}, {}), '()', True, 'from tensorflow.python.ops import variables as variables_lib\n')]