Skip to content

Commit

Permalink
[Relay][Parser] Support slash in identifier. (apache#8352)
Browse files Browse the repository at this point in the history
* [Relay][Parser] Support slash in identifier.

Variables from tensorflow may contains '/' in name (x/y/z).

* Check identifier name after parsing.
  • Loading branch information
zackcquic authored and ylc committed Jan 13, 2022
1 parent 0725a57 commit 0de7465
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/parser/tokenizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ bool IsNumeric(char c) {
!IsWhitespace(c);
}

bool IsIdentLetter(char c) { return '_' == c || ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z'); }
bool IsIdentLetter(char c) {
return '_' == c || c == '/' || ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
}

bool IsIdent(char c) { return IsIdentLetter(c) || IsDigit(c); }

Expand Down
9 changes: 9 additions & 0 deletions tests/python/relay/test_ir_text_printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,5 +284,14 @@ def test_optional_info():
assert txt.count("/* ty=int32 */") == 3


def test_slash_in_identifier():
x = relay.var("base/x")
y = relay.var("base/y")
z = x + y
txt = astext(z)
assert "base/x" in txt
assert "base/y" in txt


if __name__ == "__main__":
pytest.main([__file__])

0 comments on commit 0de7465

Please sign in to comment.