Commit 8f83be7a by Tianqi Chen

[ATTR/SYMBOL] Expose op_name attr to python (#132)

* [ATTR/SYMBOL] Expose op_name attr to python

* fix xcode
parent 7acbbcef
...@@ -473,6 +473,9 @@ bool Symbol::GetAttr(const std::string& key, std::string* out) const { ...@@ -473,6 +473,9 @@ bool Symbol::GetAttr(const std::string& key, std::string* out) const {
if (key == "name") { if (key == "name") {
*out = node->attrs.name; *out = node->attrs.name;
return true; return true;
} else if (key == "op_name") {
*out = node->attrs.op->name;
return true;
} }
auto it = node->attrs.dict.find(key); auto it = node->attrs.dict.find(key);
if (it == node->attrs.dict.end()) return false; if (it == node->attrs.dict.end()) return false;
......
...@@ -45,6 +45,15 @@ def test_copy(): ...@@ -45,6 +45,15 @@ def test_copy():
name='exp', gpu=1, attr={"kk": "1"}) name='exp', gpu=1, attr={"kk": "1"})
assert y.__copy__().debug_str() == y.debug_str() assert y.__copy__().debug_str() == y.debug_str()
def test_op_name():
x = sym.Variable('x')
y = sym.exp(x)
op_name = y.attr("op_name")
op_func = sym.__dict__[op_name]
z = op_func(x)
def test_control_dep(): def test_control_dep():
x = sym.Variable('x') x = sym.Variable('x')
y = sym.conv2d(data=x, name='conv') y = sym.conv2d(data=x, name='conv')
...@@ -53,6 +62,7 @@ def test_control_dep(): ...@@ -53,6 +62,7 @@ def test_control_dep():
t._add_control_deps([z, y]) t._add_control_deps([z, y])
if __name__ == "__main__": if __name__ == "__main__":
test_op_name()
test_copy() test_copy()
test_default_input() test_default_input()
test_compose() test_compose()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment