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

Function TestBitcastOp

tensorflow/c/kernels/bitcast_op_test.cc:40–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38};
39
40void TestBitcastOp(Tensor* input_tensor, DataType out_type,
41 TensorShape expected_shape, error::Code expected_code) {
42 Status status;
43 NodeDef def;
44 def.set_op("Bitcast");
45 def.set_device(DEVICE_CPU);
46
47 AttrValue typeAttr;
48 SetAttrValue(input_tensor->dtype(), &typeAttr);
49
50 AttrValue outTypeAttr;
51 SetAttrValue(out_type, &outTypeAttr);
52
53 (*def.mutable_attr())["T"] = typeAttr;
54 (*def.mutable_attr())["type"] = outTypeAttr;
55
56 def.add_input(
57 strings::StrCat("input1: ", DataTypeString(input_tensor->dtype())));
58
59 std::unique_ptr<OpKernel> kernel =
60 CreateOpKernel(DeviceType(DEVICE_CPU), nullptr, nullptr, def, 1, &status);
61 ASSERT_TRUE(status.ok()) << status.ToString();
62
63 OpKernelContext::Params params;
64 DummyDevice dummy_device(nullptr, false);
65 params.device = &dummy_device;
66 params.op_kernel = kernel.get();
67 gtl::InlinedVector<TensorValue, 4> inputs;
68 inputs.emplace_back(input_tensor);
69 params.inputs = &inputs;
70
71 OpKernelContext ctx(&params);
72 kernel->Compute(&ctx);
73 ASSERT_EQ(expected_code, ctx.status().code());
74 if (expected_code == error::OK) {
75 ASSERT_EQ(expected_shape, ctx.mutable_output(0)->shape())
76 << ctx.mutable_output(0)->shape().DebugString();
77 }
78}
79
80TEST(BitcastOpTest, TestUpcast) {
81 Tensor int8_input(DT_UINT8, {8});

Callers 1

TESTFunction · 0.85

Calls 15

CreateOpKernelFunction · 0.85
DeviceTypeClass · 0.85
set_opMethod · 0.80
mutable_outputMethod · 0.60
SetAttrValueFunction · 0.50
StrCatFunction · 0.50
DataTypeStringFunction · 0.50
set_deviceMethod · 0.45
dtypeMethod · 0.45
add_inputMethod · 0.45
okMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected