• 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."""
16from __future__ import absolute_import
17from __future__ import division
18from __future__ import print_function
19
20import numpy as np
21import tensorflow.compat.v1 as tf
22from tensorflow.lite.testing.zip_test_utils import create_scalar_data
23from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
24from tensorflow.lite.testing.zip_test_utils import register_make_test_function
25
26
27@register_make_test_function()
28def make_eye_tests(options):
29  """Make a set of tests for tf.eye op."""
30
31  test_parameters = [{
32      "num_rows_shape": [[]],
33      "num_cols_shape": [[]],
34      "batch_shape": [[3], [2, 4], [4, 5, 6], None],
35      "use_num_cols": [True, False],
36      "dtype": [tf.float32, tf.int32],
37  }]
38
39  def build_graph(parameters):
40    """Make a set of tests to do eye."""
41
42    input_tensor0 = tf.compat.v1.placeholder(
43        dtype=tf.int32, name="num_rows", shape=parameters["num_rows_shape"])
44    input_tensor1 = tf.compat.v1.placeholder(
45        dtype=tf.int32, name="num_columns", shape=parameters["num_cols_shape"])
46    if parameters["use_num_cols"]:
47      outs = tf.eye(
48          num_rows=input_tensor0,
49          num_columns=input_tensor1,
50          batch_shape=parameters["batch_shape"],
51          dtype=parameters["dtype"])
52      return [input_tensor0, input_tensor1], [outs]
53    else:
54      outs = tf.eye(num_rows=input_tensor0, dtype=parameters["dtype"])
55      return [input_tensor0], [outs]
56
57  def build_inputs(parameters, sess, inputs, outputs):
58    input_value0 = create_scalar_data(dtype=np.int32, min_value=1)
59    input_value1 = create_scalar_data(dtype=np.int32, min_value=1)
60    if parameters["use_num_cols"]:
61      return [input_value0, input_value1], sess.run(
62          outputs, feed_dict=dict(zip(inputs, [input_value0, input_value1])))
63    else:
64      return [input_value0], sess.run(
65          outputs, feed_dict=dict(zip(inputs, [input_value0])))
66
67  make_zip_of_tests(options, test_parameters, build_graph, build_inputs)
68