Example #1
0
 def ReductionMethodFor_Decorator(ReductionMethod):
     # Prepare a reduction method generator
     assert inspect.isclass(ReductionMethod)
     ReductionMethodGenerator = _ReductionMethodGenerator(ReductionMethod)
     # Add to cache
     dispatch(Problem, name=category, module=_cache, replaces=replaces, replaces_if=replaces_if)(ReductionMethodGenerator)
     # Return unchanged reduction method
     return ReductionMethod
Example #2
0
 def ReducedProblemFor_Decorator(ReducedProblem):
     # Prepare a reduced problem generator
     assert inspect.isclass(ReducedProblem)
     ReducedProblemGenerator = _ReducedProblemGenerator(ReducedProblem)
     # Add to cache.
     dispatch(*(Problem, ReductionMethod), name="ReducedProblem", module=_cache, replaces=replaces, replaces_if=replaces_if)(ReducedProblemGenerator)
     # Return unchanged reduced problem
     return ReducedProblem
 def ReducedProblemDecoratorFor_Decorator(ReducedProblemDecorator):
     # Prepare a reduced problem decorator generator
     assert inspect.isfunction(ReducedProblemDecorator)
     ReducedProblemDecoratorGenerator = _ReducedProblemDecoratorGenerator(ReducedProblemDecorator)
     # Add to cache ((object, object) is a placeholder for (Problem, ReductionMethod) types)
     dispatch(*(object, object), name=Algorithm.__name__, module=_cache, replaces=replaces, replaces_if=replaces_if)(ReducedProblemDecoratorGenerator)
     # Return unchanged reduced problem decorator
     return ReducedProblemDecorator
 def ReductionMethodDecoratorFor_Decorator(ReductionMethodDecorator):
     # Prepare a reduction method decorator generator
     assert inspect.isfunction(ReductionMethodDecorator)
     ReductionMethodDecoratorGenerator = _ReductionMethodDecoratorGenerator(
         ReductionMethodDecorator)
     # Add to cache (object is a placeholder for Problem type)
     dispatch(object,
              name=Algorithm.__name__,
              module=_cache,
              replaces=replaces,
              replaces_if=replaces_if)(ReductionMethodDecoratorGenerator)
     # Return unchanged reduction method decorator
     return ReductionMethodDecorator
Example #5
0
 def backend_for_decorator(function):
     assert inspect.isfunction(function)
     assert hasattr(_cache, function.__name__) # it was either added by @abstract_backend or by previous @backend_for
     if not isinstance(getattr(_cache, function.__name__), Dispatcher): # added by @abstract_backend, first time @backend_for is called for this function name
         delattr(_cache, function.__name__) # make space for dispatcher object
     _cache.__all__.add(function.__name__)
     return dispatch(*inputs, module=_cache, replaces=replaces, replaces_if=replaces_if)(function)
Example #6
0
 def BackendFor_Decorator(Class):
     assert inspect.isclass(Class)
     assert hasattr(_cache, Class.__name__) # it was either added by @AbstractBackend or by previous @BackendFor
     if not isinstance(getattr(_cache, Class.__name__), Dispatcher): # added by @AbstractBackend, first time @BackendFor is called for this class name
         delattr(_cache, Class.__name__) # make space for dispatcher object
     _cache.__all__.add(Class.__name__)
     return dispatch(*inputs, module=_cache, replaces=replaces, replaces_if=replaces_if)(Class)