Skip to main content

SPArse Modeling Software (SPAMS) Cython interface

Project description

spams-cython

This package exposes convenient interfaces of some functions of the SPArse Modeling Software (SPAMS) C++ library, allowing them to be used from Cython code by releasing the Python Global Interpreter Lock (GIL)

Installation from PyPI

pip install spams-cython

Installation from source

git clone https://github.com/getspams/spams-cython.git
cd spams-cython
pip install .

Use spams-cython into your project

pyproject.toml

[build-system]
requires = [
    "setuptools",
    "Cython",
    "spams-cython"
]

setup.py

from setuptools import setup, Extension
from Cython.Build import cythonize
import cyspams

extensions = [
    Extension(
        mymodule,
        sources['mymodule.pyx'],
        include_dirs=cyspams.get_include()
    )
]

setup(ext_modules=cythonize(extensions))

mymodule.pyx

from cyspams.interfaces cimport nnls, lasso

Note

To build your project with spams-cython you need to have a BLAS/LAPACK library on your system (e.g. OpenBLAS, Intel MKL)

Exposed functions

nnls

void nnls(const double *A, const double *y, const int m, const int n, double *x, double &rnorm)

Args in:
A → Matrix 'A = (m, n)' stored as 1D contiguous array (column-major order)
y → Vector 'y = (m)'
m → Dimension 'm'
n → Dimension 'n'

Args out:
x → Solution vector 'x = (n)'
rnorm → Squared Euclidean norm of the final residual vector


lasso

void lasso(double *A, double *y, const int m, const int p, const int n, double *x)
void lasso(double *A, double *y, const int m, const int p, const int n, double *x, const double lambda1, const double lambda2)
void lasso(double *A, double *y, const int m, const int p, const int n, double *x, const double lambda1, const double lambda2, const int mode, const bint pos)
void lasso(double *A, double *y, const int m, const int p, const int n, double *x, const double lambda1, const double lambda2, const int mode, const bint pos, const bint ols, const int max_length_path, const int L, const bint cholesky, const int n_threads, const bint verbose)

Args in:
A → Matrix 'A = (m, p)' stored as 1D contiguous array (column-major order)
y → Matrix 'y = (m, n)' stored as 1D contiguous array (column-major order)
m → Dimension 'm'
p → Dimension 'p'
n → Dimension 'n'
lambda1 → Regularization parameter (default = 0.0)
lambda2 → Parameter for solving the Elastic-Net (default = 0.0)
mode → 0 = L1COEFFS, 1 = L2ERROR, 2 = PENALTY, 3 = SPARSITY, 4 = L2ERROR2, 5 = PENALTY2, 6 = FISTAMODE (default = 2)
pos → Adds non-negativity constraints on the coefficients (default = true)
ols → Perform an orthogonal projection before returning the solution (default = false)
max_length_path → Maximum length of the path (default = -1)
L → Maximum number of steps of the homotopy algorithm. Can be used as a stopping criterion (default = -1)
cholesky → Choose between Cholesky implementation or one based on the matrix inversion Lemma (default = false)
n_threads → Number of threads to use (default = 1)
verbose → Verbose mode (default = false)

Args out:
x → Solution matrix 'x = (p, n)' stored as 1D contiguous array (column-major order)


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

spams-cython-1.0.0.tar.gz (148.7 kB view details)

Uploaded Source

Built Distribution

spams_cython-1.0.0-py3-none-any.whl (157.1 kB view details)

Uploaded Python 3

File details

Details for the file spams-cython-1.0.0.tar.gz.

File metadata

  • Download URL: spams-cython-1.0.0.tar.gz
  • Upload date:
  • Size: 148.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.9

File hashes

Hashes for spams-cython-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c7a1e32bde4e0a7d6fd61fc3922f7349d66a44b5cf2a8ab6ec14167150daa0ad
MD5 3132aa74c1610e6bf35f27e8c5a4eac4
BLAKE2b-256 9eaf411eeb198acf294a977436dee8cf546e071146719b212be665618a209c92

See more details on using hashes here.

File details

Details for the file spams_cython-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for spams_cython-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b77446cf42556613a847197d5d4cb0d2ee4c44eb99ce209cc19a421e1e776be6
MD5 d0573a48e2b1ce157cd1028e883a60c8
BLAKE2b-256 6f3ea1a9eb08de9ca17a96f5edb2c22225872f7a4cf644c4b95a7a0fe99c9f10

See more details on using hashes here.

Supported by

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