Skip to content

more flexible to_string conversion to support ternary operators #24

@jonas-eschle

Description

@jonas-eschle

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions