Coder Social home page Coder Social logo

block's Introduction

Block • [ ![Build Status] travis-image ] travis [ License license-image ] license

An intelligent block matrix library for numpy, PyTorch, and beyond.


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):

    @abstractmethod
    def extract_shape(self, x): pass

    @abstractmethod
    def build_eye(self, n): pass

    @abstractmethod
    def build_full(self, shape, fill_val): pass

    @abstractmethod
    def build(self, rows): pass

    @abstractmethod
    def is_complete(self, rows): pass

Getting Started

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

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.

Licensing

This repository is Apache-licensed.

block's People

Contributors

chenyuntc avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.