-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Parser] Fix tokenizing inf #7370
Conversation
Can you use |
BTW just to confirm, this fix should correctly handle the case of |
@altanh Supporting -inf was a bit tricky, but it works now. This is the new output after
|
@jroesch To support Now, a digit parsing in This way, negation of positive numbers and |
Hmm, the I also noticed we could maybe use
|
I suppose this is the exactly opposite approach to your current change, I think it depends on how much we care about this nested negation thing. |
yes I don't want to bother with nested negation either, but there is an annoying test tvm/tests/python/relay/test_ir_parser.py Lines 198 to 202 in 8daa97e
I didn't notice |
Hah, got it, I'm in favor of just deleting that test 😂 but I guess someone might depend on this behavior. Actually... we could do the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -212,6 +212,25 @@ struct Tokenizer { | |||
} | |||
} | |||
|
|||
Token ParseNumber(bool is_pos) { | |||
std::stringstream ss; | |||
while (More() && IsNumeric(Peek())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
out of the scope of this PR, but I imagine this is too loose in terms of accepting weird strings that satisfy the IsNumeric
constraint, such as 1e2e3+..2
. That being said, stod("1e2e3+..2")
returns 100
, so I guess it's alright lol.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is like some of the oldest tokenizer code, and I was just quickly trying to write one without getting super into regex, etc. Might be worth completely replacing soon.
LGTM |
* fix tokenizing inf * use ParseNumber to parse inf, handle -inf * fix neg handling * fixed multi negation * refactor * use while loop * simplyfing * fix lint * simpler implementation per altan's suggestion * disable flaky test
* fix tokenizing inf * use ParseNumber to parse inf, handle -inf * fix neg handling * fixed multi negation * refactor * use while loop * simplyfing * fix lint * simpler implementation per altan's suggestion * disable flaky test
* fix tokenizing inf * use ParseNumber to parse inf, handle -inf * fix neg handling * fixed multi negation * refactor * use while loop * simplyfing * fix lint * simpler implementation per altan's suggestion * disable flaky test
* fix tokenizing inf * use ParseNumber to parse inf, handle -inf * fix neg handling * fixed multi negation * refactor * use while loop * simplyfing * fix lint * simpler implementation per altan's suggestion * disable flaky test
Fixes #7339
Not sure if this is the best solution. Having
inff
in the printer output is dubious, but I kept it. If we want to special caseinf
in the printer that would also be easy.Also, do we care about single precision inf or double precision inf? (if there is any difference)
The output after
AnnotateSpans
@jroesch @altanh