From 6a92edee9bd679d1f71e66b2cc96456bead219fd Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 17 Apr 2019 10:18:45 +0200 Subject: ndarray: support stepsizes other than 1 in slicing --- ndarray.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'ndarray.c') diff --git a/ndarray.c b/ndarray.c index 504bfb7..b7c30b9 100644 --- a/ndarray.c +++ b/ndarray.c @@ -128,8 +128,8 @@ int mg2di_ndarray_slice(NDArray **result, NDArray *src, const Slice *s = &slice[i]; ptrdiff_t start, end; - if (s->step != 1) { - ret = -ENOSYS; + if (s->step < 1) { + ret = s->step ? -ENOSYS : -EINVAL; goto fail; } if (s->start == PTRDIFF_MAX) { @@ -148,10 +148,12 @@ int mg2di_ndarray_slice(NDArray **result, NDArray *src, ret = -EINVAL; goto fail; } - - offset += src->stride[i] * start; - a->priv->shape[i] = end - start; } + + offset += src->stride[i] * start; + + a->priv->stride[i] *= s->step; + a->priv->shape[i] = (end - start) / s->step; } a->dims = src->dims; -- cgit v1.2.3