/
__init__.py
74 lines (53 loc) · 1.62 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import itertools
import os
import numpy as np
_counter = itertools.count()
def parameterized(names, params):
def decorator(func):
func.param_names = names
func.params = params
return func
return decorator
def requires_dask():
try:
import dask # noqa: F401
except ImportError:
raise NotImplementedError()
def requires_sparse():
try:
import sparse # noqa: F401
except ImportError:
raise NotImplementedError()
def randn(shape, frac_nan=None, chunks=None, seed=0):
rng = np.random.RandomState(seed)
if chunks is None:
x = rng.standard_normal(shape)
else:
import dask.array as da
rng = da.random.RandomState(seed)
x = rng.standard_normal(shape, chunks=chunks)
if frac_nan is not None:
inds = rng.choice(range(x.size), int(x.size * frac_nan))
x.flat[inds] = np.nan
return x
def randint(low, high=None, size=None, frac_minus=None, seed=0):
rng = np.random.RandomState(seed)
x = rng.randint(low, high, size)
if frac_minus is not None:
inds = rng.choice(range(x.size), int(x.size * frac_minus))
x.flat[inds] = -1
return x
def _skip_slow():
"""
Use this function to skip slow or highly demanding tests.
Use it as a `Class.setup` method or a `function.setup` attribute.
Examples
--------
>>> from . import _skip_slow
>>> def time_something_slow():
... pass
...
>>> time_something.setup = _skip_slow
"""
if os.environ.get("ASV_SKIP_SLOW", "0") == "1":
raise NotImplementedError("Skipping this test...")