def get_test_lines(in_shape, permutation): """ Create a list of strings corresponding to the lines in a single test case. Uses TensorFlow to compute the expected results for the given parameters, and provides the code to call the test fixture to run the test. """ output, max_input_val = helpers.get_result_and_size( get_transpose_result, in_shape=in_shape, permutation=permutation) in_shape_str = list(map(str, in_shape)) perm_str = list(map(str, permutation)) test_case = TEST_CASE_TPL.format(n_dimensions=len(in_shape)) test_name = TEST_NAME_TPL.format(n_dimensions=len(in_shape)) + "x".join( in_shape_str) + "_" + "x".join(perm_str) test_lines = [ "TYPED_TEST({}, {}) {{".format(test_case, test_name), " using DataType = typename TestFixture::DataType;", " const std::vector<DataType> exp_out = {};".format( helpers.format_tensor(output)), " const std::vector<int> sizes = {{ {size_str} }};".format( size_str=",".join(in_shape_str)), " const std::vector<int> perm = {{ {perm_str} }};".format( perm_str=",".join(perm_str)), " const DataType max_input_val = {:.1f};".format(max_input_val), " this->run(exp_out, sizes, perm, max_input_val, 0, 0);", "}", ] return test_lines
def get_test_lines(batch, m, k, n, beta, trans_lhs, trans_rhs): """ Create a list of strings corresponding to the lines in a single test case. Uses TensorFlow to compute the expected results for the given parameters, and provides the code to call the test fixture to run the test. """ output, max_input_val = helpers.get_result_and_size(get_matmul_result, batch=batch, m=m, k=k, n=n, beta=beta, trans_lhs=trans_lhs, trans_rhs=trans_rhs) test_case = TEST_CASE_TPL.format(batch=batch, beta=beta, trans_lhs=trans_lhs, trans_rhs=trans_rhs) test_name = TEST_NAME_TPL.format(m=m, k=k, n=n) test_lines = [ "TYPED_TEST({}, {}) {{".format(test_case, test_name), " using DataType = typename TestFixture::DataType;", " const std::vector<DataType> exp_out = {};".format( helpers.format_tensor(output)), " const int batches = {};".format(batch), " const int m = {};".format(m), " const int k = {};".format(k), " const int n = {};".format(n), " const auto beta = static_cast<DataType>({});".format(beta), " const DataType max_input_val = {:.1f};".format(max_input_val), " this->run(exp_out, batches, m, k, n, beta, 0, 0, 0, max_input_val);", "}", ] return test_lines
def get_result(test_case, test_params): output, _ = helpers.get_result_and_size( get_result_function(test_case), max_input_val=test_params.in_size, floor_div=True, pointwise_op=TENSORFLOW_OPS_MAP[test_case.test_type], in_size=test_params.in_size) return output
def get_result(test_case, test_params): channel_idx = -1 if test_params.data_format == 'NHWC' else 1 output, max_input_val = helpers.get_result_and_size( get_result_function(test_case), max_input_val=test_params.in_shape[channel_idx], floor_div=True, softmax_op=TENSORFLOW_OPS_MAP[test_case.test_type], input_shape=test_params.in_shape) return output, max_input_val
def get_result_and_size(test_case, test_params): """ Get the result of the bias-add and max input value. Ensures that the resulting values are less than the REQUIRED_MAX, and if not will adjust the maximum value to allow in the input tensors. """ return helpers.get_result_and_size(get_result_function(test_case), input_shape=test_params.in_shape)
def get_result_and_size(test_case, test_params): """ Get the result of the specified convolution and max input value. Ensures that the resulting values are less than the REQUIRED_MAX, and if not will adjust the maximum value to allow in the input tensors. """ window_shape = [test_case.window, test_case.window] stride_shape = [test_case.stride, test_case.stride] return helpers.get_result_and_size(get_result_function(test_case), pool_op=test_case.test_type, input_shape=test_params.in_shape, window_shape=window_shape, stride_shape=stride_shape, padding=test_params.padding)
def get_result_and_size(test_case, test_params): """ Get the result of the specified convolution and max input value. Ensures that the resulting values are less than the REQUIRED_MAX, and if not will adjust the maximum value to allow in the input tensors. """ conv_fn = get_conv_fn(test_case.test_type) filter_shape = [ test_case.window, test_case.window, test_params.in_shape[-1], test_params.features ] stride_shape = [1, test_case.stride, test_case.stride, 1] return helpers.get_result_and_size(conv_fn, input_shape=test_params.in_shape, filter_shape=filter_shape, stride_shape=stride_shape, padding=test_params.padding)