• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2021 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 broadcast_gradient_args."""
16from __future__ import absolute_import
17from __future__ import division
18from __future__ import print_function
19
20import numpy as np
21import tensorflow as tf
22
23from tensorflow.lite.testing.zip_test_utils import ExtraTocoOptions
24from tensorflow.lite.testing.zip_test_utils import make_zip_of_tests
25from tensorflow.lite.testing.zip_test_utils import register_make_test_function
26
27
28@register_make_test_function()
29def make_broadcast_gradient_args_tests(options):
30  """Make a set of tests to do broadcast_gradient_args."""
31
32  test_parameters = [{
33      'input_case': ['ALL_EQUAL', 'ONE_DIM', 'NON_BROADCASTABLE'],
34      'dtype': [tf.dtypes.int32, tf.dtypes.int64],
35  }]
36
37  def build_graph(parameters):
38    """Build the op testing graph."""
39    input1 = tf.compat.v1.placeholder(dtype=parameters['dtype'], name='input1')
40    input2 = tf.compat.v1.placeholder(dtype=parameters['dtype'], name='input2')
41    output1, output2 = tf.raw_ops.BroadcastGradientArgs(s0=input1, s1=input2)
42    return [input1, input2], [output1, output2]
43
44  def build_inputs(parameters, sess, inputs, outputs):
45    dtype = parameters['dtype'].as_numpy_dtype()
46
47    if parameters['input_case'] == 'ALL_EQUAL':
48      values = [
49          np.array([2, 4, 1, 3], dtype=dtype),
50          np.array([2, 4, 1, 3], dtype=dtype)
51      ]
52    elif parameters['input_case'] == 'ONE_DIM':
53      values = [
54          np.array([2, 4, 1, 3], dtype=dtype),
55          np.array([2, 1, 1, 3], dtype=dtype)
56      ]
57    elif parameters['input_case'] == 'NON_BROADCASTABLE':
58      values = [
59          np.array([2, 4, 1, 3], dtype=dtype),
60          np.array([2, 5, 1, 3], dtype=dtype)
61      ]
62    return values, sess.run(outputs, feed_dict=dict(zip(inputs, values)))
63
64  extra_toco_options = ExtraTocoOptions()
65  extra_toco_options.allow_custom_ops = True
66  make_zip_of_tests(
67      options,
68      test_parameters,
69      build_graph,
70      build_inputs,
71      extra_toco_options,
72      expected_tf_failures=2)
73