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
routineslist of func

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

orderedbool

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__(self[, routines, ordered])

Initialize self.

append(self, routine)

Prepends a new routine to the selector

next(self)

Choose the next routine that requires performance analysis

prepend(self, routine)

Prepends a new routine to the selector

reset(self)

Reset the performance table to redo the performance checks

select_best(self[, routine])

Update the best routine, if applicable

start(self)

Start the performance profiler

stop(self, start)

Stop the performance profiler

append(self, routine)[source]

Prepends a new routine to the selector

Parameters
routinefunc

the new routine to be tested in the selector

property best
next(self)[source]

Choose the next routine that requires performance analysis

Returns
int

routine index

callable

func is the routine that is to be runned next (or if index is negative, then it refers to the most optimal routine

property ordered
property performances
prepend(self, routine)[source]

Prepends a new routine to the selector

Parameters
routinefunc

the new routine to be tested in the selector

reset(self)[source]

Reset the performance table to redo the performance checks

property routines
select_best(self, 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
routinefunc 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(self)[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(self, 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
startfloat

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