# 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()

[((212, 3, 212, 39), 'tensorflow.python.framework.test_util.run_v1_only', 'test_util.run_v1_only', ({(212, 25, 212, 38): '"""b/120545219"""'}, {}), "('b/120545219')", False, 'from tensorflow.python.framework import test_util\n'), ((283, 2, 283, 13), 'tensorflow.python.platform.test.main', 'test.main', ({}, {}), '()', False, 'from tensorflow.python.platform import test\n'), ((69, 15, 69, 64), 'tensorflow.python.ops.linalg_ops.lu', 'linalg_ops.lu', (), '', False, 'from tensorflow.python.ops import linalg_ops\n'), ((77, 12, 77, 49), 'tensorflow.python.ops.array_ops.matrix_band_part', 'array_ops.matrix_band_part', ({(77, 39, 77, 41): 'lu', (77, 43, 77, 45): '-1', (77, 47, 77, 48): '0'}, {}), '(lu, -1, 0)', False, 'from tensorflow.python.ops import array_ops\n'), ((89, 12, 89, 55), 'tensorflow.python.ops.array_ops.matrix_set_diag', 'array_ops.matrix_set_diag', ({(89, 38, 89, 43): 'lower', (89, 45, 89, 54): 'ones_diag'}, {}), '(lower, ones_diag)', False, 'from tensorflow.python.ops import array_ops\n'), ((92, 12, 92, 49), 'tensorflow.python.ops.array_ops.matrix_band_part', 'array_ops.matrix_band_part', ({(92, 39, 92, 41): 'lu', (92, 43, 92, 44): '0', (92, 46, 92, 48): '-1'}, {}), '(lu, 0, -1)', False, 'from tensorflow.python.ops import array_ops\n'), ((94, 19, 94, 48), 'tensorflow.python.ops.math_ops.matmul', 'math_ops.matmul', ({(94, 35, 94, 40): 'lower', (94, 42, 94, 47): 'upper'}, {}), '(lower, upper)', False, 'from tensorflow.python.ops import math_ops\n'), ((127, 11, 127, 65), 'numpy.array', 'np.array', ({(127, 20, 127, 64): '[[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]])', True, 'import numpy as np\n'), ((143, 11, 143, 63), 'numpy.array', 'np.array', ({(143, 20, 143, 62): '[[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]])', True, 'import numpy as np\n'), ((181, 19, 181, 52), 'numpy.array', 'np.array', ({(181, 28, 181, 51): '[[[1.0, -1.0], [2.0, 5.0]]]'}, {}), '([[[1.0, -1.0], [2.0, 5.0]]])', True, 'import numpy as np\n'), ((184, 22, 184, 77), 'numpy.array', 'np.array', ({(184, 31, 184, 76): '[[[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]]])', True, 'import numpy as np\n'), ((190, 4, 190, 22), 'numpy.random.seed', 'np.random.seed', ({(190, 19, 190, 21): '(42)'}, {}), '(42)', True, 'import numpy as np\n'), ((191, 15, 191, 47), 'numpy.random.rand', 'np.random.rand', ({(191, 30, 191, 40): 'batch_size', (191, 42, 191, 43): '5', (191, 45, 191, 46): '5'}, {}), '(batch_size, 5, 5)', True, 'import numpy as np\n'), ((195, 4, 195, 22), 'numpy.random.seed', 'np.random.seed', ({(195, 19, 195, 21): '(52)'}, {}), '(52)', True, 'import numpy as np\n'), ((203, 4, 203, 22), 'numpy.random.seed', 'np.random.seed', ({(203, 19, 203, 21): '(64)'}, {}), '(64)', True, 'import numpy as np\n'), ((204, 11, 204, 31), 'numpy.random.rand', 'np.random.rand', ({(204, 26, 204, 27): 'n', (204, 29, 204, 30): 'n'}, {}), '(n, n)', True, 'import numpy as np\n'), ((208, 4, 208, 23), 'numpy.random.seed', 'np.random.seed', ({(208, 19, 208, 22): '(129)'}, {}), '(129)', True, 'import numpy as np\n'), ((219, 14, 219, 55), 'tensorflow.python.ops.random_ops.random_normal', 'random_ops.random_normal', (), '', False, 'from tensorflow.python.ops import random_ops\n'), ((220, 14, 220, 55), 'tensorflow.python.ops.random_ops.random_normal', 'random_ops.random_normal', (), '', False, 'from tensorflow.python.ops import random_ops\n'), ((221, 14, 221, 36), 'tensorflow.python.ops.linalg_ops.lu', 'linalg_ops.lu', ({(221, 28, 221, 35): 'matrix1'}, {}), '(matrix1)', False, 'from tensorflow.python.ops import linalg_ops\n'), ((222, 14, 222, 36), 'tensorflow.python.ops.linalg_ops.lu', 'linalg_ops.lu', ({(222, 28, 222, 35): 'matrix2'}, {}), '(matrix2)', False, 'from tensorflow.python.ops import linalg_ops\n'), ((252, 11, 252, 48), 'numpy.tile', 'np.tile', ({(252, 19, 252, 25): 'matrix', (252, 27, 252, 47): '(batch_shape + (1, 1))'}, {}), '(matrix, batch_shape + (1, 1))', True, 'import numpy as np\n'), ((63, 22, 63, 66), 'numpy.reshape', 'np.reshape', ({(63, 33, 63, 40): 'perm_np', (63, 42, 63, 65): '(-1, perm_np.shape[-1])'}, {}), '(perm_np, (-1, perm_np.shape[-1]))', True, 'import numpy as np\n'), ((80, 12, 81, 63), 'tensorflow.python.ops.linalg_ops.eye', 'linalg_ops.eye', (), '', False, 'from tensorflow.python.ops import linalg_ops\n'), ((82, 14, 82, 69), 'tensorflow.python.ops.array_ops.concat', 'array_ops.concat', (), '', False, 'from tensorflow.python.ops import array_ops\n'), ((88, 8, 88, 40), 'numpy.append', 'np.append', ({(88, 18, 88, 29): 'batch_shape', (88, 31, 88, 39): 'num_rows'}, {}), '(batch_shape, num_rows)', True, 'import numpy as np\n'), ((101, 22, 101, 61), 'tensorflow.python.ops.array_ops.reshape', 'array_ops.reshape', ({(101, 40, 101, 44): 'perm', (101, 46, 101, 60): '[-1, num_rows]'}, {}), '(perm, [-1, num_rows])', False, 'from tensorflow.python.ops import array_ops\n'), ((102, 30, 103, 73), 'tensorflow.python.ops.array_ops.reshape', 'array_ops.reshape', ({(102, 48, 102, 60): 'verification', (103, 48, 103, 72): '[-1, num_rows, num_cols]'}, {}), '(verification, [-1, num_rows, num_cols])', False, 'from tensorflow.python.ops import array_ops\n'), ((105, 26, 106, 54), 'tensorflow.python.ops.map_fn.map_fn', 'map_fn.map_fn', ({(105, 40, 105, 68): 'array_ops.invert_permutation', (106, 40, 106, 53): 'perm_reshaped'}, {}), '(array_ops.invert_permutation, perm_reshaped)', False, 'from tensorflow.python.ops import map_fn\n'), ((120, 21, 121, 48), 'tensorflow.python.ops.array_ops.reshape', 'array_ops.reshape', ({(120, 39, 120, 69): 'permuted_verification_reshaped', (121, 39, 121, 47): 'lu_shape'}, {}), '(permuted_verification_reshaped, lu_shape)', False, 'from tensorflow.python.ops import array_ops\n'), ((148, 13, 148, 32), 'tensorflow.python.ops.linalg_ops.lu', 'linalg_ops.lu', ({(148, 27, 148, 31): 'data'}, {}), '(data)', False, 'from tensorflow.python.ops import linalg_ops\n'), ((158, 13, 158, 32), 'tensorflow.python.ops.linalg_ops.lu', 'linalg_ops.lu', ({(158, 27, 158, 31): 'data'}, {}), '(data)', False, 'from tensorflow.python.ops import linalg_ops\n'), ((183, 19, 183, 58), 'numpy.vstack', 'np.vstack', ({(183, 29, 183, 57): '(simple_array, simple_array)'}, {}), '((simple_array, simple_array))', True, 'import numpy as np\n'), ((185, 19, 185, 64), 'numpy.vstack', 'np.vstack', ({(185, 29, 185, 63): '(odd_sized_array, odd_sized_array)'}, {}), '((odd_sized_array, odd_sized_array))', True, 'import numpy as np\n'), ((196, 15, 197, 32), 'numpy.random.rand', 'np.random.rand', ({(196, 30, 196, 40): 'batch_size', (196, 42, 196, 43): '(5)', (197, 30, 197, 31): '(5)'}, {}), '(batch_size, 5, 5)', True, 'import numpy as np\n'), ((209, 11, 209, 31), 'numpy.random.rand', 'np.random.rand', ({(209, 26, 209, 27): 'n', (209, 29, 209, 30): 'n'}, {}), '(n, n)', True, 'import numpy as np\n'), ((214, 19, 214, 38), 'numpy.empty', 'np.empty', ({(214, 28, 214, 37): '[0, 2, 2]'}, {}), '([0, 2, 2])', True, 'import numpy as np\n'), ((215, 19, 215, 38), 'numpy.empty', 'np.empty', ({(215, 28, 215, 37): '[2, 0, 0]'}, {}), '([2, 0, 0])', True, 'import numpy as np\n'), ((268, 9, 268, 36), 'tensorflow.python.platform.test.is_gpu_available', 'test.is_gpu_available', ({(268, 31, 268, 35): '(True)'}, {}), '(True)', False, 'from tensorflow.python.platform import test\n'), ((117, 10, 117, 70), 'tensorflow.python.ops.array_ops.stack', 'array_ops.stack', (), '', False, 'from tensorflow.python.ops import array_ops\n'), ((151, 29, 151, 41), 'numpy.arange', 'np.arange', ({(151, 39, 151, 40): '(3)'}, {}), '(3)', True, 'import numpy as np\n'), ((161, 29, 161, 41), 'numpy.arange', 'np.arange', ({(161, 39, 161, 40): '(3)'}, {}), '(3)', True, 'import numpy as np\n'), ((197, 40, 197, 72), 'numpy.random.rand', 'np.random.rand', ({(197, 55, 197, 65): 'batch_size', (197, 67, 197, 68): '(5)', (197, 70, 197, 71): '(5)'}, {}), '(batch_size, 5, 5)', True, 'import numpy as np\n'), ((209, 39, 209, 59), 'numpy.random.rand', 'np.random.rand', ({(209, 54, 209, 55): 'n', (209, 57, 209, 58): 'n'}, {}), '(n, n)', True, 'import numpy as np\n'), ((258, 10, 258, 30), 'tensorflow.python.framework.ops.device', 'ops.device', ({(258, 21, 258, 29): '"""/cpu:0"""'}, {}), "('/cpu:0')", False, 'from tensorflow.python.framework import ops\n'), ((260, 16, 260, 37), 'tensorflow.python.ops.linalg_ops.lu', 'linalg_ops.lu', ({(260, 30, 260, 36): 'matrix'}, {}), '(matrix)', False, 'from tensorflow.python.ops import linalg_ops\n'), ((65, 57, 65, 77), 'numpy.sort', 'np.sort', ({(65, 65, 65, 76): 'perm_vector'}, {}), '(perm_vector)', True, 'import numpy as np\n'), ((154, 21, 154, 43), 'numpy.tril', 'np.tril', ({(154, 29, 154, 38): '1.0j * data', (154, 40, 154, 42): '-1'}, {}), '(1.0j * data, -1)', True, 'import numpy as np\n'), ((155, 22, 155, 44), 'numpy.triu', 'np.triu', ({(155, 30, 155, 40): '(-1.0j * data)', (155, 42, 155, 43): '(1)'}, {}), '(-1.0j * data, 1)', True, 'import numpy as np\n'), ((264, 12, 264, 41), 'tensorflow.python.ops.control_flow_ops.group', 'control_flow_ops.group', ({(264, 35, 264, 37): 'lu', (264, 39, 264, 40): 'p'}, {}), '(lu, p)', False, 'from tensorflow.python.ops import control_flow_ops\n'), ((271, 12, 271, 39), 'tensorflow.python.framework.ops.device', 'ops.device', ({(271, 23, 271, 38): '"""/device:GPU:0"""'}, {}), "('/device:GPU:0')", False, 'from tensorflow.python.framework import ops\n'), ((273, 18, 273, 39), 'tensorflow.python.ops.linalg_ops.lu', 'linalg_ops.lu', ({(273, 32, 273, 38): 'matrix'}, {}), '(matrix)', False, 'from tensorflow.python.ops import linalg_ops\n'), ((113, 14, 113, 40), 'tensorflow.python.ops.math_ops.range', 'math_ops.range', ({(113, 29, 113, 39): 'batch_size'}, {}), '(batch_size)', False, 'from tensorflow.python.ops import math_ops\n'), ((135, 23, 135, 45), 'numpy.tril', 'np.tril', ({(135, 31, 135, 40): '1.0j * data', (135, 42, 135, 44): '-1'}, {}), '(1.0j * data, -1)', True, 'import numpy as np\n'), ((136, 24, 136, 46), 'numpy.triu', 'np.triu', ({(136, 32, 136, 42): '(-1.0j * data)', (136, 44, 136, 45): '(1)'}, {}), '(-1.0j * data, 1)', True, 'import numpy as np\n'), ((171, 16, 172, 37), 'numpy.array', 'np.array', (), '', True, 'import numpy as np\n'), ((176, 16, 178, 37), 'numpy.array', 'np.array', (), '', True, 'import numpy as np\n'), ((250, 13, 250, 27), 'numpy.ones', 'np.ones', ({(250, 21, 250, 26): 'shape'}, {}), '(shape)', True, 'import numpy as np\n'), ((251, 8, 251, 18), 'numpy.ones', 'np.ones', ({(251, 16, 251, 17): 'n'}, {}), '(n)', True, 'import numpy as np\n'), ((256, 11, 256, 22), 'tensorflow.python.framework.ops.Graph', 'ops.Graph', ({}, {}), '()', False, 'from tensorflow.python.framework import ops\n'), ((257, 33, 257, 61), 'tensorflow.python.platform.benchmark.benchmark_config', 'benchmark.benchmark_config', ({}, {}), '()', False, 'from tensorflow.python.platform import benchmark\n'), ((261, 8, 261, 48), 'tensorflow.python.ops.variables.global_variables_initializer', 'variables.global_variables_initializer', ({}, {}), '()', False, 'from tensorflow.python.ops import variables\n'), ((277, 14, 277, 43), 'tensorflow.python.ops.control_flow_ops.group', 'control_flow_ops.group', ({(277, 37, 277, 39): 'lu', (277, 41, 277, 42): 'p'}, {}), '(lu, p)', False, 'from tensorflow.python.ops import control_flow_ops\n'), ((269, 13, 269, 24), 'tensorflow.python.framework.ops.Graph', 'ops.Graph', ({}, {}), '()', False, 'from tensorflow.python.framework import ops\n'), ((270, 35, 270, 63), 'tensorflow.python.platform.benchmark.benchmark_config', 'benchmark.benchmark_config', ({}, {}), '()', False, 'from tensorflow.python.platform import benchmark\n'), ((274, 10, 274, 50), 'tensorflow.python.ops.variables.global_variables_initializer', 'variables.global_variables_initializer', ({}, {}), '()', False, 'from tensorflow.python.ops import variables\n')]