perfplot complains when the `n_range` starts at zero.
zoj613 opened this issue · 3 comments
zoj613 commented
if n_range=[i for i in range(100)]
, I get the following
/home/lib/python3.8/site-packages/perfplot/main.py:78: RuntimeWarning: divide by zero encountered in log
log_n_range = numpy.log(self.n_range)
/home/lib/python3.8/site-packages/numpy/core/function_base.py:144: RuntimeWarning: invalid value encountered in multiply
y *= step
/home/lib/python3.8/site-packages/numpy/core/function_base.py:154: RuntimeWarning: invalid value encountered in add
y += start
/home/lib/python3.8/site-packages/perfplot/main.py:78: RuntimeWarning: divide by zero encountered in log
log_n_range = numpy.log(self.n_range)
/home/python3.8/site-packages/numpy/core/function_base.py:144: RuntimeWarning: invalid value encountered in multiply
y *= step
/home/lib/python3.8/site-packages/numpy/core/function_base.py:154: RuntimeWarning: invalid value encountered in add
y += start
which caused by taking log of zero.
nschloe commented
As always, a full MWE is required to reproduce.
zoj613 commented
As always, a full MWE is required to reproduce.
You're right. An example that reproduces this is the one in the README but using bench instead of plot.
import perfplot
import numpy
out = perfplot.bench(
setup=lambda n: numpy.random.rand(n), # or 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=[k for k in range(5)],
xlabel="len(a)",
)
out.show()
output:
/home/lib/python3.8/site-packages/perfplot/main.py:78: RuntimeWarning: divide by zero encountered in log
log_n_range = numpy.log(self.n_range)
/home/a/lib/python3.8/site-packages/numpy/core/function_base.py:144: RuntimeWarning: invalid value encountered in multiply
y *= step
/home/lib/python3.8/site-packages/numpy/core/function_base.py:154: RuntimeWarning: invalid value encountered in add
y += start
It seems to me the default behavior is to log the output, which gives problems when n_range
is required to start at 0. Using logx=False
and logy=False
in show() silences the warnings but this behavior is weird and confusing. Maybe the user should explicitly set scaling to log when required, not by default?