PyRSB: a Cython-based Python interface to librsb
Project description
PyRSB
librsb is a high performance sparse matrix library implementing the Recursive Sparse Blocks format, which is especially well suited for multiplications in iterative methods on huge symmetric sparse matrices.
PyRSB is a Cython-based Python interface to librsb.
On multicore machines, PyRSB can be several times faster than e.g. scipy.sparse.csr_matrix().
For an example how to invoke it with no overhead, see the advanced example.
So far, PyRSB is a prototype tested on Linux only. The librsb library offers much more, and can make PyRSB much more powerful. Prospective users and collaborators feedback are sought; please contact me to feedback and help.
Features
The following functionality is implemented:
- Initialization with
rsb.rsb_matrix()styled asscipy.sparse.csr_matrix(). - Conversion from
scipy.sparse.csr_matrix(). - Multiplication by vector/multivector.
- Rows/columns through
nr=a.shape()[0]/nr=a.shape()[1], ornr()/nc(). find(),find_block(),tril(),triu(),shape(),nnz.print'able.- PyRSB-Specific:
autotune(),do_print(). - load from a Matrix Market file, e.g.
rsb.rsb_file_mtx_load(bytes(filename,encoding='utf-8'))
Build and Use
- If you have librsb installed:
makeshall build and test. - Make sure you have
cython,scipy,numpy. installed. - If you want to install librsb on Ubuntu or Debian:
sudo apt-get install librsb-devshall suffice. Other operating systems have librsb, too. Please check yours. Or check librsb's web site. - If you want the
Makefileto build librsb (in this directory):make all-localwill attempt downloading librsb-1.2.0.9 from the web and building it here before building pyrsb. If the file is in place, it won't download it a second time. After that,make local-librsb-pyrsb(ormake lp) will build pyrsb using local librsb, then run it. make testwill test benchmark code usingtest.py(to compare speed to SciPy)make bwill also produce graphs (requiresgnuplot)
Example Usage
# Example: demo1.py
"""
pyrsb demo
"""
import numpy
import scipy
from scipy.sparse import csr_matrix
from rsb import rsb_matrix, rsb_dtype
V = [11.0, 12.0, 22.0]
I = [0, 0, 1]
J = [0, 1, 1]
c = csr_matrix((V, (I, J)))
print(c)
# several constructor forms, as with csr_matrix:
a = rsb_matrix((V, (I, J)))
a = rsb_matrix((V, (I, J)), [3, 3])
a = rsb_matrix((V, (I, J)), sym="S") # symmetric example
print(a)
a = rsb_matrix((4, 4))
a = rsb_matrix(c,dtype=rsb_dtype)
nrhs = 1 # set to nrhs>1 to multiply by multiple vectors at once
nr = a.shape[0]
nc = a.shape[1]
order = "F"
x = numpy.empty([nc, nrhs], dtype=rsb_dtype, order=order)
y = numpy.empty([nr, nrhs], dtype=rsb_dtype, order=order)
x[:, :] = 1.0
y[:, :] = 0.0
print(a)
print(x)
print(y)
# import rsb # import operators
# a.autotune() # makes only sense for large matrices
y = y + a * x
# equivalent to y=y+c*x
print(y)
del a
Example Advanced Usage
# Example: demo2.py
"""
pyrsb demo
"""
import numpy
import scipy
from scipy.sparse import csr_matrix
from rsb import rsb_matrix, rsb_dtype
V = [11.0, 12.0, 22.0]
I = [0, 0, 1]
J = [0, 1, 1]
a = rsb_matrix((V, (I, J)))
nrhs = 4 # set to nrhs>1 to multiply by multiple vectors at once
nr = a.shape[0]
nc = a.shape[1]
# Choose Fortran or "by columns" order here.
order = "F"
x = numpy.empty([nc, nrhs], dtype=rsb_dtype, order=order)
y = numpy.empty([nr, nrhs], dtype=rsb_dtype, order=order)
x[:, :] = 1.0
y[:, :] = 0.0
print(a)
print(x)
print(y)
# Autotuning example: use it if you need many multiplication iterations on huge matrices (>>1e6 nonzeroes).
# Here general (nrhs=1) case:
a.autotune()
# Here with all the autotuning parameters specified:
a.autotune(1.0,0,1,2.0,ord('N'),1.0,nrhs,ord('F'),1.0,False)
# Inefficient: reallocate y
y = y + a * x
# Inefficient: reallocate y
y += a * x
# Equivalent but more efficient: don't reallocate y
a._spmm(x,y)
print(y)
del a
License
GPLv3+
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyrsb-0.2.20210226.tar.gz.
File metadata
- Download URL: pyrsb-0.2.20210226.tar.gz
- Upload date:
- Size: 200.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2bb9053ff3b69ac8e251115abe0587a4852b4ed6e0203eac74083a2d8c12318b
|
|
| MD5 |
2b797ec55822e1159dbd1149b901463c
|
|
| BLAKE2b-256 |
3f4d07b0c3422ed7a3d23525bcbd66323cbb7ccc1c3b386709c6f6f2d19b0986
|
File details
Details for the file pyrsb-0.2.20210226-cp39-cp39-manylinux2010_x86_64.whl.
File metadata
- Download URL: pyrsb-0.2.20210226-cp39-cp39-manylinux2010_x86_64.whl
- Upload date:
- Size: 3.7 MB
- Tags: CPython 3.9, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d114b1df3f5424455aeec17149dbb81d5c78f8c7ce63963ef32445a8d2fb34a
|
|
| MD5 |
8047195c539f3a8b421b2ad0ac6cfa44
|
|
| BLAKE2b-256 |
cc4eec38979cebc8f94dd8db3133113ddcdc9e345414e389339347719fc72b8e
|
File details
Details for the file pyrsb-0.2.20210226-cp38-cp38-manylinux2010_x86_64.whl.
File metadata
- Download URL: pyrsb-0.2.20210226-cp38-cp38-manylinux2010_x86_64.whl
- Upload date:
- Size: 3.8 MB
- Tags: CPython 3.8, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd46b9506ab0ffa87852696b1711d28e7264bf77a0fdd22fdbaf4601d5c1c5b3
|
|
| MD5 |
b8be2a979fe4a1ff0888eb0c5c289187
|
|
| BLAKE2b-256 |
99562abad30385fa6e2ddcaf963d6e22e54d864d64e6ef19d36049ff1be0b4a0
|
File details
Details for the file pyrsb-0.2.20210226-cp37-cp37m-manylinux2010_x86_64.whl.
File metadata
- Download URL: pyrsb-0.2.20210226-cp37-cp37m-manylinux2010_x86_64.whl
- Upload date:
- Size: 3.6 MB
- Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f54464a4df4d56f4fbbd6a5fd9e9a28bc6ed016de66875c4b1586307da47832b
|
|
| MD5 |
057eb8ba120dcf64bd150b417a00f5bb
|
|
| BLAKE2b-256 |
20f3455164ce3923b678824056a7b0a6f4cecacf5da4d3ce76a083b0245b0eb8
|
File details
Details for the file pyrsb-0.2.20210226-cp36-cp36m-manylinux2010_x86_64.whl.
File metadata
- Download URL: pyrsb-0.2.20210226-cp36-cp36m-manylinux2010_x86_64.whl
- Upload date:
- Size: 3.6 MB
- Tags: CPython 3.6m, manylinux: glibc 2.12+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08c69724883d631e87fad4bfa1fc19d9c1348f9a822b4700b574f7d64da1552b
|
|
| MD5 |
84651990e9b5a592b1e255705415974e
|
|
| BLAKE2b-256 |
d5f736de04174ab300e736c89fc6ef8b3f75eca8b2461ff6941e839d1e7a2151
|