AureumChaos / LEAP

A general purpose Library for Evolutionary Algorithms in Python.
Academic Free License v3.0
81 stars 18 forks source link

Replace Primitive class with inspection #235

Open SigmaX opened 1 year ago

SigmaX commented 1 year ago

In #234, we introduced an optional class hierarchy for genetic programming primitives to allow a small optimization. But all these classes do is allow the arity of primitives to be queried.

@markcoletti points out that we could us reflection via inspect to access this information instead—eliminating the need for the class rappers.

lukepmccombs commented 1 year ago

I like the concept of this, although it would conflict with default arguments if they aren't considered as inputs to the function. From what I can find you can detect / extract default arguments fairly easily, but more exotic methods like curry or partial would probably still conflict. Maybe inspect as a default, but have a way to override the arity?

Edit for reference on detecting default parameters: https://stackoverflow.com/questions/12627118/get-a-function-arguments-default-value