| 38 | }; |
| 39 | |
| 40 | void 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(¶ms); |
| 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 | |
| 80 | TEST(BitcastOpTest, TestUpcast) { |
| 81 | Tensor int8_input(DT_UINT8, {8}); |
no test coverage detected