| 670 | } |
| 671 | |
| 672 | void TF_GraphCopyFunction(TF_Graph* g, const TF_Function* func, |
| 673 | const TF_Function* grad, TF_Status* status) { |
| 674 | if (func == nullptr) { |
| 675 | status->status = InvalidArgument( |
| 676 | "'func' argument to TF_GraphCopyFunction cannot be null"); |
| 677 | return; |
| 678 | } |
| 679 | |
| 680 | // TODO(iga): Add AddFunctionDef() and AddGradientDef() methods to graph |
| 681 | // to avoid the extra copy here. |
| 682 | tensorflow::FunctionDefLibrary fdef_lib; |
| 683 | *fdef_lib.add_function() = func->fdef; |
| 684 | if (grad) { |
| 685 | *fdef_lib.add_function() = grad->fdef; |
| 686 | tensorflow::GradientDef* gdef = fdef_lib.add_gradient(); |
| 687 | gdef->set_function_name(func->fdef.signature().name()); |
| 688 | gdef->set_gradient_func(grad->fdef.signature().name()); |
| 689 | } |
| 690 | |
| 691 | tensorflow::mutex_lock l(g->mu); |
| 692 | status->status = g->graph.AddFunctionLibrary(fdef_lib); |
| 693 | } |
| 694 | |
| 695 | int TF_GraphNumFunctions(TF_Graph* g) { |
| 696 | tensorflow::mutex_lock l(g->mu); |