From 77840b5f05ee5506d312c1f8a19a6796abebf03c Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 13 Jun 2019 11:22:02 +0200 Subject: ndarray: fix handling SLICE_NULL --- ndarray.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/ndarray.c b/ndarray.c index b7c30b9..dee985c 100644 --- a/ndarray.c +++ b/ndarray.c @@ -126,18 +126,21 @@ int mg2di_ndarray_slice(NDArray **result, NDArray *src, offset = 0; for (unsigned int i = 0; i < src->dims; i++) { const Slice *s = &slice[i]; - ptrdiff_t start, end; + ptrdiff_t start, end, step; - if (s->step < 1) { - ret = s->step ? -ENOSYS : -EINVAL; - goto fail; - } if (s->start == PTRDIFF_MAX) { start = 0; end = src->shape[i]; + step = 1; } else { start = s->start; end = s->end; + step = s->step; + + if (step < 1) { + ret = step ? -ENOSYS : -EINVAL; + goto fail; + } if (start < 0) start = src->shape[i] + start; @@ -152,8 +155,8 @@ int mg2di_ndarray_slice(NDArray **result, NDArray *src, offset += src->stride[i] * start; - a->priv->stride[i] *= s->step; - a->priv->shape[i] = (end - start) / s->step; + a->priv->stride[i] *= step; + a->priv->shape[i] = (end - start) / step; } a->dims = src->dims; -- cgit v1.2.3