Beispiel #1
0
def horner_form(thing, memo=None):
    """Return the sequence of Horner's method operations that evaluates the argument
    performs search on variables to determine the optimal order to evaluate them
    is otherwise a greedy algorithm"""
    if not thing.proper:
        raise ValueError(
            'Can only put proper Terms and Polynomials into Horner form')

    def inner(thing, var):
        if isinstance(thing, Term):
            return _horner_form_term(thing)
        elif var is None:
            if not isinstance(thing, Polynomial):
                # immediate error
                inner(thing, object())
            return _horner_form_search(thing, inner)
        elif isinstance(thing, Polynomial):
            return _horner_form_poly(thing, var, inner)
        else:
            raise TypeError(
                "Unknown type %s in horner_form" % repr(type(thing)), thing)

    if memo is not None:
        inner = memoize(memo)(inner)
    return _horner_cleanup(inner(thing, None))
Beispiel #2
0
def main_interface():
    profile = False
    help, vim, emacs, error_checking = False, False, False, False
    opts, args = getopt.getopt(sys.argv[1:-1], "h", \
                               ["help", "vim", "emacs", "error-checking", \
                                "memoize", "profile"])
    for opt, arg in opts:
        if opt in ("-h", "--help"):
            help = True
        elif opt == '--vim':
            vim = True
        elif opt == '--memoize':
            memoize(Symbol.get_terminal_equivalent_regexes)
            memoize(Symbol.getRightRegexes)
            memoize(Symbol.getLeftRegexes)
            memoize(Symbol.get_contexts)
        elif opt == '--profile':
            profile = True
        elif opt == '--emacs':
            emacs = True
        elif opt == '--error-checking':
            error_checking = True

    filename=sys.argv[-1]
    def do_it():
        if(help):
            usage()
            sys.exit()
    
        if(vim):
            generate_vim(filename,error_checking)
    
        if(emacs):
            generate_emacs(filename)
    
        if(not emacs and not vim):
            usage()
            sys.exit(2)
    if profile:
        fn = "sample%s.prof" % "".join(sys.argv[1:-1])
        prof = hotshot.Profile(fn)
        prof.runcall(do_it)
        prof.close()
        stats = hotshot.stats.load(fn)
        stats.strip_dirs()
        stats.sort_stats('time', 'calls')
        stats.print_stats()
    else:
        do_it()
Beispiel #3
0
def horner_form_basic(thing, memo=None):
    """Return the sequence of Horner's method operations that evaluates the argument
    chooses variables in lexicographic order and is a purely greedy algorithm."""
    if not thing.proper:
        raise ValueError('Can only put proper Terms and Polynomials into Horner form')
    def inner(thing, _):
        var = min(thing.vars) if thing.vars else None
        if isinstance(thing, Term):
            return _horner_form_term(thing)
        elif isinstance(thing, Polynomial):
            return _horner_form_poly(thing, var, inner)
        else:
            raise TypeError("Unknown type %s in horner_form_basic" % repr(type(thing)), thing)
    if memo is not None:
        inner = memoize(memo)(inner)
    return _horner_cleanup(inner(thing, None))
Beispiel #4
0
def horner_form_basic(thing, memo=None):
    """Return the sequence of Horner's method operations that evaluates the argument
    chooses variables in lexicographic order and is a purely greedy algorithm."""
    if not thing.proper:
        raise ValueError(
            'Can only put proper Terms and Polynomials into Horner form')

    def inner(thing, _):
        var = min(thing.vars) if thing.vars else None
        if isinstance(thing, Term):
            return _horner_form_term(thing)
        elif isinstance(thing, Polynomial):
            return _horner_form_poly(thing, var, inner)
        else:
            raise TypeError(
                "Unknown type %s in horner_form_basic" % repr(type(thing)),
                thing)

    if memo is not None:
        inner = memoize(memo)(inner)
    return _horner_cleanup(inner(thing, None))
Beispiel #5
0
def horner_form(thing, memo=None):
    """Return the sequence of Horner's method operations that evaluates the argument
    performs search on variables to determine the optimal order to evaluate them
    is otherwise a greedy algorithm"""
    if not thing.proper:
        raise ValueError('Can only put proper Terms and Polynomials into Horner form')

    def inner(thing, var):
        if isinstance(thing, Term):
            return _horner_form_term(thing)
        elif var is None:
            if not isinstance(thing, Polynomial):
                # immediate error
                inner(thing, object())
            return _horner_form_search(thing, inner)
        elif isinstance(thing, Polynomial):
            return _horner_form_poly(thing, var, inner)
        else:
            raise TypeError("Unknown type %s in horner_form" % repr(type(thing)), thing)
    if memo is not None:
        inner = memoize(memo)(inner)
    return _horner_cleanup(inner(thing, None))
	def wrapper(func):
		memoized_func = memoize(func)
		file_cache = file_dict(filename)
		file_cache.update(memoized_func.cache)
		memoized_func.cache = file_cache
		return memoized_func
Beispiel #7
0
def forceRun(cmd):
    set_force_build(True)
    status = memoize(cmd)
    set_force_build(False)
    if status: sys.exit(status)
Beispiel #8
0
def run(cmd):
    status = memoize(cmd)
    if status: sys.exit(status)
Beispiel #9
0
def run(cmd):
  """ Run a shell command with memoization, exit if it fails """
  status = memoize(cmd)
  if status: sys.exit(1)
Beispiel #10
0
from rebrickable.swagger_client import ApiClient
from rebrickable.swagger_client import Configuration
from rebrickable.swagger_client import LegoApi
import pprint
import dotenv
dotenv.load_dotenv(dotenv.find_dotenv())

config = Configuration()
config.host = 'https://rebrickable.com'
config.api_key = os.environ['REBRICKABLE_API_KEY']

api_client = ApiClient(header_name='Authorization',
                       header_value='key ' + config.api_key)
api = LegoApi(api_client)

api_client.call_api = memoize(RateLimited(2)(api_client.call_api))

themes = api.lego_themes_list()


def filter_theme(t, p):
    print(p.name)
    return p.name == "Harry Potter"


filtered_themes = []
for result_theme in themes.results:
    if result_theme.parent_id is not None:
        theme = api.lego_themes_read(result_theme.id)
        parent_theme = api.lego_themes_read(theme.parent_id)
Beispiel #11
0
def run(cmd):
    if not doclean:
        status = memoize(cmd)
        if status:
            print >> sys.stderr, '*** FAILURE ***'
            sys.exit(status)
Beispiel #12
0
def run(cmd):
    if not doclean:
        status = memoize(cmd)
        if status:
            print >>sys.stderr, '*** FAILURE ***'
            sys.exit(status)