{"id":13936617,"url":"https://github.com/bamos/block","last_synced_at":"2025-04-04T11:08:02.261Z","repository":{"id":57415648,"uuid":"81109221","full_name":"bamos/block","owner":"bamos","description":"An intelligent block matrix library for numpy, PyTorch, and beyond.","archived":false,"fork":false,"pushed_at":"2024-08-04T14:40:46.000Z","size":192,"stargazers_count":305,"open_issues_count":5,"forks_count":32,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-03-28T10:04:59.428Z","etag":null,"topics":["deep-learning","linear-algebra","numpy","pytorch"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bamos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-02-06T16:50:25.000Z","updated_at":"2025-03-23T03:33:32.000Z","dependencies_parsed_at":"2024-04-27T23:59:52.303Z","dependency_job_id":"4ada096a-9932-4bb1-8223-df2aeed1aad8","html_url":"https://github.com/bamos/block","commit_stats":{"total_commits":44,"total_committers":6,"mean_commits":7.333333333333333,"dds":0.25,"last_synced_commit":"6e4115785e661554348cd52f6cef927c49b2e7f5"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bamos%2Fblock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bamos%2Fblock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bamos%2Fblock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bamos%2Fblock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bamos","download_url":"https://codeload.github.com/bamos/block/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247166166,"owners_count":20894654,"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":["deep-learning","linear-algebra","numpy","pytorch"],"created_at":"2024-08-07T23:02:51.103Z","updated_at":"2025-04-04T11:08:02.241Z","avatar_url":"https://github.com/bamos.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# Block • [![License][license-image]][license] [![PyPi][pypi-image]][pypi]\n\n[license-image]: http://img.shields.io/badge/license-Apache--2-blue.svg?style=flat\n[license]: LICENSE\n\n[pypi-image]: https://img.shields.io/pypi/v/block.svg\n[pypi]: https://pypi.python.org/pypi/block\n\n*An intelligent block matrix library for numpy, PyTorch, and beyond.\nCrafted by [Brandon Amos](http://bamos.github.io) with significant\ncontributions by [Eric Wong](http://www.cs.cmu.edu/~ericwong/).*\n\n---\n\n## Why do we need an intelligent block matrix library?\n\nLet's try to construct the KKT matrix from Mattingley and Boyd's\n[CVXGEN](http://stanford.edu/~boyd/papers/pdf/code_gen_impl.pdf)\npaper in numpy and PyTorch:\n\n![](images/cvxgen-K.png)\n\nWithout `block`, there is no way to infer the appropriate sizes of\nthe zero and identity matrix blocks.\nIt is an inconvenience to think about what size these\nmatrices should be.\n\n![](images/example.png)\n\n## What does `block` do?\n\nBlock acts a lot like `np.bmat` and replaces:\n\n+ Any constant with an appropriately shaped block matrix\n  filled with that constant.\n+ The string `'I'` with an appropriately shaped identity matrix.\n+ The string `'-I'` with an appropriately shaped negated identity matrix.\n+ [[Request more features.]](https://github.com/bamos/block/issues)\n\n\n## Isn't constructing large block matrices with a lot of zeros inefficient?\n\nYes, `block` is meant to be a quick prototyping tool and\nthere's probably a more efficient way to solve your system\nif it has a lot of zeros or identity elements.\n\n## How does `block` handle numpy and PyTorch with the same interface?\n\nI wrote the logic to handle matrix sizing to be agnostic\nof the matrix library being used.\nnumpy and PyTorch are just backends.\nMore backends can easily be added for your favorite\nPython matrix library.\n\n```Python\nclass Backend(metaclass=ABCMeta):\n\n    @abstractmethod\n    def extract_shape(self, x): pass\n\n    @abstractmethod\n    def build_eye(self, n): pass\n\n    @abstractmethod\n    def build_full(self, shape, fill_val): pass\n\n    @abstractmethod\n    def build(self, rows): pass\n\n    @abstractmethod\n    def is_complete(self, rows): pass\n```\n\n# Getting Started\n\n+ Install: `pip install block`\n+ Usage: `from block import block`\n+ Run tests in `test.py`: `nosetests test.py`\n\n# Issues and Contributions\n\nI'd be happy to hear from you about any issues or features you\nadd, please [file an issue](https://github.com/bamos/block/issues)\nor [send in a PR](https://github.com/bamos/block/pulls).\n\n# Licensing\n\nThis repository is\n[Apache-licensed](https://github.com/bamos/block/blob/master/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbamos%2Fblock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbamos%2Fblock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbamos%2Fblock/lists"}