Skip to main content

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)


Release files for spams-cython 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spams-cython 1.0.0
File Size Uploaded
spams-cython-1.0.0.tar.gz 148.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for spams-cython 1.0.0
File Interpreter ABI Platform
spams_cython-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 305.8 kB

Release files / spams-cython-1.0.0.tar.gz

Download URL spams-cython-1.0.0.tar.gz
Size 148.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c7a1e32bde4e0a7d6fd61fc3922f7349d66a44b5cf2a8ab6ec14167150daa0ad
BLAKE2b-256 checksum
How to use checksums
9eaf411eeb198acf294a977436dee8cf546e071146719b212be665618a209c92
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.9

Release files / spams_cython-1.0.0-py3-none-any.whl

Download URL spams_cython-1.0.0-py3-none-any.whl
Size 157.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b77446cf42556613a847197d5d4cb0d2ee4c44eb99ce209cc19a421e1e776be6
BLAKE2b-256 checksum
How to use checksums
6f3ea1a9eb08de9ca17a96f5edb2c22225872f7a4cf644c4b95a7a0fe99c9f10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.9

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page