Package: bandmat
This package provides a simple banded matrix library for python.
It supports banded matrix-vector and matrix-matrix multiplication, converting
between full and banded matrix representations, and certain linear algebra
operations on banded matrices.
It builds on the excellent numpy and scipy packages, which have limited support
for banded matrix operations.OverviewA banded matrix is a matrix where only the diagonal, a number of superdiagonals
and a number of subdiagonals are non-zero.
The well-known BLAS interface and LAPACK library for linear algebra define
several banded matrix operations, and some of these, such as banded Cholesky
decomposition, are wrapped in the excellent python package scipy, specifically
in scipy.linalg.
The bandmat package re-uses the banded matrix representation used by BLAS,
LAPACK and scipy.linalg, wrapping it in a lightweight class for ease of use.
See the docstring for the BandMat class for full details of the representation
used.The bandmat package provides:a lightweight class wrapping the LAPACK-style banded matrix representation.
This class keeps track of things like bandwidths to allow a more direct
coding style when working with banded matrices.some basic banded matrix operations not present in scipy.
For example, banded matrix-vector multiplication is defined by BLAS but not
wrapped by scipy, and banded matrix-matrix multiplication is not defined in
BLAS or in scipy.
The bandmat package contains C implementations of these operations written in
cython.helper functions for converting between full and banded matrix
representations.certain linear algebra operations on banded matrices, including computing the
band of the inverse of a banded matrix.Only square banded matrices are supported by this package.LicensePlease see the fileLicensefor details of the license and warranty for
bandmat.InstallationFor most purposes the simplest way to install bandmat is to use pip.
For example in Debian and Ubuntu:# (for python3, use "python3-numpy python3-scipy" instead)
sudo apt-get install python-numpy python-scipy
sudo pip install bandmatThe first command installs numpy and scipy from the system repository, since
installing numpy and scipy using pip is generally not recommended.
The second command installs the latest released version ofbandmat on PyPI, together with any
currently uninstalled python packages required by bandmat.bandmat can also be installed in a virtualenv:# (for python3, use "python3-numpy python3-scipy" instead)
sudo apt-get install python-numpy python-scipy
virtualenv --system-site-packages env
env/bin/pip install bandmatThe latest development version of bandmat is available from a github repository
(see below).To check that bandmat is installed correctly you can run the test suite:python -m unittest discover bandmatExamplesSee the package docstring (runimport bandmat as bm; help(bm)in the python
interpreter) for some examples of usage.
The python scriptexample.pyalso contains some simple examples of usage.
To run it:python example.pyDevelopmentThe source code is hosted in thebandmat github repository.
To obtain the latest source code using git:git clone git://github.com/MattShannon/bandmat.gitDevelopment is in fact done usingdarcs, with the darcs
repository converted to a git repository usingdarcs-to-git.To install any currently uninstalled python packages required by bandmat:# (for python3, use "cython3 python3-numpy python3-scipy" instead)
sudo apt-get install cython python-numpy python-scipy
sudo pip install -r requirements.txtTo compile the cython part of bandmat in the current directory:python setup.py build_ext --inplaceThis command must be run after every modification to the source.pyxfiles.A note onsetup.pyThe includedsetup.pyfile operates in one of two modes depending on
whether or not the filedevis present in the project root directory.
In development mode (devpresent, as for the github repository), thebuild_extcommand uses cython to compile cython modules from their.pyxsource, and thesdistcommand is modified to first use cython to compile
cython modules from their.pyxsource to.cfiles.
In distribution mode (devabsent, as for source distributions such as the
code on PyPI), thebuild_extcommand uses a C compiler to directly compile
cython modules from the corresponding.cfiles.
This approach ensures that source distributions can be installed on systems
without cython or with an incompatible version of cython, while ensuring that
distributed.cfiles are always up-to-date and that the source.pyxfiles are used instead of.cfiles during development.The author would welcome any suggestions for more elegant ways to achieve a
similar effect to the approach described above!BugsPlease use theissue trackerto submit bug
reports.ContactThe author of bandmat isMatt Shannon.