{"id":14989232,"url":"https://github.com/flatironinstitute/sparse_dot","last_synced_at":"2025-04-04T13:04:46.339Z","repository":{"id":45128285,"uuid":"226734021","full_name":"flatironinstitute/sparse_dot","owner":"flatironinstitute","description":"Python wrapper for Intel Math Kernel Library (MKL) matrix multiplication","archived":false,"fork":false,"pushed_at":"2025-03-15T15:43:57.000Z","size":314,"stargazers_count":82,"open_issues_count":2,"forks_count":11,"subscribers_count":6,"default_branch":"release","last_synced_at":"2025-03-28T12:01:40.865Z","etag":null,"topics":["matrix-multiplication","mkl","numpy","python","scipy","sparse","sparse-matrix"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flatironinstitute.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-12-08T21:24:45.000Z","updated_at":"2025-03-26T21:48:30.000Z","dependencies_parsed_at":"2023-10-11T22:40:54.425Z","dependency_job_id":"0cf0f370-bb3a-4751-84eb-bea8a4b0883b","html_url":"https://github.com/flatironinstitute/sparse_dot","commit_stats":{"total_commits":192,"total_committers":4,"mean_commits":48.0,"dds":0.02083333333333337,"last_synced_commit":"5d60893fe01555b1c1bf29ba205b2319284a316d"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flatironinstitute%2Fsparse_dot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flatironinstitute%2Fsparse_dot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flatironinstitute%2Fsparse_dot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flatironinstitute%2Fsparse_dot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flatironinstitute","download_url":"https://codeload.github.com/flatironinstitute/sparse_dot/tar.gz/refs/heads/release","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247174423,"owners_count":20896078,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["matrix-multiplication","mkl","numpy","python","scipy","sparse","sparse-matrix"],"created_at":"2024-09-24T14:17:54.503Z","updated_at":"2025-04-04T13:04:46.308Z","avatar_url":"https://github.com/flatironinstitute.png","language":"Python","readme":"# sparse_dot_mkl\n[![Build Status](https://github.com/flatironinstitute/sparse_dot/actions/workflows/python-package.yml/badge.svg)](https://github.com/flatironinstitute/sparse_dot/actions/workflows/python-package.yml/)\n[![codecov](https://codecov.io/gh/flatironinstitute/sparse_dot/branch/release/graph/badge.svg)](https://codecov.io/gh/flatironinstitute/sparse_dot)\n[![PyPI version](https://badge.fury.io/py/sparse-dot-mkl.svg)](https://badge.fury.io/py/sparse-dot-mkl)\n[![Conda version](https://anaconda.org/conda-forge/sparse_dot_mkl/badges/version.svg)](https://anaconda.org/conda-forge/sparse_dot_mkl)\n\nThis is a wrapper for the sparse matrix multiplication in the intel MKL library.\nIt is implemented entirely in native python using `ctypes`.\nThe main advantage to MKL (which motivated this) is multithreaded sparse matrix multiplication. \nThe scipy sparse implementation is single-threaded at the time of writing (2020-01-03).\nA secondary advantage is the direct multiplication of a sparse and a dense matrix without requiring any\nintermediate conversion (also multithreaded). \n\nThree python functions are explicitly available (`dot_product_mkl`, `gram_matrix_mkl`, and `sparse_qr_solve_mkl`),\nand several wrapped MKL functions (e.g. `mkl_get_version_string`, `pardiso`) are accessible:\n\n#### dot_product_mkl\n\n`dot_product_mkl(matrix_a, matrix_b, cast=False, copy=True, reorder_output=False, dense=False, debug=False, out=None, out_scalar=None)`\n\n`matrix_a` and `matrix_b` are either numpy arrays (1d or 2d) or scipy sparse matrices (CSR, CSC, or BSR).\nBSR matrices are supported for matrix-matrix multiplication only if one matrix is a dense array or both sparse matrices are BSR.\nSparse COO matrices are not supported. \nNumpy arrays must be contiguous. \nNon-contiguous arrays should be copied to a contiguous array prior to calling this \nfunction.\n\nThis package only works with float or complex float data.\n`cast=True` will convert data to double-precision floats or complex floats by making an internal copy if necessary.\nIf A and B are both single-precision floats or complex floats they will be used as is.\n`cast=False` will raise a ValueError if the input arrays are not both double-precision or both single-precision.\nThis defaults to `False` on the principle that potentially unsafe dtype conversions should not occur without explicit\ninstruction.\n\nThe output will be a dense array, unless both inputs are sparse, in which case the output will be a sparse matrix.\nThe sparse matrix output format will be the same as the left (A) input sparse matrix.\n`dense=True` will directly produce a dense array during sparse matrix multiplication. \n`dense` has no effect if a dense array would be produced anyway. \nDense array outputs may be row-ordered or column-ordered, depending on input ordering.\n\n`copy` is deprecated and has no effect.\n\n`reorder_output=True` will order sparse matrix indices in the output matrix. \nIt has no effect if the output is a dense array.\nInput sparse matrices may be reordered without warning in place. \nThis will not change data, only the way it is stored.\nScipy matrix multiplication does not produce ordered outputs, so this defaults to `False`.\n\n`out` is an optional reference to a dense output array to which the product of the matrix multiplication will be added. \nThis must be identical in attributes to the array that would be returned if it was not used.\nSpecifically it must have the correct shape, dtype, and column- or row-major order and it must be contiguous. \nA ValueError will be raised if any attribute of this array is incorrect.\nThis function will return a reference to the same array object when `out` is set.\n\n`out_scalar` is an optional element-wise scaling of `out`, if `out` is provided.\nIt will multiply `out` prior to adding the matrix multiplication such that \n`out := matrix_a * matrix_b + out_scalar * out`\n\n#### sparse_qr_solve_mkl\n\n`sparse_qr_solve_mkl(matrix_a, matrix_b, cast=False, debug=False)`\n\nThis is a QR solver for systems of linear equations (AX = B) where `matrix_a` is a sparse CSR matrix \nand `matrix_b` is a dense matrix.\nIt will return a dense array X.\n\n`cast=True` will convert data to compatible floats by making an internal copy if necessary.\nIt will also convert a CSC matrix to a CSR matrix if necessary.\n\n#### gram_matrix_mkl\n\n`gram_matrix_mkl(matrix, transpose=False, cast=False, dense=False, debug=False, reorder_output=False)`\n\nThis will calculate the gram matrix A\u003csup\u003eT\u003c/sup\u003eA for matrix A, where matrix A is dense or a sparse CSR matrix.\nIt will return the upper triangular portion of the resulting symmetric matrix.\nIf A is sparse, it will return a sparse matrix unless `dense=True` is set.\n\n`transpose=True` will instead return AA\u003csup\u003eT\u003c/sup\u003e \n\n`reorder_output=True` will order sparse matrix indices in the output matrix. \n\n`cast=True` will convert data to compatible floats by making an internal copy if necessary.\nIt will also convert a CSC matrix to a CSR matrix if necessary.\n\n#### PARDISO\n\n`pardisoinit(mtype, pt=None, iparm=None, single_precision=None, zero_indexing=True)`\n\n`pardiso(A, B, pt, mtype, iparm, phase=13, maxfct=1, mnum=1, perm=None, msglvl=0, X=None, quiet=False)`\n\nWrapper for MKL pardiso solver and the pardisoinit function which initializes `pt` and `iparm`.\nThis is a direct solver for real or complex systems of linear equations (AX = B) where `A`\nis a sparse CSR matrix and `B` is a dense matrix with one or more right-hand sides.\nIt will return a dense array X.\n\nRefer to the pardiso documentation for detailed description of options.\nConsider this wrapper to be experimental.\n\n#### SciPy Classes\n\n`csr_array`, `csr_matrix`, `csc_array`, `csc_matrix`, `bsr_array`, `bsr_matrix`\n\nScipy sparse classes where `__matmul__` and `__rmatmul__` have been replaced to use MKL\nfor matrix math\n\n#### Service Functions\n\nSeveral service functions are available and can be imported from the base `sparse_dot_mkl` package.\n\n`mkl_get_max_threads()` returns the maximum number of threads used by MKL as an integer\n\n`mkl_set_num_threads(n_threads)` will set a maximum number of threads hint for MKL \n\n`mkl_set_num_threads_local(n_threads)` will set a maximum thread hint for the current MKL thread only\n\n`mkl_get_version()` returns a tuple of MKL version information\n(MajorVersion, MinorVersion, UpdateVersion, ProductStatus, Build, Processor, Platform)\n\n`mkl_get_version_string()` returns a descriptive string of the current MKL version\n\n`mkl_interface_integer_dtype()` returns the numpy dtype for sparse matrix index arrays\n\n#### Requirements\n\nThis package requires the MKL runtime linking library `libmkl_rt.so` \n(or `libmkl_rt.dylib` for OSX, or `mkl_rt.dll` for WIN).\nIf the MKL library cannot be loaded an `ImportError` will be raised when the package is first imported. \nMKL is distributed with the full version of conda,\nand can be installed into Miniconda with `conda install -c intel mkl`.\nAlternatively, you may add need to add the path to MKL shared objects to `LD_LIBRARY_PATH`\n(e.g. `export LD_LIBRARY_PATH=/opt/intel/mkl/lib/intel64:$LD_LIBRARY_PATH`).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflatironinstitute%2Fsparse_dot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflatironinstitute%2Fsparse_dot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflatironinstitute%2Fsparse_dot/lists"}