• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14# ==============================================================================
15"""Test configs for eye."""
16import numpy as np
17import tensorflow.compat.v1 as tf
18from tensorflow.lite.testing.zip_test_utils import create_scalar_data
19from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
20from tensorflow.lite.testing.zip_test_utils import register_make_test_function
21
22
23@register_make_test_function()
24def make_eye_tests(options):
25  """Make a set of tests for tf.eye op."""
26
27  test_parameters = [{
28      "num_rows_shape": [[]],
29      "num_cols_shape": [[]],
30      "batch_shape": [[3], [2, 4], [4, 5, 6], None],
31      "use_num_cols": [True, False],
32      "dtype": [tf.float32, tf.int32],
33  }]
34
35  def build_graph(parameters):
36    """Make a set of tests to do eye."""
37
38    input_tensor0 = tf.compat.v1.placeholder(
39        dtype=tf.int32, name="num_rows", shape=parameters["num_rows_shape"])
40    input_tensor1 = tf.compat.v1.placeholder(
41        dtype=tf.int32, name="num_columns", shape=parameters["num_cols_shape"])
42    if parameters["use_num_cols"]:
43      outs = tf.eye(
44          num_rows=input_tensor0,
45          num_columns=input_tensor1,
46          batch_shape=parameters["batch_shape"],
47          dtype=parameters["dtype"])
48      return [input_tensor0, input_tensor1], [outs]
49    else:
50      outs = tf.eye(num_rows=input_tensor0, dtype=parameters["dtype"])
51      return [input_tensor0], [outs]
52
53  def build_inputs(parameters, sess, inputs, outputs):
54    input_value0 = create_scalar_data(dtype=np.int32, min_value=1)
55    input_value1 = create_scalar_data(dtype=np.int32, min_value=1)
56    if parameters["use_num_cols"]:
57      return [input_value0, input_value1], sess.run(
58          outputs, feed_dict=dict(zip(inputs, [input_value0, input_value1])))
59    else:
60      return [input_value0], sess.run(
61          outputs, feed_dict=dict(zip(inputs, [input_value0])))
62
63  make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
64