• Stars
    star
    297
  • Rank 140,075 (Top 3 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created almost 8 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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

    @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.

More Repositories

1

dcgan-completion.tensorflow

Image Completion with Deep Learning in TensorFlow
Python
1,308
star
2

densenet.pytorch

A PyTorch implementation of DenseNet.
Python
823
star
3

cv

TeX
398
star
4

latex-templates

Website for personal collection and previewing of LaTeX templates. Presented with Python/Jinja2.
TeX
366
star
5

thesis

Differentiable Optimization-Based Modeling for Machine Learning
TeX
318
star
6

dotfiles

♥ Linux, xmonad, emacs, vim, zsh, tmux
Shell
238
star
7

zsh-history-analysis

Plot your .zsh_history.
Python
224
star
8

python-scripts

Short and fun Python scripts.
Python
197
star
9

reading-list

My reading list.
CSS
185
star
10

presentations

TeX
141
star
11

beamer-snippets

Website for personal collection and previewing of Beamer and TikZ snippets. Presented with Python/Jinja2.
TeX
109
star
12

setGPU

Small Python library to automatically set CUDA_VISIBLE_DEVICES to the least loaded device on multi-GPU systems.
Python
106
star
13

parsec-benchmark

An unofficial mirror of the core PARSEC 3.0 benchmark suite with patches to run on x86_64 Arch Linux and generalize builds.
C
97
star
14

conference-tracker

Minimal-maintenance conference tracker.
Python
71
star
15

girl

Check your GitHub READMEs for broken links.
Scala
70
star
16

bamos.github.io

JavaScript
36
star
17

snowglobe

Haskell-driven, small-scale web analytics with minimal configuration.
Haskell
27
star
18

ecos.torch

Unofficial Torch ECOS bindings to solve linear programs (LPs) and second-order cone programs (SOCPs).
C
16
star
19

gurobi.torch

Unofficial Gurobi Torch bindings.
Lua
9
star
20

shell-scripts

Miscellaneous short shell scripts.
Shell
9
star
21

github-wiki-link-validator

Ensure all links in a Github Wiki point to valid locations within the Wiki.
Python
5
star
22

docker-llvm-polly-pocl

Build LLVM, Polly, and PoCL in an Ubuntu 12.04 Docker container.
Shell
4
star