[SciPy-dev] change scipy.optimize function signatures?? FEEDBACK NEEDED!! (ticket 285)

Alan G Isaac aisaac@american....
Thu Jul 19 10:33:56 CDT 2007


Dmitrey has raised some questions about ticket 285:
http://projects.scipy.org/scipy/scipy/ticket/285

The changes proposed are not complex to implement,
but they increase the interface complexity.
They also raise some design considerations.

For example, according to the ticket, the signature for brent would change from
def brent(func, args=(), brack=None, tol=1.48e-8, full_output=0, maxiter=500):
to
def brent(func, args=(), brack=None, tol=1.48e-8, full_output=0, maxiter=500, bracket_keywords = {} ):

In my personal view, this signature is already messy.
If it is to grow an argument, I suggest that the argument
be a parameters object.

This would work something like the following.
(No deep thought on this yet.)

class OptizationParams:
    def __init__(self, **kwargs):
        self.set_defaults()
        for k,v in kwargs.iteritems():
            if hasattr(self, k):
                setattr(self, k, v)
            else:
                raise AttributeError
    def set_defaults(self):
        self.args = ()
        self.tol = 1.48e-8
        self.full_output=0
        self.maxiter=500
        self.bracket_interval = None
        self.bracket_grow_limit = None

The signature for brent would become
def brent(func, params=OptizationParams(), **kwargs):

Any kwargs provided to `brent` would override the values in 
the OptParam instance.  This should be fully backwards 
compatible and, looking forward, very flexible.

Comments?

Cheers,
Alan Isaac




More information about the Scipy-dev mailing list