From 32b31ea620a0aa63ea83f18492db07516d3fba00 Mon Sep 17 00:00:00 2001 From: Zack Chen Date: Sat, 26 Jun 2021 20:35:48 +0800 Subject: [PATCH 1/2] [Relay][Parser] Support slash in identifier. Variables from tensorflow may contains '/' in name (x/y/z). --- src/parser/tokenizer.h | 4 +++- tests/python/relay/test_ir_text_printer.py | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/parser/tokenizer.h b/src/parser/tokenizer.h index e26c97429d6b..d7b3b3f6f681 100644 --- a/src/parser/tokenizer.h +++ b/src/parser/tokenizer.h @@ -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); } diff --git a/tests/python/relay/test_ir_text_printer.py b/tests/python/relay/test_ir_text_printer.py index b4d02e4815fb..86caf7dcffb8 100644 --- a/tests/python/relay/test_ir_text_printer.py +++ b/tests/python/relay/test_ir_text_printer.py @@ -285,5 +285,12 @@ 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) + + if __name__ == "__main__": pytest.main([__file__]) From 97e8e2cdcece53c5a62457989429e16b5e40d456 Mon Sep 17 00:00:00 2001 From: Zack Chen Date: Tue, 29 Jun 2021 09:28:24 +0800 Subject: [PATCH 2/2] Check identifier name after parsing. --- tests/python/relay/test_ir_text_printer.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/python/relay/test_ir_text_printer.py b/tests/python/relay/test_ir_text_printer.py index 76fb3cf60bf0..2834bba9248b 100644 --- a/tests/python/relay/test_ir_text_printer.py +++ b/tests/python/relay/test_ir_text_printer.py @@ -289,6 +289,8 @@ def test_slash_in_identifier(): y = relay.var("base/y") z = x + y txt = astext(z) + assert "base/x" in txt + assert "base/y" in txt if __name__ == "__main__":