{"id":13498185,"url":"https://github.com/borzunov/cpmoptimize","last_synced_at":"2025-10-03T15:02:32.837Z","repository":{"id":20708269,"uuid":"23992154","full_name":"borzunov/cpmoptimize","owner":"borzunov","description":"🚀 🐍   Optimizes Python bytecode calculating linear recurrences, reducing the time complexity from O(n) to O(log n)","archived":false,"fork":false,"pushed_at":"2022-02-11T20:03:43.000Z","size":94,"stargazers_count":179,"open_issues_count":0,"forks_count":12,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-11-01T13:36:23.232Z","etag":null,"topics":["bytecode","linear-algebra","matrix-exponentiation","optimization","python","time-complexity"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/borzunov.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES.rst","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-09-13T10:57:15.000Z","updated_at":"2024-09-03T09:22:51.000Z","dependencies_parsed_at":"2022-09-11T01:11:54.862Z","dependency_job_id":null,"html_url":"https://github.com/borzunov/cpmoptimize","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borzunov%2Fcpmoptimize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borzunov%2Fcpmoptimize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borzunov%2Fcpmoptimize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/borzunov%2Fcpmoptimize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/borzunov","download_url":"https://codeload.github.com/borzunov/cpmoptimize/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246927839,"owners_count":20856198,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bytecode","linear-algebra","matrix-exponentiation","optimization","python","time-complexity"],"created_at":"2024-07-31T20:00:53.264Z","updated_at":"2025-10-03T15:02:25.586Z","avatar_url":"https://github.com/borzunov.png","language":"Python","readme":"===========\ncpmoptimize\n===========\n\n.. image:: https://img.shields.io/pypi/v/cpmoptimize.svg?color=blue\n    :target: https://pypi.python.org/pypi/cpmoptimize\n\n.. image:: https://img.shields.io/pypi/pyversions/cpmoptimize.svg\n    :target: https://pypi.python.org/pypi/cpmoptimize\n\n.. image:: https://img.shields.io/pypi/implementation/cpmoptimize.svg\n    :target: https://pypi.python.org/pypi/cpmoptimize\n\nDescription\n-----------\n\nThis library provides a decorator that disassembles the function's bytecode, checks if it calculates linear recurrences, and tries to reduce the algorithm's time complexity from O(n) to O(log n) using the `fast matrix exponentiation`_.\n\n.. _fast matrix exponentiation: https://en.wikipedia.org/wiki/Exponentiation_by_squaring\n\n**Detailed description:** Russian_, English_.\n\n.. _English: http://kukuruku.co/hub/algorithms/automatic-algorithms-optimization-via-fast-matrix-exponentiation\n.. _Russian: http://habrahabr.ru/post/236689/\n\nInspired by the `Alexander Skidanov`_'s `optimizing interpreter`_.\n\n.. _Alexander Skidanov: https://github.com/SkidanovAlex\n.. _optimizing interpreter: https://github.com/SkidanovAlex/interpreter\n\n**Update (Feb 2022):** This library was created in 2014 and only supports Python 2.6-2.7 (not Python 3). I don't plan to upgrade it myself but I'd be happy to help anyone willing to do that (this is a good exercise to understand how it works). If you're interested, please open an issue.\n\nExample\n-------\n\nSuppose we want to calculate the ten millionth `Fibonacci number`_ in Python. The function with a trivial algorithm is rather slow:\n\n.. code:: python\n\n    def fib(n):\n        a = 0\n        b = 1\n        for i in xrange(n):\n            a, b = b, a + b\n        return a\n\n    result = fib(10 ** 7)\n\n    # Time: 25 min 31 sec\n\nBut if we apply the optimizing decorator, the function will give you the answer much faster:\n\n.. code:: python\n\n    from cpmoptimize import cpmoptimize\n\n    @cpmoptimize()\n    def fib(n):\n        a = 0\n        b = 1\n        for i in xrange(n):\n            a, b = b, a + b\n        return a\n\n    result = fib(10 ** 7)\n\n    # Time: 18 sec (85x faster)\n\n.. _Fibonacci number: https://en.wikipedia.org/wiki/Fibonacci_number\n\nInstallation\n------------\n\nYou can install the stable version of the library using pip::\n\n    sudo pip install cpmoptimize\n\nOr install a previously downloaded and extracted package::\n\n    sudo python setup.py install\n\nAuthor\n------\n\nCopyright (c) 2014, 2015 Alexander Borzunov\n","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fborzunov%2Fcpmoptimize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fborzunov%2Fcpmoptimize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fborzunov%2Fcpmoptimize/lists"}