Skip to main content
Help us improve Python packaging – donate today!

A decorator for automatic algorithms optimization via fast matrix exponentiation

Project Description

A decorator for automatic algorithms optimization via fast matrix exponentiation

Installation

You can install the stable version of the library using pip:

sudo pip install cpmoptimize

Or install a previously downloaded and extracted package:

sudo python setup.py install

Basic Example

Suppose we want to calculate the ten millionth Fibonacci number using a program in Python. The function with a trivial algorithm is rather slow:

def fib(n):
    a = 0
    b = 1
    for i in xrange(n):
        a, b = b, a + b
    return a

result = fib(10 ** 7)

# Time: 25 min 31 sec

But if we apply the optimizing decorator, the function will give you the answer much faster:

from cpmoptimize import cpmoptimize

@cpmoptimize()
def fib(n):
    a = 0
    b = 1
    for i in xrange(n):
        a, b = b, a + b
    return a

result = fib(10 ** 7)

# Time: 18 sec (85x faster)

Description

Actually, the decorator disassembles bytecode of a function using pretty byteplay library, analyzes the code, and tries to reduce time complexity of the algorithm used in it using fast matrix exponentiation.

The decorator uses a method implemented by Alexander Skidanov in his simple optimizing interpreter.

A detailed description of the library (including an idea explanation and an interface reference) is available in English and Russian.

Author

Copyright (c) 2014, 2015 Alexander Borzunov

Release history Release notifications

This version
History Node

0.3.post2

History Node

0.3.post1

History Node

0.3

History Node

0.2

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
cpmoptimize-0.3.post2.tar.gz (23.9 kB) Copy SHA256 hash SHA256 Source None Jul 27, 2015

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page