Skip to content
An intelligent block matrix library for numpy, PyTorch, and beyond.
Branch: master
Clone or download
Latest commit 022fd9b Feb 14, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
block Update block_tridiag. Feb 14, 2019
images Make the colors in the example consistent. Feb 6, 2017
.gitignore Initial commit. Feb 6, 2017
.travis.yml Update travis flake checks. Apr 12, 2017
LICENSE Initial commit. Feb 6, 2017 Bump to v0.0.5. Apr 12, 2017 Add flake8 check to travis. Apr 7, 2017

Block • Build Status License PyPi

An intelligent block matrix library for numpy, PyTorch, and beyond. Crafted by Brandon Amos with significant contributions by Eric Wong.

Why do we need an intelligent block matrix library?

Let's try to construct the KKT matrix from Mattingley and Boyd's CVXGEN paper in numpy and PyTorch:

Without block, there is no way to infer the appropriate sizes of the zero and identity matrix blocks. It is an inconvenience to think about what size these matrices should be.

What does block do?

Block acts a lot like np.bmat and replaces:

  • Any constant with an appropriately shaped block matrix filled with that constant.
  • The string 'I' with an appropriately shaped identity matrix.
  • The string '-I' with an appropriately shaped negated identity matrix.
  • [Request more features.]

Isn't constructing large block matrices with a lot of zeros inefficient?

Yes, block is meant to be a quick prototyping tool and there's probably a more efficient way to solve your system if it has a lot of zeros or identity elements.

How does block handle numpy and PyTorch with the same interface?

I wrote the logic to handle matrix sizing to be agnostic of the matrix library being used. numpy and PyTorch are just backends. More backends can easily be added for your favorite Python matrix library.

class Backend(metaclass=ABCMeta):

    def extract_shape(self, x): pass

    def build_eye(self, n): pass

    def build_full(self, shape, fill_val): pass

    def build(self, rows): pass

    def is_complete(self, rows): pass

Getting Started

  • Install: pip install block
  • Usage: from block import block
  • Run tests in nosetests

Issues and Contributions

I'd be happy to hear from you about any issues or features you add, please file an issue or send in a PR.


This repository is Apache-licensed.

You can’t perform that action at this time.