Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_speed(n=3):
path_pts = [[0, 0], [0, 1], [1, 1], [1, 0]]
path0 = path.Path(path_pts)
path1 = pypathlib.ClosedPath(path_pts)
def _mpl_path(pts):
return path0.contains_points(pts)
def _pypathlib_contains_points(pts):
return path1.contains_points(pts)
numpy.random.seed(0)
perfplot.show(
setup=lambda n: numpy.random.rand(n, 2),
kernels=[_mpl_path, _pypathlib_contains_points],
n_range=[2 ** k for k in range(n)],
labels=["matplotlib.path.contains_points", "pypathlib.contains_points"],
logx=True,
logy=True,
xlabel="num points",
)
def test_speed(N=2):
numpy.random.seed(1)
osa = colorio.OsaUcs()
cielab = colorio.CIELAB()
# cam16 = colorio.CAM16(0.69, 20, L_A=64 / numpy.pi / 5)
ciecam02 = colorio.CIECAM02(0.69, 20, L_A=64 / numpy.pi / 5)
# This close probably means that another figure hasn't been properly closed.
import matplotlib.pyplot as plt
plt.close()
perfplot.show(
# Don't use numpy.random.rand(3, n) to avoid the CIECAM breakdown
setup=lambda n: numpy.outer(numpy.random.rand(3), numpy.ones(n)) * 10,
equality_check=None,
kernels=[
osa.to_xyz100,
cielab.to_xyz100,
# cam16.to_xyz100,
lambda Jsh: ciecam02.to_xyz100(Jsh, "Jsh"),
numpy.cbrt,
],
labels=["OSA-UCS", "CIELAB", "CIECAM02", "cbrt"],
n_range=[2 ** n for n in range(N)],
logx=True,
logy=True,
# relative_to=3
def setup(n):
out = numpy.empty((3, n))
rgb = numpy.random.rand(3)
for k in range(3):
out[k] = rgb[k]
return out
Y_b = 20
L_A = 64 / numpy.pi / 5
c = 0.69 # average
cam16 = colorio.CAM16(c, Y_b, L_A)
cam16_legacy = CAM16Legacy(c, Y_b, L_A)
perfplot.show(
setup=setup,
kernels=[cam16.from_xyz100, cam16_legacy.from_xyz100],
labels=["new", "legacy"],
n_range=1000 * numpy.arange(6),
equality_check=False,
)
return
import numpy
import perfplot
perfplot.show(
setup=numpy.random.rand,
kernels=[
lambda a: numpy.c_[a, a],
lambda a: numpy.stack([a, a]).T,
lambda a: numpy.vstack([a, a]).T,
lambda a: numpy.column_stack([a, a]),
lambda a: numpy.concatenate([a[:, None], a[:, None]], axis=1),
],
labels=["c_", "stack", "vstack", "column_stack", "concat"],
n_range=[2 ** k for k in range(15)],
xlabel="len(a)",
)