CAPI Graph test in tensorflow/c/c_api_test.c
import std.stdio; writeln("CAPI Graph test"); TF_Status* s = TF_NewStatus(); TF_Graph* graph = TF_NewGraph(); // Make a placeholder operation. TF_Operation* feed = Placeholder(graph, s); assertStatus(s); // Test TF_Operation*() query functions. assert(TF_OperationName(feed).fromStringz == "feed"); assert(TF_OperationOpType(feed).fromStringz == "Placeholder"); assert(TF_OperationDevice(feed).fromStringz == ""); assert(TF_OperationNumOutputs(feed) == 1); assert(TF_OperationOutputType(TF_Output(feed, 0)) == TF_INT32); assert(TF_OperationOutputListLength(feed, "output", s) == 1); assertStatus(s); assert(TF_OperationNumInputs(feed) == 0); assert(TF_OperationOutputNumConsumers(TF_Output(feed, 0)) == 0); assert(TF_OperationNumControlInputs(feed) == 0); assert(TF_OperationNumControlOutputs(feed) == 0); // TODO(karita): implement AttrValue type switching by `value_case` AttrValue attrValue; assert(GetAttrValue(feed, "dtype", &attrValue, s)); assert(attrValue.type == TENSORFLOW__DATA_TYPE__DT_INT32); // Test not found errors in TF_Operation*() query functions. assert(TF_OperationOutputListLength(feed, "bogus", s) == -1); assert(TF_GetCode(s) == TF_INVALID_ARGUMENT); assert(!GetAttrValue(feed, "missing", &attrValue, s)); assert(TF_Message(s).fromStringz == "Operation 'feed' has no attr named 'missing'."); // Make a constant oper with the scalar "3". TF_Operation* three = ScalarConst(3, graph, s); assertStatus(s); // Add oper. Add(feed, three, graph, s); assertStatus(s);
Adds two tensors.