scikit-hep / scikit-hep/formulate

more flexible to_string conversion to support ternary operators

Open
#24 0 comments 0 reactions 0 assignees View on GitHub

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):

  1. To enable support for this conversion, I would propose a to_string method that can be registered with the function in PFunction. 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] + ")").

  2. 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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.