scikit-hep / scikit-hep/formulate
more flexible to_string conversion to support ternary operators
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14
- Forks
- 6
- Avg merge
- 4h 20m
- Merged PRs (30d)
- 4
Description
First of, thanks a lot for this great package!
Numexpr supports where whereas ROOT supports an (equivalent) ternary operator from C++ (Expression1 ? Expression2 : Expression3). While the former is already implemented and works fine with the current function registry, the latter cannot (AFAIK) be supported with the current construction of joining the arguments withing brackets with ,.
Two ideas (using as an example sqrt):
-
To enable support for this conversion, I would propose a
to_stringmethod that can be registered with the function inPFunction. Defaults to the current conversion. This takes the name of the method and arguments.
Disadvantage: we have too much freedom (e.g. for sqrt:
('sqrt', 1, lambda f, args: f + "(" + args[0] + ")")
or duplicate the name
('sqrt', 1, lambda args: 'sqrt' + "(" + args[0] + ")"). -
use string formatting: require the signature to be contained in the string definition:
'(sqrt({})', 1).
Disadvantage: arbitrary number of arguments?
I would propose to go for the first solution.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading PFunction and the sqrt example in formulate/backends/numexpr.py, then compare the current argument-joining behavior with the proposed registered to_string conversion. Done means function definitions can support ternary-style formatting while preserving the existing default conversion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100