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_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 make_zip_of_tests 24from tensorflow.lite.testing.zip_test_utils import register_make_test_function 25 26 27@register_make_test_function("make_broadcast_args_tests") 28def make_broadcast_args_tests(options): 29 """Make a set of tests to do broadcast_args.""" 30 31 # Chose a set of parameters 32 test_parameters = [{ 33 "dtype": [tf.int64, tf.int32], 34 "input1_shape": [[1], [4], [3, 4], [1, 3, 4]], 35 "input2_shape": [[6, 4, 3, 4]], 36 }, { 37 "dtype": [tf.int64, tf.int32], 38 "input1_shape": [[1, 4, 0]], 39 "input2_shape": [[3, 1, 0], [3, 4, 1]], 40 }] 41 42 def build_graph(parameters): 43 """Build the graph for broadcast_args tests.""" 44 shape1_tensor = tf.compat.v1.placeholder( 45 dtype=parameters["dtype"], 46 name="input1", 47 shape=[len(parameters["input1_shape"])]) 48 shape2_tensor = tf.compat.v1.placeholder( 49 dtype=parameters["dtype"], 50 name="input2", 51 shape=[len(parameters["input2_shape"])]) 52 53 out = tf.raw_ops.BroadcastArgs(s0=shape1_tensor, s1=shape2_tensor) 54 return [shape1_tensor, shape2_tensor], [out] 55 56 def build_inputs(parameters, sess, inputs, outputs): 57 input_values = [ 58 np.array(parameters["input1_shape"]).astype( 59 parameters["dtype"].as_numpy_dtype), 60 np.array(parameters["input2_shape"]).astype( 61 parameters["dtype"].as_numpy_dtype), 62 ] 63 return input_values, sess.run( 64 outputs, feed_dict=dict(zip(inputs, input_values))) 65 66 make_zip_of_tests(options, test_parameters, build_graph, build_inputs) 67