def __init__(self, bounds=None, num=None, step=None, points=None):
if points is not None:
# points are given, easy one
self._values = np.atleast_1d(points)
self._limits = (points.min(), points.max())
self._num = points.size
# TODO check for evenly spaced entries
# for now just use provided information
self._step = step
elif bounds and num:
self._limits = bounds
self._num = num
self._values, self._step = np.linspace(bounds[0], bounds[1], num, retstep=True)
if step is not None and not np.isclose(self._step, step):
raise ValueError("could not satisfy both redundant requirements for num and step!")
elif bounds and step:
self._limits = bounds
# calculate number of needed points but save correct step size
self._num = int((bounds[1] - bounds[0]) / step + 1.5)
self._values, self._step = np.linspace(bounds[0], bounds[1], self._num, retstep=True)
if np.abs(step - self._step) > 1e-1:
warnings.warn("desired step-size {} doesn't fit to given interval,"
" changing to {}".format(step, self._step))
else:
raise ValueError("not enough arguments provided!")
评论列表
文章目录