Selector¶
-
class
sisl.
Selector
(routines=None, ordered=False)¶ Bases:
object
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. The performance of a method is based on a pre-selected metric (time, memory, etc.).
The chosen method will be based on the routine which has the highest metric. E.g. for time the metric could be \(1/(stop - start)\).
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.
-
routines
¶ this is a list of functions that will be selected from.
- Type
list of func
-
ordered
¶ 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 currently runned routines.
- Type
Attributes
__doc__
__module__
__slots__
_best
_metric
_ordered
_routines
Methods
__call__
(*args, **kwargs)Call the function that optimizes the run-time the most
__delattr__
Implement delattr(self, name).
__dir__
Default dir() implementation.
__eq__
Return self==value.
__format__
Default object formatter.
__ge__
Return self>=value.
__getattribute__
Return getattr(self, name).
__gt__
Return self>value.
__hash__
Return hash(self).
__init__
([routines, ordered])Initialize self.
__init_subclass__
This method is called when a class is subclassed.
__le__
Return self<=value.
__len__
()Number of routines that it can select from
__lt__
Return self<value.
__ne__
Return self!=value.
__new__
Create and return a new object.
__reduce__
Helper for pickle.
__reduce_ex__
Helper for pickle.
__repr__
Return repr(self).
__setattr__
Implement setattr(self, name, value).
__sizeof__
Size of object in memory, in bytes.
__str__
()A representation of the current selector state
__subclasshook__
Abstract classes can override this to customize issubclass().
append
(routine)Prepends a new routine to the selector
next
()Choose the next routine that requires metric analysis
prepend
(routine)Prepends a new routine to the selector
reset
()Reset the metric table to redo the performance checks
select_best
([routine])Update the
best
routine, if applicablestart
()Start the metric profiler
stop
(start)Stop the metric profiler
-
append
(routine)[source]¶ Prepends a new routine to the selector
- Parameters
routine (func) – the new routine to be tested in the selector
-
property
best
¶
-
property
metric
¶
-
next
()[source]¶ Choose the next routine that requires metric 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
¶
-
prepend
(routine)[source]¶ Prepends a new routine to the selector
- Parameters
routine (func) – the new routine to be tested in the selector
-
property
routines
¶
-
select_best
(routine=None)[source]¶ Update the
best
routine, if applicableUpdate 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 metrics. If, however, not all metric 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 metric profiler
This routine should return an initial state value. The difference between stop() - start() should yield a metric identifier which may be used to control the used algorithm.
The best method A large metric identifier results in the use of the routine.
-
stop
(start)[source]¶ Stop the metric profiler
This routine returns the actual metric for the method. Its input is what
start
returns and it may be of any value.A large metric identifier results in the use of the routine.
- Parameters
start (obj) – the output of the start() routine to convert to actual metric identifier
-