https://github.com/flatironinstitute/sparse_dot

Python wrapper for Intel Math Kernel Library (MKL) matrix multiplication

https://github.com/flatironinstitute/sparse_dot

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.7%) to scientific vocabulary

Keywords

matrix-multiplication mkl numpy python scipy sparse sparse-matrix
Last synced: 5 months ago · JSON representation

Repository

Python wrapper for Intel Math Kernel Library (MKL) matrix multiplication

Basic Info
  • Host: GitHub
  • Owner: flatironinstitute
  • License: mit
  • Language: Python
  • Default Branch: release
  • Homepage:
  • Size: 326 KB
Statistics
  • Stars: 89
  • Watchers: 5
  • Forks: 11
  • Open Issues: 3
  • Releases: 19
Topics
matrix-multiplication mkl numpy python scipy sparse sparse-matrix
Created about 6 years ago · Last pushed 7 months ago
Metadata Files
Readme Changelog License

README.md

sparsedotmkl

Build Status codecov PyPI version Conda version

This is a wrapper for the sparse matrix multiplication in the intel MKL library. It is implemented entirely in native python using ctypes. The main advantage to MKL (which motivated this) is multithreaded sparse matrix multiplication. The scipy sparse implementation is single-threaded at the time of writing (2020-01-03). A secondary advantage is the direct multiplication of a sparse and a dense matrix without requiring any intermediate conversion (also multithreaded).

Three python functions are explicitly available (dot_product_mkl, gram_matrix_mkl, and sparse_qr_solve_mkl), and several wrapped MKL functions (e.g. mkl_get_version_string, pardiso) are accessible:

dotproductmkl

dot_product_mkl(matrix_a, matrix_b, cast=False, copy=True, reorder_output=False, dense=False, debug=False, out=None, out_scalar=None)

matrix_a and matrix_b are either numpy arrays (1d or 2d) or scipy sparse matrices (CSR, CSC, or BSR). BSR matrices are supported for matrix-matrix multiplication only if one matrix is a dense array or both sparse matrices are BSR. Sparse COO matrices are not supported. Numpy arrays must be contiguous. Non-contiguous arrays should be copied to a contiguous array prior to calling this function.

This package only works with float or complex float data. cast=True will convert data to double-precision floats or complex floats by making an internal copy if necessary. If A and B are both single-precision floats or complex floats they will be used as is. cast=False will raise a ValueError if the input arrays are not both double-precision or both single-precision. This defaults to False on the principle that potentially unsafe dtype conversions should not occur without explicit instruction.

The output will be a dense array, unless both inputs are sparse, in which case the output will be a sparse matrix. The sparse matrix output format will be the same as the left (A) input sparse matrix. dense=True will directly produce a dense array during sparse matrix multiplication. dense has no effect if a dense array would be produced anyway. Dense array outputs may be row-ordered or column-ordered, depending on input ordering.

copy is deprecated and has no effect.

reorder_output=True will order sparse matrix indices in the output matrix. It has no effect if the output is a dense array. Input sparse matrices may be reordered without warning in place. This will not change data, only the way it is stored. Scipy matrix multiplication does not produce ordered outputs, so this defaults to False.

out is an optional reference to a dense output array to which the product of the matrix multiplication will be added. This must be identical in attributes to the array that would be returned if it was not used. Specifically it must have the correct shape, dtype, and column- or row-major order and it must be contiguous. A ValueError will be raised if any attribute of this array is incorrect. This function will return a reference to the same array object when out is set.

out_scalar is an optional element-wise scaling of out, if out is provided. It will multiply out prior to adding the matrix multiplication such that out := matrix_a * matrix_b + out_scalar * out

sparseqrsolve_mkl

sparse_qr_solve_mkl(matrix_a, matrix_b, cast=False, debug=False)

This is a QR solver for systems of linear equations (AX = B) where matrix_a is a sparse CSR matrix and matrix_b is a dense matrix. It will return a dense array X.

cast=True will convert data to compatible floats by making an internal copy if necessary. It will also convert a CSC matrix to a CSR matrix if necessary.

grammatrixmkl

gram_matrix_mkl(matrix, transpose=False, cast=False, dense=False, debug=False, reorder_output=False)

This will calculate the gram matrix ATA for matrix A, where matrix A is dense or a sparse CSR matrix. It will return the upper triangular portion of the resulting symmetric matrix. If A is sparse, it will return a sparse matrix unless dense=True is set.

transpose=True will instead return AAT

reorder_output=True will order sparse matrix indices in the output matrix.

cast=True will convert data to compatible floats by making an internal copy if necessary. It will also convert a CSC matrix to a CSR matrix if necessary.

PARDISO

pardisoinit(mtype, pt=None, iparm=None, single_precision=None, zero_indexing=True)

pardiso(A, B, pt, mtype, iparm, phase=13, maxfct=1, mnum=1, perm=None, msglvl=0, X=None, quiet=False)

Wrapper for MKL pardiso solver and the pardisoinit function which initializes pt and iparm. This is a direct solver for real or complex systems of linear equations (AX = B) where A is a sparse CSR matrix and B is a dense matrix with one or more right-hand sides. It will return a dense array X.

