samskalicky commented on a change in pull request #17034: Dynamic subgraph property URL: https://github.com/apache/incubator-mxnet/pull/17034#discussion_r362102949
########## File path: example/extensions/lib_subgraph/subgraph_lib.cc ########## @@ -0,0 +1,278 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/*! + * Copyright (c) 2019 by Contributors + * \file subgraph_lib.cc + * \brief subgraph operator implementation library file + */ + +#include <math.h> +#include <iostream> +#include <algorithm> +#include "lib_api.h" + +MXReturnValue parseAttrs(std::map<std::string, std::string> attrs, + int* num_in, int* num_out) { + *num_in = 1; + *num_out = 1; + if (attrs.count(SUBGRAPH_SYM_JSON)) { + // example of subgraph json parsing + JsonParser jp; + JsonVal val = jp.parse_to_json(attrs[SUBGRAPH_SYM_JSON]); + int input = 0; + for (auto &item : val.map[JsonVal("nodes")].list) { + if (item.map[JsonVal("op")].str == "null") + input++; + } + int output = val.map[JsonVal("heads")].list.size(); + *num_in = input; + *num_out = output; + } + return MX_SUCCESS; +} + +MXReturnValue inferType(std::map<std::string, std::string> attrs, Review comment: Thanks for the comments @guanxinq. Heres the original custom operator PR for reference #15921 this is an API that was added in that PR. In this PR we're just implementing a library using that API. There is a separate github issue for suggestions for a 2nd custom op PR that @rondogency is planning to work on #17006. You can leave these kind of comments there to make enhancements on that PR. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
