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

Support custom atomic operators #254

Merged

Conversation

jakobj
Copy link
Member

@jakobj jakobj commented Dec 17, 2020

This PR introduces a decorator which users can apply to custom functions which are then available as atomic operators in the strings defining the operation of custom nodes. Hard to explain, easy to show:

    @cgp.atomic_operator
    def f_scale(x):
        return 2.0 * x

    class MyScaledAdd(cgp.node.OperatorNode):
        _arity = 2
        _def_output = "f_scale((x_0 + x_1))"

These few lines introduced a new primitive, i.e., a new node function, to CGP. This approach also works for custom atomic operators which depend on external libraries.

closes #235

@jakobj jakobj added this to the 0.3.0 milestone Dec 17, 2020
@coveralls
Copy link
Collaborator

Coverage Status

Coverage increased (+0.02%) to 94.466% when pulling 54d1baa on jakobj:enh/custom-atomic-operators into f6143c5 on Happy-Algorithms-League:master.

Copy link
Contributor

@HenrikMettler HenrikMettler left a comment

Choose a reason for hiding this comment

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

This is so nice 😍 Maybe I like it too much to be critical, but everything looks good to me

Copy link
Member

@mschmidt87 mschmidt87 left a comment

Choose a reason for hiding this comment

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

Beautiful.

@jakobj jakobj merged commit d1038b8 into Happy-Algorithms-League:master Dec 26, 2020
@jakobj jakobj deleted the enh/custom-atomic-operators branch December 26, 2020 14:34
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.

Allow users to define custom atomic operators
4 participants