Refer to the pardiso documentation for detailed description of options. Consider this wrapper to be experimental.

SciPy Classes

csr_array, csr_matrix, csc_array, csc_matrix, bsr_array, bsr_matrix

Scipy sparse classes where __matmul__ and __rmatmul__ have been replaced to use MKL for matrix math

Service Functions

Several service functions are available and can be imported from the base sparse_dot_mkl package.

mkl_get_max_threads() returns the maximum number of threads used by MKL as an integer

mkl_set_num_threads(n_threads) will set a maximum number of threads hint for MKL

mkl_set_num_threads_local(n_threads) will set a maximum thread hint for the current MKL thread only

mkl_get_version() returns a tuple of MKL version information (MajorVersion, MinorVersion, UpdateVersion, ProductStatus, Build, Processor, Platform)

mkl_get_version_string() returns a descriptive string of the current MKL version

mkl_interface_integer_dtype() returns the numpy dtype for sparse matrix index arrays

Requirements

This package requires the MKL runtime linking library libmkl_rt.so (or libmkl_rt.dylib for OSX, or mkl_rt.dll for WIN). If the MKL library cannot be loaded an ImportError will be raised when the package is first imported. MKL is distributed with the full version of conda, and can be installed into Miniconda with conda install -c intel mkl. Alternatively, you may add need to add the path to MKL shared objects to LD_LIBRARY_PATH (e.g. export LD_LIBRARY_PATH=/opt/intel/mkl/lib/intel64:$LD_LIBRARY_PATH).

Owner

  • Name: Flatiron Institute
  • Login: flatironinstitute
  • Kind: organization
  • Location: New York City

@SimonsFoundation

GitHub Events

Total
  • Create event: 4
  • Issues event: 11
  • Release event: 4
  • Watch event: 12
  • Member event: 4
  • Issue comment event: 29
  • Push event: 14
  • Pull request event: 2
  • Fork event: 1
Last Year
  • Create event: 4
  • Issues event: 11
  • Release event: 4
  • Watch event: 12
  • Member event: 4
  • Issue comment event: 29
  • Push event: 14
  • Pull request event: 2
  • Fork event: 1

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 219
  • Total Committers: 5
  • Avg Commits per committer: 43.8
  • Development Distribution Score (DDS): 0.041
Past Year
  • Commits: 29
  • Committers: 2
  • Avg Commits per committer: 14.5
  • Development Distribution Score (DDS): 0.172
Top Committers
Name Email Commits
asistradition a****n 210
Benjamin Desef p****t@y****e 5
Leonid Kostrykin k****n@e****e 2
mynameisvinn v****g@g****m 1
LemonBoy t****n@g****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 7 months ago

All Time
  • Total issues: 27
  • Total pull requests: 7
  • Average time to close issues: 3 months
  • Average time to close pull requests: 10 days
  • Total issue authors: 23
  • Total pull request authors: 4
  • Average comments per issue: 3.93
  • Average comments per pull request: 1.43
  • Merged pull requests: 7
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 9
  • Pull requests: 1
  • Average time to close issues: 16 days
  • Average time to close pull requests: 1 day
  • Issue authors: 8
  • Pull request authors: 1
  • Average comments per issue: 3.0
  • Average comments per pull request: 6.0
  • Merged pull requests: 1
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • kostrykin (2)
  • tbenthompson (2)
  • hrittich (2)
  • simonwm (2)
  • peterwilton-ttam (1)
  • alexbovet (1)
  • bentrainer (1)
  • floatingCatty (1)
  • leycec (1)
  • leebo-2020 (1)
  • DManowitz (1)
  • GitHubOpenIssue (1)
  • projekter (1)
  • DeepakSaini119 (1)
  • gnool (1)
Pull Request Authors
  • asistradition (4)
  • projekter (2)
  • mynameisvinn (1)
  • LemonBoy (1)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 2
  • Total downloads:
    • pypi 3,240 last-month
  • Total dependent packages: 10
    (may contain duplicates)
  • Total dependent repositories: 2
    (may contain duplicates)
  • Total versions: 59
  • Total maintainers: 2
pypi.org: sparse-dot-mkl

Intel MKL wrapper for sparse matrix multiplication

  • Versions: 39
  • Dependent Packages: 10
  • Dependent Repositories: 2
  • Downloads: 3,240 Last month
Rankings
Dependent packages count: 1.2%
Average: 8.2%
Downloads: 8.3%
Stargazers count: 8.7%
Forks count: 11.4%
Dependent repos count: 11.6%
Maintainers (2)
Last synced: 6 months ago
conda-forge.org: sparse_dot_mkl

This package is a ctypes wrapper for the Math Kernel Library matrix multiplicaton. It will dot product numpy dense arrays and scipy sparse arrays (multithreaded)

  • Versions: 20
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent repos count: 34.0%
Stargazers count: 38.0%
Average: 42.3%
Forks count: 46.0%
Dependent packages count: 51.2%
Last synced: 6 months ago

Dependencies

setup.py pypi
  • numpy *
  • scipy *
.github/workflows/python-package.yml actions
  • actions/checkout v3 composite
  • codecov/codecov-action v3 composite