Skip to main content

cpmoptimize

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

Metadata

Release files for cpmoptimize 0.3.post2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cpmoptimize 0.3.post2
File Size Uploaded Provenance Actions
cpmoptimize-0.3.post2.tar.gz 23.9 kB Without provenance Details for cpmoptimize-0.3.post2.tar.gz

Release files / cpmoptimize-0.3.post2.tar.gz

Download URL cpmoptimize-0.3.post2.tar.gz
Size 23.9 kB
Tags Source
SHA-256 checksum
How to use checksums
d65fbe4e9b6d1832931d23b2afd5d56eff0fee6d7ababd08089a4fc12c83a14e
BLAKE2b-256 checksum
How to use checksums
c74eeb2afd1c9927491afac1382625fbe86dc21eaebbb89d53b3573a8ab599e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for cpmoptimize 0.3.post2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page