Skip to main content

pygensvd.py

An updated version of the original pygsvd package by Benjamin Naecker. This version uses cmake for compilation rather than distutils, but only supports openblas as a backend (for now).

A Python wrapper to the LAPACK generalized singular value decomposition.

(C) 2017 Benjamin Naecker bnaecker@fastmail.com

Overview

The pygsvd module exports a single function gsvd, which computes the generalized singular value decomposition (GSVD) of a pair of matrices, A and B. The GSVD is a joint decomposition useful for computing regularized solutions to ill-posed least-squares problems, as well as dimensionality reduction and clustering.

The pygsvd module is very simple: it just wraps the underlying LAPACK routine ggsvd3, both the double-precision (dggsvd3) and complex-double precision versions (zggsvd3).

Building

Because the pygsvd module wraps a LAPACK routine itself, it is provided as a Python and NumPy extension module. The module must be compiled, and doing so requires a LAPACK header and a shared library. The module currently supports both the standard C bindings to LAPACK (called LAPACKE), and those provided by Intel's Math Kernel Library. Notably it does not support Apple's Accelerate framework, which seems to be outdated and differs in several subtle and annoying ways.

You can build against either of the supported implementations, by editing the setup.cfg file. Set the define= line in the file to be one of USE_LAPACK (the default) or USE_MKL.

You must also add the include and library directories for these. The build process already searches /usr/local/{include,lib}, but if these don't contain the header and library, add the directory containing these to the include_dirs= and library_dirs= line. Multiple directories are separated by a :. You can also set these on the command line when building.

For example, to use the LAPACK library, with a header in /some/dir/ and the library in /some/libdir/, you could run:

$ python3 setup.py build_ext --include-dirs="/some/dir" --library-dirs="/some/libdir"

Then you can install the module either as usual or in develop mode as:

$ python3 setup.py {install,develop}

Or via pip as:

$ pip3 install .

Usage

The GSVD of a pair of NumPy ndarrays a and b can be computed as:

>>> c, s, x = pygsvd.gsvd(a, b)

