All Projects → uber → hypothesis-gufunc

uber / hypothesis-gufunc

Licence: Apache-2.0 License
Extension to hypothesis for testing numpy general universal functions

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to hypothesis-gufunc

Fsharp Hedgehog
Release with confidence, state-of-the-art property testing for .NET.
Stars: ✭ 219 (+584.38%)
Mutual labels:  property-based-testing, testing-tools
Dbdeployer
DBdeployer is a tool that deploys MySQL database servers easily.
Stars: ✭ 467 (+1359.38%)
Mutual labels:  sandbox, testing-tools
reach
Load embeddings and featurize your sentences.
Stars: ✭ 17 (-46.87%)
Mutual labels:  numpy, vectorization
Haskell Hedgehog
Release with confidence, state-of-the-art property testing for Haskell.
Stars: ✭ 584 (+1725%)
Mutual labels:  property-based-testing, testing-tools
kitimat
A library for generative, property-based testing in TypeScript and Jest.
Stars: ✭ 68 (+112.5%)
Mutual labels:  property-based-testing, generative-testing
Fast Check
Property based testing framework for JavaScript (like QuickCheck) written in TypeScript
Stars: ✭ 2,604 (+8037.5%)
Mutual labels:  property-based-testing, generative-testing
Xarray
N-D labeled arrays and datasets in Python
Stars: ✭ 2,353 (+7253.13%)
Mutual labels:  numpy, xarray
Deepstate
A unit test-like interface for fuzzing and symbolic execution
Stars: ✭ 603 (+1784.38%)
Mutual labels:  property-based-testing, testing-tools
ava-fast-check
Property based testing for AVA based on fast-check
Stars: ✭ 44 (+37.5%)
Mutual labels:  property-based-testing, generative-testing
piggy
Test for spec compatibility and breaking changes.
Stars: ✭ 45 (+40.63%)
Mutual labels:  property-based-testing, generative-testing
leancheck
enumerative property-based testing for Haskell
Stars: ✭ 38 (+18.75%)
Mutual labels:  property-based-testing, testing-tools
spyndex
Awesome Spectral Indices in Python.
Stars: ✭ 56 (+75%)
Mutual labels:  numpy, xarray
From Python To Numpy
An open-access book on numpy vectorization techniques, Nicolas P. Rougier, 2017
Stars: ✭ 1,728 (+5300%)
Mutual labels:  numpy, vectorization
Componentfixture
🛠️Interactive sandox playground for vue components
Stars: ✭ 44 (+37.5%)
Mutual labels:  sandbox, testing-tools
extrapolate
generalize counter-examples of property-based testing
Stars: ✭ 13 (-59.37%)
Mutual labels:  property-based-testing, testing-tools
gcpy
Python toolkit for GEOS-Chem.
Stars: ✭ 34 (+6.25%)
Mutual labels:  numpy, xarray
Scipy-Bordeaux-2017
Course taught at the University of Bordeaux in the academic year 2017 for PhD students.
Stars: ✭ 16 (-50%)
Mutual labels:  numpy
deckard
DNS test harness
Stars: ✭ 28 (-12.5%)
Mutual labels:  testing-tools
Exploratory Data Analysis Visualization Python
Data analysis and visualization with PyData ecosystem: Pandas, Matplotlib Numpy, and Seaborn
Stars: ✭ 78 (+143.75%)
Mutual labels:  numpy
Image-Classifier
Final Project of the Udacity AI Programming with Python Nanodegree
Stars: ✭ 63 (+96.88%)
Mutual labels:  numpy

Hypothesis GU Funcs

https://api.travis-ci.com/uber/hypothesis-gufunc.png?token=RSemjpisB7uiZv78DVwd&branch=master

This project is experimental and the APIs are not considered stable.

Only Python>=3.6 is officially supported, but older versions of Python likely work as well.

This package includes support for strategies which generate arguments to functions that follow the numpy general universal function API. So, it can automatically generate the matrices with shapes that follow the shape constraints. For example, to generate test inputs for np.dot, one can use,

import numpy as np
from hypothesis import given
from hypothesis.strategies import floats
from hypothesis_gufunc.gufunc import gufunc_args

easy_floats = floats(min_value=-10, max_value=10)

@given(gufunc_args('(m,n),(n,p)->(m,p)', dtype=np.float_, elements=easy_floats))
def test_np_dot(args):
    x, y = args
    assert np.allclose(np.dot(x, y), np.dot(y.T, x.T).T)

test_np_dot()  # Run the test

We also allow for adding extra dimensions that follow the numpy broadcasting conventions. This allows one to test that the broadcasting follows the vectorization conventions:

@given(gufunc_args('(m,n),(n,p)->(m,p)', dtype=np.float_, elements=easy_floats, max_dims_extra=3))
def test_np_matmul(args):
    x, y = args
    f_vec = np.vectorize(np.matmul, signature='(m,n),(n,p)->(m,p)', otypes=[np.float_])
    assert np.allclose(np.matmul(x, y), f_vec(x, y))

test_np_matmul()  # Run the test

Providing max_dims_extra=3 gives up to 3 broadcast compatible dimensions on each of the arguments.

Quick Start/Installation

Simply install with pip:

pip install hypothesis-gufunc

If one would like the same pinned requirements we use during testing, then one can install from the repo with:

git clone [email protected]:uber/hypothesis-gufunc.git
cd hypothesis-gufunc
pip install -r requirements/base.txt
pip install -e .

Running the Tests

The tests for this package can be run by first doing a cd to its root directory and then

./test.sh

The script creates a conda environment using the requirements found in requirements/test.txt.

Hypothesis for Xarray

This package also contains an extension to hypothesis to generate xarray data structures.

To install the package with the xarray dependencies install it with pip as

pip install hypothesis-gufunc[xarray]

Once installed, one can generate a data array as follows:

from hypothesis.strategies import integers, lists
from hypothesis_gufunc.extra.xr import fixed_dataarrays

S = fixed_dataarrays(("a", "b"), coords_st={"a": lists(integers(0, 3))})
S.example()

Here, coords_st allows one to specify a custom strategy for the coordinates on a per-dimension basis. Likewise, if one has known coordinates one can call fixed_coords_dataarrays; or dataarrays if one wants both the dimensions and coordinates determined by the strategy.

The package also has the ability to generate a dataset:

from hypothesis_gufunc.extra.xr import fixed_datasets

S = fixed_datasets({5: ("a", "b"), "bar": ("b"), "baz": ()}, coords_st={"a": lists(integers(0, 3))})
S.example()

One can use fixed_coords_datasets when the coordinates are determined; or simply datasets to have both the dimensions and coordinates generated.

Links

The source is hosted on GitHub.

The documentation is hosted at Read the Docs.

The main hypothesis project.

A description of the numpy Generalized Universal Function API.

Likewise, the numpy broadcasting rules are described here.

The xarray project describes data arrays and datasets.

License

This project is licensed under the Apache 2 License - see the LICENSE file for details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].