Skip to content
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

Parse inf nan #36

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Parse inf nan #36

wants to merge 1 commit into from

Conversation

kaushikcfd
Copy link
Collaborator

No description provided.

@@ -144,6 +144,8 @@ class Parser:
r"[0-9]*\.[0-9]+[eEdD][+-]?[0-9]+([a-zA-Z]*)\b"),
# has a letter tag
pytools.lex.RE(r"[0-9]+([a-zA-Z]+)"),
# inf, nan
pytools.lex.RE("inf"), pytools.lex.RE("nan"),
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't quite what Python does. nan is the identifier, not a floating point number. I do agree that we want literals for these guys, but I'm not totally sure I like these. Python's float("nan") seems a bit out of character for (e.g.) loopy. Any other ideas?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. The other possibility is to provide a namespace for such keywords, but that would violate
assert print(parse("inf")) == "inf"
  1. We could also make the parser take a flag to treat these as keywords or otherwise.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's wrong with letting user code run a mapper to run symbol lookup on these things? I think in loopy lang we will ultimately want to allow from numpy import inf, to provide a principled way of accessing these things. (To be clear, I am only thinking of data and LoopKernel objects as being potentially importable.) But doing so would require loopy to remain in charge of symbol lookup.

I'm OK with adding a flag for the behavior you propose though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants