Skip to main content

PyRSB: a Cython-based Python interface to librsb

Project description

PyRSB

GPL enforced badge Build Status

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 as scipy.sparse.csr_matrix().
  • Conversion from scipy.sparse.csr_matrix().
  • Multiplication by vector/multivector.
  • Rows/columns through nr=a.shape()[0]/nr=a.shape()[1], or nr()/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: make shall 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-dev shall suffice. Other operating systems have librsb, too. Please check yours. Or check librsb's web site.
  • If you want the Makefile to build librsb (in this directory): make all-local will 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 (or make lp) will build pyrsb using local librsb, then run it.
  • make test will test benchmark code using test.py (to compare speed to SciPy)
  • make b will also produce graphs (requires gnuplot)

Example Usage

# Example: demo1.py
"""
pyrsb demo
"""

import numpy
import scipy
from scipy.sparse import csr_matrix
from pyrsb import *

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 pyrsb import *

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyrsb-0.2.20210301.tar.gz (16.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyrsb-0.2.20210301-cp39-cp39-manylinux2010_x86_64.whl (3.7 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.12+ x86-64

pyrsb-0.2.20210301-cp38-cp38-manylinux2010_x86_64.whl (3.8 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.12+ x86-64

pyrsb-0.2.20210301-cp37-cp37m-manylinux2010_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.12+ x86-64

pyrsb-0.2.20210301-cp36-cp36m-manylinux2010_x86_64.whl (3.6 MB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.12+ x86-64

File details

Details for the file pyrsb-0.2.20210301.tar.gz.

File metadata

  • Download URL: pyrsb-0.2.20210301.tar.gz
  • Upload date:
  • Size: 16.1 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

Hashes for pyrsb-0.2.20210301.tar.gz
Algorithm Hash digest
SHA256 e80582943f0c70f87a4e0882dbabdabbeea0dda1afa1aea3272ee19ce68e0273
MD5 2a47d855a041327b47686c3a45ceae05
BLAKE2b-256 62248401b5e5b77c1b42426fd9244fbeb12f8aaed5bbb8e71e413ea4387e77b7

See more details on using hashes here.

File details

Details for the file pyrsb-0.2.20210301-cp39-cp39-manylinux2010_x86_64.whl.

File metadata

  • Download URL: pyrsb-0.2.20210301-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

Hashes for pyrsb-0.2.20210301-cp39-cp39-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 ad5905618fc9980350b9e962cb3a118fef16ea8d141958d658a4e0d422911e6d
MD5 d41f718f4d76bc4e0abba19f0edf786e
BLAKE2b-256 9b9fbdd736fdbbb7c827c6e96da26fe93191b9951b9c446a111db3a5cbc62b9c

See more details on using hashes here.

File details

Details for the file pyrsb-0.2.20210301-cp38-cp38-manylinux2010_x86_64.whl.

File metadata

  • Download URL: pyrsb-0.2.20210301-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

Hashes for pyrsb-0.2.20210301-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 8f215992bcf0e350fd7f10786a596196e902352f94d0298f57900ff9a16aef1b
MD5 afe6817525551f92f44c59118adf884c
BLAKE2b-256 37001c72b89369ef6cf40b68cde3948e77f7d242df87097fbdd9f7652cfc56a2

See more details on using hashes here.

File details

Details for the file pyrsb-0.2.20210301-cp37-cp37m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: pyrsb-0.2.20210301-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

Hashes for pyrsb-0.2.20210301-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 6ef17b53e495d77ac8e0759c7b502738dc18d339a77356bf36c44b9024c779bc
MD5 30b5b41ead1faa53bfe32028170e63be
BLAKE2b-256 09218e80b121cf7c9ce6a18c4cfa09d3e1b2d52081336610c59be6fdaed7fcd3

See more details on using hashes here.

File details

Details for the file pyrsb-0.2.20210301-cp36-cp36m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: pyrsb-0.2.20210301-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

Hashes for pyrsb-0.2.20210301-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 a0261d95b38f1fc8da80380b3d47b4f4531dec4d568e245c2cffec843f2a6cfc
MD5 881953853ea5fef5e2978617bda05c30
BLAKE2b-256 5dd2fb96b4fa8aec74ab1a57bf7ce4b7df039070c6bae16e1e1582bec0ad40b5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page