pytest-numguard
pytest plugin for numerical edge-case testing of array code: it runs your functions on NaN, ±inf, huge and subnormal magnitudes, cancellation-prone data, empty arrays and float16/32/64 inputs, and compares them against references and metamorphic properties.
pip install pytest-numguard
This package installs numguard-ci,
which provides the plugin (the command and the import are numguard). Once it
is installed, pytest picks the plugin up automatically. The example needs SciPy
for the reference (pip install scipy):
import numpy as np
import pytest
from scipy.special import logsumexp as reference
def naive_logsumexp(x):
return np.log(np.sum(np.exp(x)))
def stable_logsumexp(x):
x = np.asarray(x)
if x.size == 0:
return x.dtype.type(-np.inf)
m = np.max(x)
if not np.isfinite(m):
return m
return (m + np.log(np.sum(np.exp(x - m)))).astype(x.dtype)
@pytest.mark.numguard(fn=naive_logsumexp, reference=reference)
def test_naive_logsumexp():
pass
@pytest.mark.numguard(fn=stable_logsumexp, reference=reference, properties=["translation_equivariant"])
def test_stable_logsumexp():
pass
Run pytest: the naive version fails on the huge, large, cancellation and
wide_range cases (it returns inf where the reference is finite), and the
stable version passes. Options such as --numguard-backend torch and the
numguard.toml configuration are documented at
https://github.com/bhaskargurram-ai/numguard.
Metadata
Release files for pytest-numguard 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pytest_numguard-1.0.1.tar.gz | 3.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_numguard-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.3 kB
Release files / pytest_numguard-1.0.1.tar.gz
| Download URL | pytest_numguard-1.0.1.tar.gz |
|---|---|
| Size | 3.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fd2e9b5cbbc2e1bb4a87572f0420645942139aa282693e1672bfb68d7f40003d
|
|
BLAKE2b-256 checksum How to use checksums |
569dc5e25aac76219ab4b7ec93f569b6df899046886276466e74dcb3a22b5065
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / pytest_numguard-1.0.1-py3-none-any.whl
| Download URL | pytest_numguard-1.0.1-py3-none-any.whl |
|---|---|
| Size | 3.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
98dd264e051c3986d0a147e8a5d23a3c68130726950c2b13aeffb1f5953f7497
|
|
BLAKE2b-256 checksum How to use checksums |
274faeb5444049b720964d3c395b9597098b3ecec4da8f1a960f1a9f184dcd8d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for pytest-numguard 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.