# Copyright 2018 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.
# ==============================================================================
"""Tests for tensorflow.ops.tf.Lu."""

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import numpy as np

from tensorflow.python.client import session
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_ops
from tensorflow.python.ops import linalg_ops
from tensorflow.python.ops import map_fn
from tensorflow.python.ops import math_ops
from tensorflow.python.ops import random_ops
from tensorflow.python.ops import variables
from tensorflow.python.platform import benchmark
from tensorflow.python.platform import test


class LuOpTest(test.TestCase):

  @property
  def float_types(self):
    return set((np.float64, np.float32, np.complex64, np.complex128))

  def _verifyLuBase(self, x, lower, upper, perm, verification,
                    output_idx_type):
    lower_np, upper_np, perm_np, verification_np = self.evaluate(
        [lower, upper, perm, verification])

    self.assertAllClose(x, verification_np)
    self.assertShapeEqual(x, lower)
    self.assertShapeEqual(x, upper)

    self.assertAllEqual(x.shape[:-1], perm.shape.as_list())

    # Check dtypes are as expected.
    self.assertEqual(x.dtype, lower_np.dtype)
    self.assertEqual(x.dtype, upper_np.dtype)
    self.assertEqual(output_idx_type.as_numpy_dtype, perm_np.dtype)

    # Check that the permutation is valid.
    if perm_np.shape[-1] > 0:
      perm_reshaped = np.reshape(perm_np, (-1, perm_np.shape[-1]))
      for perm_vector in perm_reshaped:
        self.assertAllClose(np.arange(len(perm_vector)), np.sort(perm_vector))

  def _verifyLu(self, x, output_idx_type=dtypes.int64):
    # Verify that Px = LU.
    lu, perm = linalg_ops.lu(x, output_idx_type=output_idx_type)

    # Prepare the lower factor of shape num_rows x num_rows
    lu_shape = np.array(lu.shape.as_list())
    batch_shape = lu_shape[:-2]
    num_rows = lu_shape[-2]
    num_cols = lu_shape[-1]

    lower = array_ops.matrix_band_part(lu, -1, 0)

    if num_rows > num_cols:
      eye = linalg_ops.eye(
          num_rows, batch_shape=batch_shape, dtype=lower.dtype)
      lower = array_ops.concat([lower, eye[..., num_cols:]], axis=-1)
    elif num_rows < num_cols:
      lower = lower[..., :num_rows]

    # Fill the diagonal with ones.
    ones_diag = array_ops.ones(
        np.append(batch_shape, num_rows), dtype=lower.dtype)
    lower = array_ops.matrix_set_diag(lower, ones_diag)

    # Prepare the upper factor.
    upper = array_ops.matrix_band_part(lu, 0, -1)

    verification = math_ops.matmul(lower, upper)

    # Permute the rows of product of the Cholesky factors.
    if num_rows > 0:
      # Reshape the product of the triangular factors and permutation indices
      # to a single batch dimension. This makes it easy to apply
      # invert_permutation and gather_nd ops.
      perm_reshaped = array_ops.reshape(perm, [-1, num_rows])
      verification_reshaped = array_ops.reshape(verification,
                                                [-1, num_rows, num_cols])
      # Invert the permutation in each batch.
      inv_perm_reshaped = map_fn.map_fn(array_ops.invert_permutation,
                                        perm_reshaped)
      batch_size = perm_reshaped.shape.as_list()[0]
      # Prepare the batch indices with the same shape as the permutation.
      # The corresponding batch index is paired with each of the `num_rows`
      # permutation indices.
      batch_indices = math_ops.cast(
          array_ops.broadcast_to(
              math_ops.range(batch_size)[:, None], perm_reshaped.shape),
          dtype=output_idx_type)
      permuted_verification_reshaped = array_ops.gather_nd(
          verification_reshaped,
          array_ops.stack([batch_indices, inv_perm_reshaped], axis=-1))

      # Reshape the verification matrix back to the original shape.
      verification = array_ops.reshape(permuted_verification_reshaped,
                                       lu_shape)

    self._verifyLuBase(x, lower, upper, perm, verification,
                       output_idx_type)

  def testBasic(self):
    data = np.array([[4., -1., 2.], [-1., 6., 0], [10., 0., 5.]])

    for dtype in (np.float32, np.float64):
      for output_idx_type in (dtypes.int32, dtypes.int64):
        self._verifyLu(data.astype(dtype), output_idx_type=output_idx_type)

    for dtype in (np.complex64, np.complex128):
      for output_idx_type in (dtypes.int32, dtypes.int64):
        complex_data = np.tril(1j * data, -1).astype(dtype)
        complex_data += np.triu(-1j * data, 1).astype(dtype)
        complex_data += data
        self._verifyLu(complex_data, output_idx_type=output_idx_type)

  def testPivoting(self):
    # This matrix triggers partial pivoting because the first diagonal entry
    # is small.
    data = np.array([[1e-9, 1., 0.], [1., 0., 0], [0., 1., 5]])
    self._verifyLu(data.astype(np.float32))

    for dtype in (np.float32, np.float64):
      self._verifyLu(data.astype(dtype))
      _, p = linalg_ops.lu(data)
      p_val = self.evaluate([p])
      # Make sure p_val is not the identity permutation.
      self.assertNotAllClose(np.arange(3), p_val)

    for dtype in (np.complex64, np.complex128):
      complex_data = np.tril(1j * data, -1).astype(dtype)
      complex_data += np.triu(-1j * data, 1).astype(dtype)
      complex_data += data
      self._verifyLu(complex_data)
      _, p = linalg_ops.lu(data)
      p_val = self.evaluate([p])
      # Make sure p_val is not the identity permutation.
      self.assertNotAllClose(np.arange(3), p_val)

  def testInvalidMatrix(self):
    # LU factorization gives an error when the input is singular.
    # Note: A singular matrix may return without error but it won't be a valid
    # factorization.
    for dtype in self.float_types:
      with self.assertRaises(errors.InvalidArgumentError):
        self.evaluate(
            linalg_ops.lu(
                np.array([[1., 2., 3.], [2., 4., 6.], [2., 3., 4.]],
                         dtype=dtype)))
      with self.assertRaises(errors.InvalidArgumentError):
        self.evaluate(
            linalg_ops.lu(
                np.array([[[1., 2., 3.], [2., 4., 6.], [1., 2., 3.]],
                          [[1., 2., 3.], [3., 4., 5.], [5., 6., 7.]]],
                         dtype=dtype)))

  def testBatch(self):
    simple_array = np.array([[[1., -1.], [2., 5.]]])  # shape (1, 2, 2)
    self._verifyLu(simple_array)
    self._verifyLu(np.vstack((simple_array, simple_array)))
    odd_sized_array = np.array([[[4., -1., 2.], [-1., 6., 0], [2., 0., 5.]]])
    self._verifyLu(np.vstack((odd_sized_array, odd_sized_array)))

    batch_size = 200

    # Generate random matrices.
    np.random.seed(42)
    matrices = np.random.rand(batch_size, 5, 5)
    self._verifyLu(matrices)

    # Generate random complex valued matrices.
    np.random.seed(52)
    matrices = np.random.rand(batch_size, 5,
                              5) + 1j * np.random.rand(batch_size, 5, 5)
    self._verifyLu(matrices)

  def testLargeMatrix(self):
    # Generate random matrices.
    n = 500
    np.random.seed(64)
    data = np.random.rand(n, n)
    self._verifyLu(data)

    # Generate random complex valued matrices.
    np.random.seed(129)
    data = np.random.rand(n, n) + 1j * np.random.rand(n, n)
    self._verifyLu(data)

  @test_util.run_v1_only("b/120545219")
  def testEmpty(self):
    self._verifyLu(np.empty([0, 2, 2]))
    self._verifyLu(np.empty([2, 0, 0]))

  @test_util.run_deprecated_v1
  def testConcurrentExecutesWithoutError(self):
    matrix1 = random_ops.random_normal([5, 5], seed=42)
    matrix2 = random_ops.random_normal([5, 5], seed=42)
    lu1, p1 = linalg_ops.lu(matrix1)
    lu2, p2 = linalg_ops.lu(matrix2)
    lu1_val, p1_val, lu2_val, p2_val = self.evaluate([lu1, p1, lu2, p2])
    self.assertAllEqual(lu1_val, lu2_val)
    self.assertAllEqual(p1_val, p2_val)


