Skip to main content

A decorator for automatic algorithms optimization via fast matrix exponentiation

Project description

A decorator for automatic algorithms optimization via fast matrix exponentiation

https://img.shields.io/travis/borzunov/cpmoptimize/master.svg https://img.shields.io/pypi/v/cpmoptimize.svg https://img.shields.io/pypi/pyversions/cpmoptimize.svg https://img.shields.io/pypi/implementation/cpmoptimize.svg

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

Project details


Download files

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

Source Distribution

cpmoptimize-0.4.tar.gz (13.6 kB view details)

Uploaded Source

File details

Details for the file cpmoptimize-0.4.tar.gz.

File metadata

  • Download URL: cpmoptimize-0.4.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for cpmoptimize-0.4.tar.gz
Algorithm Hash digest
SHA256 a6aa5c904790d51dc53b536dda50003dfda1ddd020636f1f5d716f2cafcefa7d
MD5 86f427dad3e27ee29a963fbb228996a9
BLAKE2b-256 761b7d5fb10ccef4cb2d3430ecaf2fa59fc12ef44b8324d8f929bfd816d52974

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page