pymor.algorithms.rules¶
Module Contents¶
Classes¶
Decorator to make a method a rule in a given |
|
Decorator to make a method a rule in a given |
|
|
|
|
|
|
|
|
|
|
|
Meta class for |
|
Define algorithm by a table of match conditions and corresponding actions. |
Functions¶
- class pymor.algorithms.rules.rule[source]¶
Decorator to make a method a rule in a given
RuleTable.The decorated function will become the
actionto perform in case the rulematches. Matching conditions are specified by subclassing and overriding thematchesmethod.If an action is decorated by multiple rules, all these rules must match for the action to apply.
- class pymor.algorithms.rules.match_class_base(*classes)[source]¶
Bases:
ruleDecorator to make a method a rule in a given
RuleTable.The decorated function will become the
actionto perform in case the rulematches. Matching conditions are specified by subclassing and overriding thematchesmethod.If an action is decorated by multiple rules, all these rules must match for the action to apply.
- class pymor.algorithms.rules.match_class(*classes)[source]¶
Bases:
match_class_baserulethat matches when obj is instance of one of the given classes.
- class pymor.algorithms.rules.match_class_all(*classes)[source]¶
Bases:
match_class_baserulethat matches when each item of obj is instance of one of the given classes.
- class pymor.algorithms.rules.match_class_any(*classes)[source]¶
Bases:
match_class_baserulethat matches when any item of obj is instance of one of the given classes.
- class pymor.algorithms.rules.match_generic(condition, condition_description=None)[source]¶
Bases:
rulerulewith matching condition given by an arbitrary function.Parameters
- condition
Function of one argument which checks if given object matches condition.
- condition_description
Optional string describing the condition implemented by
condition.
- class pymor.algorithms.rules.RuleTableMeta(cls, name, bases, namespace)[source]¶
Bases:
pymor.core.base.UberMetaMeta class for
RuleTable.
- class pymor.algorithms.rules.RuleTable(use_caching=False)[source]¶
Bases:
pymor.core.base.BasicObjectDefine algorithm by a table of match conditions and corresponding actions.
RuleTablemanages a table ofrules, stored in therulesattributes, which can beappliedto given objects.A new table is created by subclassing
RuleTableand defining new methods which are decorated withmatch_class,match_genericor anotherrulesubclass. The order of the method definitions determines the order in which the definedrulesare applied.Parameters
- use_caching
If
True, cache results ofapply.
- classmethod breakpoint_for_obj(cls, obj)[source]¶
Add a conditional breakpoint for given object.
Break execution in
apply, when being applied to a certain object.Parameters
- obj
Object for which to add the conditional breakpoint.
- classmethod breakpoint_for_name(cls, name)[source]¶
Add a conditional breakpoint for objects of given name.
Break execution in
apply, when being applied to an object with a certain name.Parameters
- name
nameof the object for which to add the conditional breakpoint.
- apply(self, obj)[source]¶
Sequentially apply rules to given object.
This method iterates over all rules of the given
RuleTable. For eachrule, it is checked if itmatchesthe given object. IfFalse, the nextrulein the table is considered. IfTruethe correspondingactionis executed withobjas parameter. If execution ofactionraisesRuleNotMatchingError, the rule is considered as not matching, and execution continues with evaluation of the next rule. Otherwise, execution is stopped and the return value ofrule.actionis returned to the caller.If no
rulematches, aNoMatchingRuleErroris raised.Parameters
- obj
The object to apply the
RuleTableto.
Returns
Return value of the action of the first matching
rulein the table.Raises
- NoMatchingRuleError
No
rulecould be applied to the given object.
- apply_children(self, obj, children=None)[source]¶
Apply rules to all children of the given object.
This method calls
applyto each child of the given object. The children of the object are either provided by thechildrenparameter or automatically inferred by theget_childrenmethod.Parameters
- obj
The object to apply the
RuleTableto.- children
Noneor a list of attribute names defining the children to consider.
Returns
Result of : meth:
applyfor all given children.
- replace_children(self, obj, children=None)[source]¶
Replace children of object according to rule table.
Same as
apply_children, but additionally callsobj.with_to replace the children ofobjwith the result of the correspondingapplycall.