Selector

class sisl.Selector(routines=None, ordered=False)[source]

Base class for implementing a selector of class routines

This class should contain a list of routines and may then be used to always return the best performant routine.

This is done on a per-class basis where this class should initially determine which routine is the best performing one and then always return that one.

Attributes:
routines : list of func

this is a list of functions that will be selected from.

ordered : bool

If False a simple selection of the most performant one will be chosen. If True, it will check the routines in order and once one of the routines is less performant it will choose from the setof runned routines.

Attributes

best
ordered
performances
routines

Methods

__init__([routines, ordered]) Initialize self.
append(routine) Prepends a new routine to the selector
next() Choose the next routine that requires performance analysis
prepend(routine) Prepends a new routine to the selector
reset() Reset the performance table to redo the performance checks
select_best([routine]) Update the best routine, if applicable
start() Start the performance profiler
stop(start) Stop the performance profiler
append(routine)[source]

Prepends a new routine to the selector

Parameters:
routine : func

the new routine to be tested in the selector

best
next()[source]

Choose the next routine that requires performance analysis

Returns:
int, func :

a tuple with the int specifying the routine index. func is the routine that is to be runned.

ordered
performances
prepend(routine)[source]

Prepends a new routine to the selector

Parameters:
routine : func

the new routine to be tested in the selector

reset()[source]

Reset the performance table to redo the performance checks

routines
select_best(routine=None)[source]

Update the best routine, if applicable

Update the selector to choose the best method. If not all routines have been carried through, then no best routine will be selected (unless self.ordered is True).

By passing a routine as an argument that given routine will by default be the chosen best algorithm.

Parameters:
routine : func or str

If None is passed (the default) it will select the best default routine based on the stored performances. If, however, not all performance values has been created no routine will be selected.

If passing a func that function will be chosen as the best method

start()[source]

Start the performance profiler

This routine should return an initial state value. The difference between stop() - start() should yield a performance identifier which may be used to control the used algorithm.

A large performance identifier results in the use of the routine.

stop(start)[source]

Stop the performance profiler

This routine should return an initial state value. The difference between stop() - start() should yield a performance identifier which may be used to control the used algorithm.

A large performance identifier results in the use of the routine.

Parameters:
start : float

the output of the start() routine to convert to actual performance identifier