Linear Algebra routines for Python as implemented in the R language.
Project description
®️ rlinalg
Linear Algebra routines for Python as implemented in the R language.
🗺️ Overview
The R Project for Statistical Computing provides an environment for using and developing statistical methods. Most of the array manipulation and linear algebra routines are implemented using LAPACK, which can be accessed in Python using SciPy and NumPy.
However, when trying to port and reproduce code from R in Python, one can notice differences in the implementation of several routines, in particular in the QR decomposition with pivoting enabled:
> mat <- t(matrix(seq_len(9), nrow=3))
> qr.Q(mat)
[,1] [,2] [,3]
[1,] -0.1230915 0.9045340 0.4082483
[2,] -0.4923660 0.3015113 -0.8164966
[3,] -0.8616404 -0.3015113 0.4082483
>>> mat = numpy.arange(1, 10).reshape(3, 3)
>>> scipy.linalg.qr(mat, pivoting = True)[0]
array([[-0.2672612 0.8728716 0.4082483]
[-0.5345225 0.2182179 -0.8164966]
[-0.8017837 -0.4364358 0.4082483]])
The culprit here is the qr
function from R not using LAPACK dgeqp3
by default, but a modified R-specific version of the LINPACK dqrdc
routine (dqrdc2
) that optimizes the pivoting strategy. This means that code
using qr
in R will behave differently than an equivalent Python using
LAPACK, and there was (until now) no way to reproduce the R behaviour.
The rlinalg
library provides linear algebra routines from R using the
Fortran sources to allow reproducibility. It exposes an API similar to
the scipy
interface for similar functions (qr
, cond
, lstsq
),
which can be used to get the same results as R:
>>> mat = numpy.arange(1, 10).reshape(3, 3)
>>> rlinalg.qr(mat).Q.round(7)
array([[-0.1230915 0.904534 0.4082483]
[-0.492366 0.3015113 -0.8164966]
[-0.8616404 -0.3015113 0.4082483]])
This library depends on NumPy, and on the BLAS libraries available on the system. It is available for all modern Python versions (3.7+). Building is done with Meson and requires a Fortran compiler when compiling from source.
🔧 Installing
Install the rlinalg
package directly from PyPi
which hosts universal wheels that can be installed with pip
:
$ pip install rlinalg
💭 Feedback
⚠️ Issue Tracker
Found a bug? Have an enhancement request? Head over to the GitHub issue tracker if you need to report or ask something. If you are filing in on a bug, please include as much information as you can about the issue, and try to recreate the same bug in a simple, easily reproducible situation.
📋 Changelog
This project adheres to Semantic Versioning and provides a changelog in the Keep a Changelog format.
⚖️ License
This library is provided under the GNU General Public License v3.0 or later. It includes some code redistributed from the R language, which is licensed under the GNU General Public License v2.0 or later. Some tests were adapted from SciPy, which is developed under the BSD-3-clause license.
This project is in no way not affiliated, sponsored, or otherwise endorsed
by the R
project.
It was developed by Martin Larralde during his
PhD project at the Leiden University Medical Center
in the Zeller lab.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file rlinalg-0.1.1.tar.gz
.
File metadata
- Download URL: rlinalg-0.1.1.tar.gz
- Upload date:
- Size: 15.9 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d8af86782666bfe9d1a5475549d1f0e52928739909dc42ffc71b084f25dda2c3 |
|
MD5 | 69c191a7b457736d91315daa2faedb66 |
|
BLAKE2b-256 | 5efd52c89af015f196a5c5797c070f706912c587c6a2852dc933146a7c8c9f43 |
File details
Details for the file rlinalg-0.1.1-pp310-pypy310_pp73-manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: rlinalg-0.1.1-pp310-pypy310_pp73-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 12.0 MB
- Tags: PyPy, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 657035fb74350e8e26ef36dbd7c78cdfff60d9f381f944781ac22cc61b2fd79e |
|
MD5 | 4ceed1588e91c07c72eb6801ea0b87a4 |
|
BLAKE2b-256 | 6e65c2aa83473b420e7f93ea6ffc7ebfdf5310db1733a689f8716ad9c65ceef1 |
File details
Details for the file rlinalg-0.1.1-pp39-pypy39_pp73-manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: rlinalg-0.1.1-pp39-pypy39_pp73-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 12.0 MB
- Tags: PyPy, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 061914a5b2609fc5ea486908052407a8b084c427722af32c2539b84857dd3f4e |
|
MD5 | b6bd3009ea708b42dfcab77c51c59aad |
|
BLAKE2b-256 | 73a4b26a78d9615605b3b609c07f477765b217cdd26b62a1c86129eafb09596c |
File details
Details for the file rlinalg-0.1.1-pp38-pypy38_pp73-manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: rlinalg-0.1.1-pp38-pypy38_pp73-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 12.0 MB
- Tags: PyPy, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d170e69a17ce87db4697f44c5d9978af8670dee222c9530257266fd29a95f046 |
|
MD5 | 8482cff08c9f05cbf81fadbc843a901b |
|
BLAKE2b-256 | 04f8d260574822ef995ea98f3c55ce767ba1484399ee78c6fe8f93683d8e5e3b |
File details
Details for the file rlinalg-0.1.1-pp37-pypy37_pp73-manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: rlinalg-0.1.1-pp37-pypy37_pp73-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 12.0 MB
- Tags: PyPy, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a2226c1e7d05d0fe3b57c9be11b96779375ffcb0de432b5fd0949b62128739d |
|
MD5 | 131caea69adc37ea26d6b0de5780560b |
|
BLAKE2b-256 | a1b2374f0ad0e4e92333e043c2e21d05999eb1ab7ff56c36251b6370fdbda5bf |
File details
Details for the file rlinalg-0.1.1-cp312-cp312-manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: rlinalg-0.1.1-cp312-cp312-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 12.0 MB
- Tags: CPython 3.12, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 799e15a302310885f4eb13fd806a68d2fd17015391744bb84f841a1e94594d7e |
|
MD5 | 935b8bc377141f5a718408d8ee9c309e |
|
BLAKE2b-256 | 4570dc6a8da0c4726522fd5ed3d90b1bbe048fa6f6ab173cbd3c5963c1f4652b |
File details
Details for the file rlinalg-0.1.1-cp311-cp311-manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: rlinalg-0.1.1-cp311-cp311-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 12.0 MB
- Tags: CPython 3.11, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f444f765504982120779e9e110ed0ec86c7db1ff3bb972663252ed474f40d59 |
|
MD5 | 8784197235c754912340116b70fa55d3 |
|
BLAKE2b-256 | 8c8eafd1d0a1ab3d01da15363b8e3e72b96e4818befbef13136867698c24430b |
File details
Details for the file rlinalg-0.1.1-cp310-cp310-manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: rlinalg-0.1.1-cp310-cp310-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 12.0 MB
- Tags: CPython 3.10, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | be00753e1c3f31f0d0e6344778d24c92dfbb2060b3942e31b994e07bf3d6a430 |
|
MD5 | 3c4d4f5ba8b83958a6edd5cadb52ef24 |
|
BLAKE2b-256 | 15468bf756e69bcd4b725fbc4c6a5f16e0f87a6dc41cea6a1650c71d8bf8ab51 |
File details
Details for the file rlinalg-0.1.1-cp39-cp39-manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: rlinalg-0.1.1-cp39-cp39-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 12.0 MB
- Tags: CPython 3.9, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0d2181d825e163bdd355f57a98622ff0d346266df85f01a7dbc1cd3b80061e4 |
|
MD5 | d4408fa20c556ec0e1b1481c394fd2fb |
|
BLAKE2b-256 | 77cf1e22247ef8dc54f41a6aa7eb688b94d38e0173bdfa37e3d45a0a2263c382 |
File details
Details for the file rlinalg-0.1.1-cp38-cp38-manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: rlinalg-0.1.1-cp38-cp38-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 12.0 MB
- Tags: CPython 3.8, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c50d7759c3123d8116f8ecb8d1d47eb6b33b68f913c48eb4ab48d4cfb79ed1b8 |
|
MD5 | c4b4164443d1e8c1a72b6e12372ff5ea |
|
BLAKE2b-256 | e9e88603ef696885684d9df55dbe7e55fff82e23c60d0d0528ae8f37874d88d6 |
File details
Details for the file rlinalg-0.1.1-cp37-cp37m-manylinux_2_28_x86_64.whl
.
File metadata
- Download URL: rlinalg-0.1.1-cp37-cp37m-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 12.0 MB
- Tags: CPython 3.7m, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3841aa988ca252b5dd2c4341fb88bdbb4c02437d6aa6124dc4937b460cf5ddc5 |
|
MD5 | ee84cc55ef7c13b2b2be217a866ae66d |
|
BLAKE2b-256 | 2b7ac613af747768359fd8ce469631c8bef6ff2e051b8f55a66759741cb8ba45 |