class LuBenchmark(test.Benchmark):
  shapes = [
      (4, 4),
      (10, 10),
      (16, 16),
      (101, 101),
      (256, 256),
      (1000, 1000),
      (1024, 1024),
      (2048, 2048),
      (4096, 4096),
      (513, 2, 2),
      (513, 8, 8),
      (513, 256, 256),
      (4, 513, 2, 2),
  ]

  def _GenerateMatrix(self, shape):
    batch_shape = shape[:-2]
    shape = shape[-2:]
    assert shape[0] == shape[1]
    n = shape[0]
    matrix = np.ones(shape).astype(np.float32) / (2.0 * n) + np.diag(
        np.ones(n).astype(np.float32))
    return np.tile(matrix, batch_shape + (1, 1))

  def benchmarkLuOp(self):
    for shape in self.shapes:
      with ops.Graph().as_default(), \
          session.Session(config=benchmark.benchmark_config()) as sess, \
          ops.device("/cpu:0"):
        matrix = variables.Variable(self._GenerateMatrix(shape))
        lu, p = linalg_ops.lu(matrix)
        variables.global_variables_initializer().run()
        self.run_op_benchmark(
            sess,
            control_flow_ops.group(lu, p),
            min_iters=25,
            name="lu_cpu_{shape}".format(shape=shape))

      if test.is_gpu_available(True):
        with ops.Graph().as_default(), \
            session.Session(config=benchmark.benchmark_config()) as sess, \
            ops.device("/device:GPU:0"):
          matrix = variables.Variable(self._GenerateMatrix(shape))
          lu, p = linalg_ops.lu(matrix)
          variables.global_variables_initializer().run()
          self.run_op_benchmark(
              sess,
              control_flow_ops.group(lu, p),
              min_iters=25,
              name="lu_gpu_{shape}".format(shape=shape))


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

