| 64 | )doc"); |
| 65 | |
| 66 | TEST(TFunc, SquarePlusOne) { |
| 67 | auto fdef = FDH::Create( |
| 68 | // Name |
| 69 | "SquarePlusOne", |
| 70 | // Inputs |
| 71 | {"x: T"}, |
| 72 | // Outputs |
| 73 | {"y: T"}, |
| 74 | // Attrs |
| 75 | {"T: {float, double, int32, int64}"}, |
| 76 | // Nodes |
| 77 | {// a = Square<T>(x) |
| 78 | {{"a"}, "Square", {"x"}, {{"T", "$T"}}}, |
| 79 | // o = One<T>() |
| 80 | // NOTE: We can also have a Cast<Tin, Tout>(x) instead. |
| 81 | {{"o"}, "One", {}, {{"T", "$T"}}}, |
| 82 | // y = Add<T>(a, o) |
| 83 | {{"y"}, "Add", {"a:y", "o:y"}, {{"T", "$T"}}}}, |
| 84 | // Returns |
| 85 | {{"y", "y:z:0"}}); |
| 86 | |
| 87 | const char* e = R"P( |
| 88 | SquarePlusOne[T:{float, double, int32, int64}](x:T) -> (y:T) { |
| 89 | a = Square[T=$T](x) |
| 90 | o = One[T=$T]() |
| 91 | y = Add[T=$T](a:y, o:y) |
| 92 | return y = y:z:0 |
| 93 | } |
| 94 | )P"; |
| 95 | EXPECT_EQ(DebugString(fdef), e); |
| 96 | |
| 97 | // Instantiate one with T=float |
| 98 | InstantiationResult result; |
| 99 | TF_ASSERT_OK( |
| 100 | InstantiateFunction(fdef, Attrs({{"T", DT_FLOAT}}), GetOpSig, &result)); |
| 101 | const char* e2 = R"P( |
| 102 | (x:float) -> (y:float) { |
| 103 | a = Square[T=float](x) |
| 104 | o = One[T=float]() |
| 105 | y = Add[T=float](a, o) |
| 106 | } |
| 107 | )P"; |
| 108 | EXPECT_EQ(result.arg_types, DataTypeVector({DT_FLOAT})); |
| 109 | EXPECT_EQ(result.ret_types, DataTypeVector({DT_FLOAT})); |
| 110 | EXPECT_EQ(DebugString(result.nodes), e2); |
| 111 | } |
| 112 | |
| 113 | TEST(TFunc, ControlDep) { |
| 114 | auto fdef = FDH::Create( |
nothing calls this directly
no test coverage detected