if n_steps < 1:
raise ParameterError("n_steps must be a positive integer")
if data.ndim > 2:
raise ParameterError("Input must be at most 2-dimensional. "
"Given data.shape={}".format(data.shape))
if delay == 0:
raise ParameterError("delay must be a non-zero integer")
data = np.atleast_2d(data)
t = data.shape[-1]
if t < 1:
raise ParameterError("Cannot stack memory when input data has "
"no columns. Given data.shape={}".format(data.shape))
kwargs.setdefault("mode", "constant")
if kwargs["mode"] == "constant":
kwargs.setdefault("constant_values", [0])
// Pad the end with zeros, which will roll to the front below
if delay > 0:
padding = (int((n_steps - 1) * delay), 0)
else:
padding = (0, int((n_steps - 1) * -delay))
data = np.pad(data, [(0, 0), padding], **kwargs)
// Construct the shape of the target array
shape = list(data.shape)
shape[0] = shape[0] * n_steps
shape[1] = t
shape = tuple(shape)
// Construct the output array to match layout and dtype of input
history = np.empty_like(data, shape=shape)
// Populate the output array
__stack(history, data, n_steps, delay)