Metadata-Version: 2.2
Name: sparse-approx-gsm
Version: 1.0.0
Summary: Sparse Approximation by the Generalized Soft-Min Penalty
Requires-Python: >=3.8
Requires-Dist: numpy>=1.21
Provides-Extra: gpu
Requires-Dist: cupy-cuda12x; extra == "gpu"
Provides-Extra: dev
Requires-Dist: pytest>=7; extra == "dev"
Requires-Dist: scipy; extra == "dev"
Requires-Dist: mpmath; extra == "dev"
Description-Content-Type: text/markdown

# sparse-approx-gsm

Python (+ optional CUDA) implementation of **Sparse Approximation by the Generalized Soft-Min (GSM) Penalty** — a sparse-recovery solver based on the Trimmed Lasso.

> Tal Amir, Ronen Basri, Boaz Nadler — *The Trimmed Lasso: Sparse Recovery Guarantees and Practical Optimization by the Generalized Soft-Min Penalty*. Weizmann Institute of Science.

## Install

**With CUDA extension:**
```bash
NVCC=/path/to/nvcc
PYBIND11_DIR=$(python -c "import pybind11; print(pybind11.get_cmake_dir())")
CMAKE_ARGS="-DCMAKE_CUDA_COMPILER=$NVCC -Dpybind11_DIR=$PYBIND11_DIR -DCMAKE_CXX_COMPILER=/usr/bin/g++" \
  pip install --no-build-isolation . -v
```

**CPU only** (omit CUDA flags):
```bash
pip install --no-build-isolation .
```

`--no-build-isolation` is needed on conda environments to avoid linker conflicts. See `CLAUDE.md` for full details.

## Usage

```python
from gsm_python import sparse_approx_gsm, SparseApproxGSM, gsm

# High-level solver: min ||Ax - y||_2  s.t.  ||x||_0 <= k
x = sparse_approx_gsm(A, y, k, profile='normal')

# GSM function and gradient
mu, theta = gsm(z, k, gamma)
```

## Optional GPU

Install CuPy for the matching CUDA version (e.g. `pip install cupy-cuda12x`), then pass
a CuPy array to `gsm()` or use `SparseApproxGSM(..., use_gpu=True)`.