This returns the generalized singular values, in arrays c and s, and the right generalized singular vectors in x. Optionally, the transformation matrices u and v` may also be computed. E.g.:

>>> c, s, x, u = pygsvd.gsvd(a, b, extras='u')

also returns the left generalized singular vectors of a.

By default, the matrices u and v, if returned, are of shape (m, n) and (p, n). Using the optional argument full_matrices is set to True, then the matrices are square, of shape (m, m) and (p, p).

The generalized singular value decomposition

The GSVD is a joint decomposition of a pair of matrices. Given matrices A with shape (m, n) and B with shape (p, n), it computes:

    A = U*C*X.T
    B = V*S*X.T

where U and V are unitary matrices, with shapes (m, m) and (p, p), and X is shaped as (n, n), respectively. C and S are diagonal (possibly non-square) matrices containing the generalized singular value pairs.

This decomposition has many uses, including least-squares fitting of ill-posed problems. For example, letting B be the "second derivative" operator one can solve the equation

min_x ||Ax - b||^2 + \lambda ||Bx||^2

using the GSVD, which achieves a smoother solution as \lambda is increased. Similarly, setting B to the identity matrix, this becomes the standard ridge regression problem. These are both versions of the Tichonov regularization problem, for which the GSVD provides a useful and efficient solution.

Metadata

Release files for pygensvd 0.1.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 pygensvd 0.1.0
File Size Uploaded
pygensvd-0.1.0.tar.gz 10.7 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for pygensvd 0.1.0
File
pygensvd-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details
pygensvd-0.1.0-cp311-cp311-macosx_10_9_x86_64.whl CPython 3.11 CPython 3.11 macOS 10.9+ x86-64 Details
pygensvd-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details
pygensvd-0.1.0-cp310-cp310-macosx_10_9_x86_64.whl CPython 3.10 CPython 3.10 macOS 10.9+ x86-64 Details
pygensvd-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.17+ x86-64 Details
pygensvd-0.1.0-cp39-cp39-macosx_10_9_x86_64.whl CPython 3.9 CPython 3.9 macOS 10.9+ x86-64 Details
pygensvd-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.17+ x86-64 Details
pygensvd-0.1.0-cp38-cp38-macosx_10_9_x86_64.whl CPython 3.8 CPython 3.8 macOS 10.9+ x86-64 Details
pygensvd-0.1.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-64 Details
pygensvd-0.1.0-cp37-cp37m-macosx_10_9_x86_64.whl CPython 3.7 CPython 3.7 pymalloc macOS 10.9+ x86-64 Details

Total release size: 113.0 MB

Release files / pygensvd-0.1.0.tar.gz

Download URL pygensvd-0.1.0.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c6857fa0522e1899673729c250eddb987f14cbd515ab33e958e98d81feb6016c
BLAKE2b-256 checksum
How to use checksums
97147fb79dc6a86fb0b2f061beeac84eae9316c196cbce75941df876f91c2c4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.17

Release files / pygensvd-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pygensvd-0.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 11.0 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
1e31c359bd0615e1e9de551225d3d5c81289cba51a2932c1121c51b4ccefc61e
BLAKE2b-256 checksum
How to use checksums
629c2335e2805e4e5b08df278a1d6479dc05fbd962b5dff9ca04897e233b91e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.17

Release files / pygensvd-0.1.0-cp311-cp311-macosx_10_9_x86_64.whl

Download URL pygensvd-0.1.0-cp311-cp311-macosx_10_9_x86_64.whl
Size 11.6 MB
Tags CPython 3.11 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
6464e660ef9d814e2af5fad959ab909134caab15342e8de55357af64c82b598c
BLAKE2b-256 checksum
How to use checksums
f03de7ab23b03df862d7f0575444a39eb379e44712da932635a8b1a3c703ce87
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.17

Release files / pygensvd-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pygensvd-0.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 11.0 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
1c5c56e725cd089277a687f9bb741b0cfefc07f28bffce6f4779795fb95852e5
BLAKE2b-256 checksum
How to use checksums
78ee2d85d6a20620dc20a0aababe1e530ebac41e24e6e05e428dc5c57803efa4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.17

Release files / pygensvd-0.1.0-cp310-cp310-macosx_10_9_x86_64.whl

Download URL pygensvd-0.1.0-cp310-cp310-macosx_10_9_x86_64.whl
Size 11.6 MB
Tags CPython 3.10 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
7c9c4e145e8a09202279660d1885246fac58f181750ac47a0d1de7937c1ace05
BLAKE2b-256 checksum
How to use checksums
64b1af2ba7e1963900fffe1424f55c54f6752d9a453eb0a450049095e381c571
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.17

Release files / pygensvd-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pygensvd-0.1.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 11.0 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
2bded7671052f2428dae559d440d7156dab46e93762e66ed4832b11efe4f425b
BLAKE2b-256 checksum
How to use checksums
1b78617fb2f730ed51c828c38b522d94bf4d6ccee9bfa317e850ca35452737cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.17

Release files / pygensvd-0.1.0-cp39-cp39-macosx_10_9_x86_64.whl

Download URL pygensvd-0.1.0-cp39-cp39-macosx_10_9_x86_64.whl
Size 11.6 MB
Tags CPython 3.9 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
642765da943df098df101de8aced46a4b9a9c476dc1d3e2df4a917c117931b3a
BLAKE2b-256 checksum
How to use checksums
be9b23b32e27994dd684852306adc346586bb0ba423b9effaa9acb78c63dd587
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.17

Release files / pygensvd-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pygensvd-0.1.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 11.0 MB
Tags CPython 3.8 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
78885cbeab4568ff8b85383a135ec9f37087edf39ae763194cac4e694f172ee4
BLAKE2b-256 checksum
How to use checksums
b01ad5f81f011ebe23656419451dc5a6acbd702340a6247340b3dc4aaade56e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.17

Release files / pygensvd-0.1.0-cp38-cp38-macosx_10_9_x86_64.whl

Download URL pygensvd-0.1.0-cp38-cp38-macosx_10_9_x86_64.whl
Size 11.6 MB
Tags CPython 3.8 macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
a6a40781ebd6fafef50fcb5ead725ed1bd95132b5eebc2d3b1f34a010b378979
BLAKE2b-256 checksum
How to use checksums
44982e7692d06e3e1522d554e3cb7793087838f86badbb9e61b3c5bde232f734
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.17

Release files / pygensvd-0.1.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL pygensvd-0.1.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 11.0 MB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
e7db5355116858d55a151c4415a89f974fa13770160da7715ab3823343233fa1
BLAKE2b-256 checksum
How to use checksums
94571417605322b2e4a01cedad660b102fcf402d08c8af19693c6230f6667139
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.17

Release files / pygensvd-0.1.0-cp37-cp37m-macosx_10_9_x86_64.whl

Download URL pygensvd-0.1.0-cp37-cp37m-macosx_10_9_x86_64.whl
Size 11.6 MB
Tags CPython 3.7 CPython 3.7 pymalloc macOS 10.9+ x86-64
SHA-256 checksum
How to use checksums
d1f7c232cc1a2d1b5caac1e131aa4b81662728c90f431be5aa9a0d114f0484fb
BLAKE2b-256 checksum
How to use checksums
5df2ac2f5afdcd6feb136eaa81a1a913e52d9d9b733a70a85ea45c98cb6a08e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.17

Release history Release notifications | RSS feed

This release

0.1.0 This release

11 release files

0.0.1

1 release file

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