[((8201, 8237), 'tensorflow.python.framework.test_util.run_v1_only', 'test_util.run_v1_only', (['"""b/120545219"""'], {}), "('b/120545219')\n", (8222, 8237), False, 'from tensorflow.python.framework import test_util\n'), ((10466, 10477), 'tensorflow.python.platform.test.main', 'test.main', ([], {}), '()\n', (10475, 10477), False, 'from tensorflow.python.platform import test\n'), ((2584, 2633), 'tensorflow.python.ops.linalg_ops.lu', 'linalg_ops.lu', (['x'], {'output_idx_type': 'output_idx_type'}), '(x, output_idx_type=output_idx_type)\n', (2597, 2633), False, 'from tensorflow.python.ops import linalg_ops\n'), ((2840, 2877), 'tensorflow.python.ops.array_ops.matrix_band_part', 'array_ops.matrix_band_part', (['lu', '(-1)', '(0)'], {}), '(lu, -1, 0)\n', (2866, 2877), False, 'from tensorflow.python.ops import array_ops\n'), ((3276, 3319), 'tensorflow.python.ops.array_ops.matrix_set_diag', 'array_ops.matrix_set_diag', (['lower', 'ones_diag'], {}), '(lower, ones_diag)\n', (3301, 3319), False, 'from tensorflow.python.ops import array_ops\n'), ((3365, 3402), 'tensorflow.python.ops.array_ops.matrix_band_part', 'array_ops.matrix_band_part', (['lu', '(0)', '(-1)'], {}), '(lu, 0, -1)\n', (3391, 3402), False, 'from tensorflow.python.ops import array_ops\n'), ((3423, 3452), 'tensorflow.python.ops.math_ops.matmul', 'math_ops.matmul', (['lower', 'upper'], {}), '(lower, upper)\n', (3438, 3452), False, 'from tensorflow.python.ops import math_ops\n'), ((4990, 5052), 'numpy.array', 'np.array', (['[[4.0, -1.0, 2.0], [-1.0, 6.0, 0], [10.0, 0.0, 5.0]]'], {}), '([[4.0, -1.0, 2.0], [-1.0, 6.0, 0], [10.0, 0.0, 5.0]])\n', (4998, 5052), True, 'import numpy as np\n'), ((5683, 5742), 'numpy.array', 'np.array', (['[[1e-09, 1.0, 0.0], [1.0, 0.0, 0], [0.0, 1.0, 5]]'], {}), '([[1e-09, 1.0, 0.0], [1.0, 0.0, 0], [0.0, 1.0, 5]])\n', (5691, 5742), True, 'import numpy as np\n'), ((7223, 7260), 'numpy.array', 'np.array', (['[[[1.0, -1.0], [2.0, 5.0]]]'], {}), '([[[1.0, -1.0], [2.0, 5.0]]])\n', (7231, 7260), True, 'import numpy as np\n'), ((7391, 7454), 'numpy.array', 'np.array', (['[[[4.0, -1.0, 2.0], [-1.0, 6.0, 0], [2.0, 0.0, 5.0]]]'], {}), '([[[4.0, -1.0, 2.0], [-1.0, 6.0, 0], [2.0, 0.0, 5.0]]])\n', (7399, 7454), True, 'import numpy as np\n'), ((7572, 7590), 'numpy.random.seed', 'np.random.seed', (['(42)'], {}), '(42)\n', (7586, 7590), True, 'import numpy as np\n'), ((7606, 7638), 'numpy.random.rand', 'np.random.rand', (['batch_size', '(5)', '(5)'], {}), '(batch_size, 5, 5)\n', (7620, 7638), True, 'import numpy as np\n'), ((7720, 7738), 'numpy.random.seed', 'np.random.seed', (['(52)'], {}), '(52)\n', (7734, 7738), True, 'import numpy as np\n'), ((7964, 7982), 'numpy.random.seed', 'np.random.seed', (['(64)'], {}), '(64)\n', (7978, 7982), True, 'import numpy as np\n'), ((7994, 8014), 'numpy.random.rand', 'np.random.rand', (['n', 'n'], {}), '(n, n)\n', (8008, 8014), True, 'import numpy as np\n'), ((8092, 8111), 'numpy.random.seed', 'np.random.seed', (['(129)'], {}), '(129)\n', (8106, 8111), True, 'import numpy as np\n'), ((8435, 8476), 'tensorflow.python.ops.random_ops.random_normal', 'random_ops.random_normal', (['[5, 5]'], {'seed': '(42)'}), '([5, 5], seed=42)\n', (8459, 8476), False, 'from tensorflow.python.ops import random_ops\n'), ((8491, 8532), 'tensorflow.python.ops.random_ops.random_normal', 'random_ops.random_normal', (['[5, 5]'], {'seed': '(42)'}), '([5, 5], seed=42)\n', (8515, 8532), False, 'from tensorflow.python.ops import random_ops\n'), ((8547, 8569), 'tensorflow.python.ops.linalg_ops.lu', 'linalg_ops.lu', (['matrix1'], {}), '(matrix1)\n', (8560, 8569), False, 'from tensorflow.python.ops import linalg_ops\n'), ((8584, 8606), 'tensorflow.python.ops.linalg_ops.lu', 'linalg_ops.lu', (['matrix2'], {}), '(matrix2)\n', (8597, 8606), False, 'from tensorflow.python.ops import linalg_ops\n'), ((9319, 9356), 'numpy.tile', 'np.tile', (['matrix', '(batch_shape + (1, 1))'], {}), '(matrix, batch_shape + (1, 1))\n', (9326, 9356), True, 'import numpy as np\n'), ((2321, 2365), 'numpy.reshape', 'np.reshape', (['perm_np', '(-1, perm_np.shape[-1])'], {}), '(perm_np, (-1, perm_np.shape[-1]))\n', (2331, 2365), True, 'import numpy as np\n'), ((2919, 2987), 'tensorflow.python.ops.linalg_ops.eye', 'linalg_ops.eye', (['num_rows'], {'batch_shape': 'batch_shape', 'dtype': 'lower.dtype'}), '(num_rows, batch_shape=batch_shape, dtype=lower.dtype)\n', (2933, 2987), False, 'from tensorflow.python.ops import linalg_ops\n'), ((3013, 3070), 'tensorflow.python.ops.array_ops.concat', 'array_ops.concat', (['[lower, eye[(...), num_cols:]]'], {'axis': '(-1)'}), '([lower, eye[(...), num_cols:]], axis=-1)\n', (3029, 3070), False, 'from tensorflow.python.ops import array_ops\n'), ((3211, 3243), 'numpy.append', 'np.append', (['batch_shape', 'num_rows'], {}), '(batch_shape, num_rows)\n', (3220, 3243), True, 'import numpy as np\n'), ((3745, 3784), 'tensorflow.python.ops.array_ops.reshape', 'array_ops.reshape', (['perm', '[-1, num_rows]'], {}), '(perm, [-1, num_rows])\n', (3762, 3784), False, 'from tensorflow.python.ops import array_ops\n'), ((3815, 3872), 'tensorflow.python.ops.array_ops.reshape', 'array_ops.reshape', (['verification', '[-1, num_rows, num_cols]'], {}), '(verification, [-1, num_rows, num_cols])\n', (3832, 3872), False, 'from tensorflow.python.ops import array_ops\n'), ((3993, 4051), 'tensorflow.python.ops.map_fn.map_fn', 'map_fn.map_fn', (['array_ops.invert_permutation', 'perm_reshaped'], {}), '(array_ops.invert_permutation, perm_reshaped)\n', (4006, 4051), False, 'from tensorflow.python.ops import map_fn\n'), ((4755, 4814), 'tensorflow.python.ops.array_ops.reshape', 'array_ops.reshape', (['permuted_verification_reshaped', 'lu_shape'], {}), '(permuted_verification_reshaped, lu_shape)\n', (4772, 4814), False, 'from tensorflow.python.ops import array_ops\n'), ((5878, 5897), 'tensorflow.python.ops.linalg_ops.lu', 'linalg_ops.lu', (['data'], {}), '(data)\n', (5891, 5897), False, 'from tensorflow.python.ops import linalg_ops\n'), ((6279, 6298), 'tensorflow.python.ops.linalg_ops.lu', 'linalg_ops.lu', (['data'], {}), '(data)\n', (6292, 6298), False, 'from tensorflow.python.ops import linalg_ops\n'), ((7328, 7367), 'numpy.vstack', 'np.vstack', (['(simple_array, simple_array)'], {}), '((simple_array, simple_array))\n', (7337, 7367), True, 'import numpy as np\n'), ((7466, 7511), 'numpy.vstack', 'np.vstack', (['(odd_sized_array, odd_sized_array)'], {}), '((odd_sized_array, odd_sized_array))\n', (7475, 7511), True, 'import numpy as np\n'), ((7754, 7786), 'numpy.random.rand', 'np.random.rand', (['batch_size', '(5)', '(5)'], {}), '(batch_size, 5, 5)\n', (7768, 7786), True, 'import numpy as np\n'), ((8123, 8143), 'numpy.random.rand', 'np.random.rand', (['n', 'n'], {}), '(n, n)\n', (8137, 8143), True, 'import numpy as np\n'), ((8280, 8299), 'numpy.empty', 'np.empty', (['[0, 2, 2]'], {}), '([0, 2, 2])\n', (8288, 8299), True, 'import numpy as np\n'), ((8320, 8339), 'numpy.empty', 'np.empty', (['[2, 0, 0]'], {}), '([2, 0, 0])\n', (8328, 8339), True, 'import numpy as np\n'), ((9901, 9928), 'tensorflow.python.platform.test.is_gpu_available', 'test.is_gpu_available', (['(True)'], {}), '(True)\n', (9922, 9928), False, 'from tensorflow.python.platform import test\n'), ((4603, 4663), 'tensorflow.python.ops.array_ops.stack', 'array_ops.stack', (['[batch_indices, inv_perm_reshaped]'], {'axis': '(-1)'}), '([batch_indices, inv_perm_reshaped], axis=-1)\n', (4618, 4663), False, 'from tensorflow.python.ops import array_ops\n'), ((6017, 6029), 'numpy.arange', 'np.arange', (['(3)'], {}), '(3)\n', (6026, 6029), True, 'import numpy as np\n'), ((6418, 6430), 'numpy.arange', 'np.arange', (['(3)'], {}), '(3)\n', (6427, 6430), True, 'import numpy as np\n'), ((7824, 7856), 'numpy.random.rand', 'np.random.rand', (['batch_size', '(5)', '(5)'], {}), '(batch_size, 5, 5)\n', (7838, 7856), True, 'import numpy as np\n'), ((8151, 8171), 'numpy.random.rand', 'np.random.rand', (['n', 'n'], {}), '(n, n)\n', (8165, 8171), True, 'import numpy as np\n'), ((9538, 9558), 'tensorflow.python.framework.ops.device', 'ops.device', (['"""/cpu:0"""'], {}), "('/cpu:0')\n", (9548, 9558), False, 'from tensorflow.python.framework import ops\n'), ((9641, 9662), 'tensorflow.python.ops.linalg_ops.lu', 'linalg_ops.lu', (['matrix'], {}), '(matrix)\n', (9654, 9662), False, 'from tensorflow.python.ops import linalg_ops\n'), ((2463, 2483), 'numpy.sort', 'np.sort', (['perm_vector'], {}), '(perm_vector)\n', (2470, 2483), True, 'import numpy as np\n'), ((6108, 6132), 'numpy.tril', 'np.tril', (['(1.0j * data)', '(-1)'], {}), '(1.0j * data, -1)\n', (6115, 6132), True, 'import numpy as np\n'), ((6167, 6191), 'numpy.triu', 'np.triu', (['(-1.0j * data)', '(1)'], {}), '(-1.0j * data, 1)\n', (6174, 6191), True, 'import numpy as np\n'), ((9779, 9808), 'tensorflow.python.ops.control_flow_ops.group', 'control_flow_ops.group', (['lu', 'p'], {}), '(lu, p)\n', (9801, 9808), False, 'from tensorflow.python.ops import control_flow_ops\n'), ((10059, 10086), 'tensorflow.python.framework.ops.device', 'ops.device', (['"""/device:GPU:0"""'], {}), "('/device:GPU:0')\n", (10069, 10086), False, 'from tensorflow.python.framework import ops\n'), ((10173, 10194), 'tensorflow.python.ops.linalg_ops.lu', 'linalg_ops.lu', (['matrix'], {}), '(matrix)\n', (10186, 10194), False, 'from tensorflow.python.ops import linalg_ops\n'), ((4408, 4434), 'tensorflow.python.ops.math_ops.range', 'math_ops.range', (['batch_size'], {}), '(batch_size)\n', (4422, 4434), False, 'from tensorflow.python.ops import math_ops\n'), ((5355, 5379), 'numpy.tril', 'np.tril', (['(1.0j * data)', '(-1)'], {}), '(1.0j * data, -1)\n', (5362, 5379), True, 'import numpy as np\n'), ((5416, 5440), 'numpy.triu', 'np.triu', (['(-1.0j * data)', '(1)'], {}), '(-1.0j * data, 1)\n', (5423, 5440), True, 'import numpy as np\n'), ((6797, 6871), 'numpy.array', 'np.array', (['[[1.0, 2.0, 3.0], [2.0, 4.0, 6.0], [2.0, 3.0, 4.0]]'], {'dtype': 'dtype'}), '([[1.0, 2.0, 3.0], [2.0, 4.0, 6.0], [2.0, 3.0, 4.0]], dtype=dtype)\n', (6805, 6871), True, 'import numpy as np\n'), ((7015, 7149), 'numpy.array', 'np.array', (['[[[1.0, 2.0, 3.0], [2.0, 4.0, 6.0], [1.0, 2.0, 3.0]], [[1.0, 2.0, 3.0], [\n    3.0, 4.0, 5.0], [5.0, 6.0, 7.0]]]'], {'dtype': 'dtype'}), '([[[1.0, 2.0, 3.0], [2.0, 4.0, 6.0], [1.0, 2.0, 3.0]], [[1.0, 2.0, \n    3.0], [3.0, 4.0, 5.0], [5.0, 6.0, 7.0]]], dtype=dtype)\n', (7023, 7149), True, 'import numpy as np\n'), ((9212, 9226), 'numpy.ones', 'np.ones', (['shape'], {}), '(shape)\n', (9219, 9226), True, 'import numpy as np\n'), ((9277, 9287), 'numpy.ones', 'np.ones', (['n'], {}), '(n)\n', (9284, 9287), True, 'import numpy as np\n'), ((9426, 9437), 'tensorflow.python.framework.ops.Graph', 'ops.Graph', ([], {}), '()\n', (9435, 9437), False, 'from tensorflow.python.framework import ops\n'), ((9487, 9515), 'tensorflow.python.platform.benchmark.benchmark_config', 'benchmark.benchmark_config', ([], {}), '()\n', (9513, 9515), False, 'from tensorflow.python.platform import benchmark\n'), ((9671, 9711), 'tensorflow.python.ops.variables.global_variables_initializer', 'variables.global_variables_initializer', ([], {}), '()\n', (9709, 9711), False, 'from tensorflow.python.ops import variables\n'), ((10319, 10348), 'tensorflow.python.ops.control_flow_ops.group', 'control_flow_ops.group', (['lu', 'p'], {}), '(lu, p)\n', (10341, 10348), False, 'from tensorflow.python.ops import control_flow_ops\n'), ((9943, 9954), 'tensorflow.python.framework.ops.Graph', 'ops.Graph', ([], {}), '()\n', (9952, 9954), False, 'from tensorflow.python.framework import ops\n'), ((10006, 10034), 'tensorflow.python.platform.benchmark.benchmark_config', 'benchmark.benchmark_config', ([], {}), '()\n', (10032, 10034), False, 'from tensorflow.python.platform import benchmark\n'), ((10205, 10245), 'tensorflow.python.ops.variables.global_variables_initializer', 'variables.global_variables_initializer', ([], {}), '()\n', (10243, 10245), False, 'from tensorflow.python.ops import variables\n')]