MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / TestMulShape

Function TestMulShape

tensorflow/core/kernels/quantized_mul_op_test.cc:87–135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85}
86
87void TestMulShape(const std::vector<int64>& x_shape,
88 const std::vector<int64>& y_shape) {
89 const size_t x_num_elements = TensorShape(x_shape).num_elements();
90 std::vector<float> x_values(x_num_elements);
91 for (int i = 0; i < x_num_elements; ++i) {
92 x_values[i] = i % 256;
93 }
94 const float x_min_value = 0.0f;
95 const float x_max_value = 256.0f;
96
97 const size_t y_num_elements = TensorShape(y_shape).num_elements();
98 std::vector<float> y_values(y_num_elements);
99 for (int i = 0; i < y_num_elements; ++i) {
100 y_values[i] = ((i + 23) % 123) - 50;
101 }
102 const float y_min_value = -150.0f;
103 const float y_max_value = 150.0f;
104
105 Scope root = Scope::NewRootScope();
106
107 Tensor x_float_tensor(DT_FLOAT, TensorShape(x_shape));
108 test::FillValues<float>(&x_float_tensor, x_values);
109 Output x = Const(root.WithOpName("x"), Input::Initializer(x_float_tensor));
110
111 Tensor y_float_tensor(DT_FLOAT, TensorShape(y_shape));
112 test::FillValues<float>(&y_float_tensor, y_values);
113 Output y = Const(root.WithOpName("y"), Input::Initializer(y_float_tensor));
114
115 Mul mul = Mul(root.WithOpName("mul"), x, y);
116
117 TF_EXPECT_OK(root.status());
118
119 ClientSession session(root);
120 std::vector<Tensor> outputs;
121 TF_EXPECT_OK(session.Run(ClientSession::FeedType(), {mul.z}, &outputs));
122
123 const Tensor& expected_values_tensor = outputs[0];
124 const float* expected_values_data =
125 expected_values_tensor.flat<float>().data();
126 std::vector<float> expected_values(
127 expected_values_data,
128 expected_values_data + expected_values_tensor.NumElements());
129 std::vector<int64> expected_shape;
130 for (const int64 dim : expected_values_tensor.shape().dim_sizes()) {
131 expected_shape.push_back(dim);
132 }
133 TestMul(x_shape, x_values, x_min_value, x_max_value, y_shape, y_values,
134 y_min_value, y_max_value, expected_shape, expected_values, 256.0);
135}
136
137void TimeMul(const std::vector<int64>& x_shape,
138 const std::vector<int64>& y_shape, int64 iterations) {

Callers 4

TimeMulFunction · 0.85
TestScalarFunction · 0.85
TestVectorFunction · 0.85
TestVectorTimesTensorFunction · 0.85

Calls 14

TestMulFunction · 0.85
WithOpNameMethod · 0.80
TensorShapeClass · 0.50
ConstFunction · 0.50
InitializerClass · 0.50
MulFunction · 0.50
num_elementsMethod · 0.45
statusMethod · 0.45
RunMethod · 0.45
dataMethod · 0.45
NumElementsMethod · 0.45
dim_sizesMethod · 0.45

Tested by

no test coverage detected